Java Code Examples for java.util.ArrayList#listIterator()
The following examples show how to use
java.util.ArrayList#listIterator() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AttributeMapper.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
public void modify(ModifyInterceptorChain chain, DistinguishedName dn, ArrayList<LDAPModification> mods, LDAPConstraints constraints) throws LDAPException { ListIterator<LDAPModification> it = mods.listIterator(); while (it.hasNext()) { LDAPModification mod = it.next(); String newName = this.localMap.get(mod.getAttribute().getBaseName().toLowerCase()); if (newName != null) { LDAPAttribute newAttrib = new LDAPAttribute(newName); byte[][] vals = mod.getAttribute().getByteValueArray(); for (int i=0,m=vals.length;i<m;i++) { newAttrib.addValue(vals[i]); } LDAPModification newMod = new LDAPModification(mod.getOp(),newAttrib); it.remove(); it.add(newMod); } } chain.nextModify(dn,mods,constraints); }
Example 2
Source File: AttributeMapper.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
public void modify(ModifyInterceptorChain chain, DistinguishedName dn, ArrayList<LDAPModification> mods, LDAPConstraints constraints) throws LDAPException { ListIterator<LDAPModification> it = mods.listIterator(); while (it.hasNext()) { LDAPModification mod = it.next(); String newName = this.localMap.get(mod.getAttribute().getBaseName().toLowerCase()); if (newName != null) { LDAPAttribute newAttrib = new LDAPAttribute(newName); byte[][] vals = mod.getAttribute().getByteValueArray(); for (int i=0,m=vals.length;i<m;i++) { newAttrib.addValue(vals[i]); } LDAPModification newMod = new LDAPModification(mod.getOp(),newAttrib); it.remove(); it.add(newMod); } } chain.nextModify(dn,mods,constraints); }
Example 3
Source File: Code.java From immutables with Apache License 2.0 | 6 votes |
static List<Term> replaceReturn(List<Term> code, String replacement) { ArrayList<Term> result = new ArrayList<>(code); ListIterator<Term> it = result.listIterator(); boolean wasReturn = false; while (it.hasNext()) { Term t = it.next(); if (t.isWordOrNumber() && t.is("return")) { it.set(new Other(replacement)); wasReturn = true; } } if (!wasReturn) { ListIterator<Term> revIt = Lists.reverse(result).listIterator(); if (nextNonBlankIs(revIt, "}")) { nextNonBlankIs(revIt, ";"); revIt.previous(); revIt.add(new Delimiter(";")); revIt.add(new Other(replacement)); revIt.add(new Whitespace("\n")); } } return result; }
Example 4
Source File: FilterBam.java From Drop-seq with MIT License | 6 votes |
private SAMFileHeader editSequenceDictionary(final SAMFileHeader fileHeader) { if (DROP_REJECTED_REF || !STRIP_REF_PREFIX.isEmpty()) { // Make mutable copy of sequence list final ArrayList<SAMSequenceRecord> sequences = new ArrayList<>(fileHeader.getSequenceDictionary().getSequences()); final ListIterator<SAMSequenceRecord> it = sequences.listIterator(); while (it.hasNext()) { final SAMSequenceRecord sequence = it.next(); if (DROP_REJECTED_REF && filterReference(sequence.getSequenceName())) it.remove(); else { final String editedSequenceName = stripReferencePrefix(sequence.getSequenceName()); if (editedSequenceName != null) it.set(cloneWithNewName(sequence, editedSequenceName)); } } fileHeader.getSequenceDictionary().setSequences(sequences); } return fileHeader; }
Example 5
Source File: Main.java From ChessOOP with MIT License | 5 votes |
private ArrayList<Cell> filterdestination (ArrayList<Cell> destlist, Cell fromcell) { ArrayList<Cell> newlist = new ArrayList<Cell>(); Cell newboardstate[][] = new Cell[8][8]; ListIterator<Cell> it = destlist.listIterator(); int x,y; while (it.hasNext()) { for(int i=0;i<8;i++) for(int j=0;j<8;j++) { try { newboardstate[i][j] = new Cell(boardState[i][j]);} catch (CloneNotSupportedException e){e.printStackTrace();}} Cell tempc = it.next(); if(newboardstate[tempc.x][tempc.y].getpiece()!=null) newboardstate[tempc.x][tempc.y].removePiece(); newboardstate[tempc.x][tempc.y].setPiece(newboardstate[fromcell.x][fromcell.y].getpiece()); x=getKing(chance).getx(); y=getKing(chance).gety(); if(newboardstate[fromcell.x][fromcell.y].getpiece() instanceof King) { ((King)(newboardstate[tempc.x][tempc.y].getpiece())).setx(tempc.x); ((King)(newboardstate[tempc.x][tempc.y].getpiece())).sety(tempc.y); x=tempc.x; y=tempc.y; } newboardstate[fromcell.x][fromcell.y].removePiece(); if ((((King)(newboardstate[x][y].getpiece())).isindanger(newboardstate)==false)) newlist.add(tempc); } return newlist; }
Example 6
Source File: TestImmutableListIterator.java From java-license-manager with Apache License 2.0 | 5 votes |
public TestImmutableListIterator() { ArrayList<String> temp = new ArrayList<>(); temp.add("MyString1"); temp.add("YourString2"); temp.add("HisString3"); temp.add("HerString4"); this.valid = new MockValidObject(); this.iterator = new ImmutableListIterator<>(temp.listIterator(), this.valid); }
Example 7
Source File: IterateThroughArrayListUsingListIteratorExample.java From javaide with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { //create an ArrayList object ArrayList arrayList = new ArrayList(); //Add elements to Arraylist arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); arrayList.add("4"); arrayList.add("5"); /* Get a ListIterator object for ArrayList using listIterator() method. */ ListIterator itr = arrayList.listIterator(); /* Use hasNext() and next() methods of ListIterator to iterate through the elements in forward direction. */ System.out.println("Iterating through ArrayList elements in forward direction..."); while (itr.hasNext()) System.out.println(itr.next()); /* Use hasPrevious() and previous() methods of ListIterator to iterate through the elements in backward direction. */ System.out.println("Iterating through ArrayList elements in backward direction..."); while (itr.hasPrevious()) System.out.println(itr.previous()); }
Example 8
Source File: CallActivity.java From restcomm-android-sdk with GNU Affero General Public License v3.0 | 5 votes |
private boolean havePermissions(ArrayList<String> permissions) { boolean allGranted = true; ListIterator<String> it = permissions.listIterator(); while (it.hasNext()) { if (ActivityCompat.checkSelfPermission(this, it.next()) != PackageManager.PERMISSION_GRANTED) { allGranted = false; } else { // permission granted, remove it from permissions it.remove(); } } return allGranted; }
Example 9
Source File: StructTest.java From ion-java with Apache License 2.0 | 5 votes |
void remove_all_copies(ArrayList<TestField> s, String fieldName) { ListIterator<TestField> it = s.listIterator(); while (it.hasNext()) { TestField field = it.next(); if (field._fieldName.equals(fieldName)) { it.remove(); } } }
Example 10
Source File: SaiyTextToSpeech.java From Saiy-PS with GNU Affero General Public License v3.0 | 5 votes |
private ArrayList<SaiyVoice> filterLegacy(@NonNull final ArrayList<SaiyVoice> voiceArray) { if (DEBUG) { MyLog.i(CLS_NAME, "filterLegacy"); } if (isNetworkAllowed) { final ArrayList<SaiyVoice> voiceArrayCopy = new ArrayList<>(voiceArray); final ListIterator<SaiyVoice> itr = voiceArrayCopy.listIterator(); SaiyVoice v; while (itr.hasNext()) { v = itr.next(); if (v.getFeatures().contains(TTSDefaults.LEGACY_ENGINE_FIELD)) { itr.remove(); } } if (voiceArrayCopy.isEmpty()) { return filterQuality(voiceArray); } else { return filterQuality(voiceArrayCopy); } } return filterQuality(voiceArray); }
Example 11
Source File: Configuration.java From hadoop-gpu with Apache License 2.0 | 5 votes |
private void toString(ArrayList resources, StringBuffer sb) { ListIterator i = resources.listIterator(); while (i.hasNext()) { if (i.nextIndex() != 0) { sb.append(", "); } sb.append(i.next()); } }
Example 12
Source File: Code.java From immutables with Apache License 2.0 | 5 votes |
static List<Term> trimLeadingIndent(List<Term> code) { ArrayList<Term> result = new ArrayList<>(code); ListIterator<Term> it = result.listIterator(); while (it.hasNext()) { Term t = it.next(); if (t.isWhitespace()) { String whitespace = t.toString(); int indexOf = whitespace.indexOf('\n'); if (indexOf >= 0) { it.set(new Whitespace(whitespace.substring(0, indexOf + 1))); } } } return result; }
Example 13
Source File: DefaultResourceTransformerChain.java From java-technology-stack with MIT License | 5 votes |
private DefaultResourceTransformerChain initTransformerChain(ResourceResolverChain resolverChain, ArrayList<ResourceTransformer> transformers) { DefaultResourceTransformerChain chain = new DefaultResourceTransformerChain(resolverChain, null, null); ListIterator<? extends ResourceTransformer> it = transformers.listIterator(transformers.size()); while (it.hasPrevious()) { chain = new DefaultResourceTransformerChain(resolverChain, it.previous(), chain); } return chain; }
Example 14
Source File: ListHandleAdapter.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @param iterator */ private ListIterator convertIteratorToListIterator( Iterator iterator ) { ArrayList list = new ArrayList( ); for ( Iterator it = iterator; it.hasNext( ); ) { list.add( it.next( ) ); } return list.listIterator( list.size( ) ); }
Example 15
Source File: AmqpConsumer.java From qpid-jms with Apache License 2.0 | 4 votes |
/** * Recovers all previously delivered but not acknowledged messages. * * @throws Exception if an error occurs while performing the recover. */ public void recover() throws Exception { LOG.debug("Session Recover for consumer: {}", getResourceInfo().getId()); ArrayList<JmsInboundMessageDispatch> redispatchList = new ArrayList<JmsInboundMessageDispatch>(); Delivery delivery = getEndpoint().head(); while (delivery != null) { Delivery current = delivery; delivery = delivery.next(); if (!(current.getContext() instanceof JmsInboundMessageDispatch)) { LOG.debug("{} Found incomplete delivery with no context during recover processing", AmqpConsumer.this); continue; } JmsInboundMessageDispatch envelope = (JmsInboundMessageDispatch) current.getContext(); if (envelope.isDelivered()) { envelope.getMessage().getFacade().setRedeliveryCount( envelope.getMessage().getFacade().getRedeliveryCount() + 1); envelope.setEnqueueFirst(true); envelope.setDelivered(false); if(acknowledgementMode == Session.CLIENT_ACKNOWLEDGE) { envelope.setRecovered(true); } redispatchList.add(envelope); } } // Previously delivered messages should be tagged as dispatched messages again so we // can properly compute the next credit refresh, so subtract them from both the delivered // and dispatched counts and then dispatch them again as a new message. deliveredCount -= redispatchList.size(); dispatchedCount -= redispatchList.size(); ListIterator<JmsInboundMessageDispatch> reverseIterator = redispatchList.listIterator(redispatchList.size()); while (reverseIterator.hasPrevious()) { deliver(reverseIterator.previous()); } }
Example 16
Source File: AESKeyFileEncrypterFactory.java From qpid-broker-j with Apache License 2.0 | 4 votes |
private void checkFilePermissions(String fileLocation, File file) throws IOException { if(isPosixFileSystem(file)) { Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(file.toPath()); if (permissions.contains(PosixFilePermission.GROUP_READ) || permissions.contains(PosixFilePermission.OTHERS_READ) || permissions.contains(PosixFilePermission.GROUP_WRITE) || permissions.contains(PosixFilePermission.OTHERS_WRITE)) { throw new IllegalArgumentException("Key file '" + fileLocation + "' has incorrect permissions. Only the owner " + "should be able to read or write this file."); } } else if(isAclFileSystem(file)) { AclFileAttributeView attributeView = Files.getFileAttributeView(file.toPath(), AclFileAttributeView.class); ArrayList<AclEntry> acls = new ArrayList<>(attributeView.getAcl()); ListIterator<AclEntry> iter = acls.listIterator(); UserPrincipal owner = Files.getOwner(file.toPath()); while(iter.hasNext()) { AclEntry acl = iter.next(); if(acl.type() == AclEntryType.ALLOW) { Set<AclEntryPermission> originalPermissions = acl.permissions(); Set<AclEntryPermission> updatedPermissions = EnumSet.copyOf(originalPermissions); if (updatedPermissions.removeAll(EnumSet.of(AclEntryPermission.APPEND_DATA, AclEntryPermission.EXECUTE, AclEntryPermission.WRITE_ACL, AclEntryPermission.WRITE_DATA, AclEntryPermission.WRITE_OWNER))) { throw new IllegalArgumentException("Key file '" + fileLocation + "' has incorrect permissions. The file should not be modifiable by any user."); } if (!owner.equals(acl.principal()) && updatedPermissions.removeAll(EnumSet.of(AclEntryPermission.READ_DATA))) { throw new IllegalArgumentException("Key file '" + fileLocation + "' has incorrect permissions. Only the owner should be able to read from the file."); } } } } else { throw new IllegalArgumentException(ILLEGAL_ARG_EXCEPTION); } }
Example 17
Source File: RelativePath.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public ListIterator<String> segmentIterator() { ArrayList<String> content = new ArrayList<String>(Arrays.asList(segments)); return content.listIterator(); }
Example 18
Source File: BlackList.java From Saiy-PS with GNU Affero General Public License v3.0 | 4 votes |
/** * Check if the remote package that is making the denied requests has done this too many times, * calculated using {@link #MAX_ACQUIRE_REJECT} & {@link #MAX_PAST_TIME} * <p> * It would also be possible to extend this method to analyse the Uid, but that is perhaps a * little too cautious? * * @param blackListArray the ArrayList of {@link BlackList} * @return true if the package should be permanently blacklisted */ public static synchronized boolean shouldBlackList(final ArrayList<BlackList> blackListArray) { if (DEBUG) { MyLog.i(CLS_NAME, "shouldBlackList: " + blackListArray.size()); } final int blackListSize = blackListArray.size(); if (blackListSize > 5) { final BlackList currentBlackList = blackListArray.get(blackListSize - 1); final String currentPackageName = currentBlackList.getPackageName(); final int currentUid = currentBlackList.getCallingUid(); final long currentRequestTime = currentBlackList.getRequestTime(); if (DEBUG) { MyLog.v(CLS_NAME, "shouldBlackList: currentPackageName: " + currentPackageName); MyLog.v(CLS_NAME, "shouldBlackList: currentUid: " + currentUid); MyLog.v(CLS_NAME, "shouldBlackList: currentRequestTime: " + currentRequestTime); } BlackList blackList; String packageName; int matches = 0; for (int i = 0; i < (blackListSize - 1); i++) { blackList = blackListArray.get(i); packageName = blackList.getPackageName(); if (packageName.matches(currentPackageName)) { if (DEBUG) { MyLog.v(CLS_NAME, "shouldBlackList: difference: " + (currentRequestTime - blackList.getRequestTime())); } if ((currentRequestTime - blackList.getRequestTime()) < MAX_PAST_TIME) { matches++; } } } if (DEBUG) { MyLog.v(CLS_NAME, "shouldBlackList: matches: " + matches); } final ListIterator itr = blackListArray.listIterator(); if (matches > MAX_ACQUIRE_REJECT) { if (DEBUG) { MyLog.e(CLS_NAME, "Blacklisted package: " + currentPackageName); } while (itr.hasNext()) { blackList = (BlackList) itr.next(); packageName = blackList.getPackageName(); if (packageName.matches(currentPackageName)) { itr.remove(); } else if ((currentRequestTime - blackList.getRequestTime()) > MAX_PAST_TIME) { itr.remove(); } } return true; } else { while (itr.hasNext()) { blackList = (BlackList) itr.next(); if ((currentRequestTime - blackList.getRequestTime()) > MAX_PAST_TIME) { itr.remove(); } } } if (DEBUG) { MyLog.v(CLS_NAME, "shouldBlackList: blackListArray trimmed size: " + blackListArray.size()); } } return false; }
Example 19
Source File: RelativePath.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public ListIterator<String> segmentIterator() { ArrayList<String> content = new ArrayList<String>(Arrays.asList(segments)); return content.listIterator(); }
Example 20
Source File: RelativePath.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public ListIterator<String> segmentIterator() { ArrayList<String> content = new ArrayList<String>(Arrays.asList(segments)); return content.listIterator(); }