java.util.ArrayList#listIterator ( )源码实例Demo

下面列出了java.util.ArrayList#listIterator ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MyVirtualDirectory   文件: AttributeMapper.java
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);
	
}
 
源代码2 项目: MyVirtualDirectory   文件: AttributeMapper.java
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);
	
}
 
源代码3 项目: immutables   文件: Code.java
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;
}
 
源代码4 项目: Drop-seq   文件: FilterBam.java
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;
}
 
源代码5 项目: ChessOOP   文件: Main.java
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;
}
 
源代码6 项目: birt   文件: ListHandleAdapter.java
/**
 * @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( ) );
}
 
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;
}
 
源代码8 项目: immutables   文件: Code.java
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;
}
 
源代码9 项目: hadoop-gpu   文件: Configuration.java
private void toString(ArrayList resources, StringBuffer sb) {
  ListIterator i = resources.listIterator();
  while (i.hasNext()) {
    if (i.nextIndex() != 0) {
      sb.append(", ");
    }
    sb.append(i.next());
  }
}
 
源代码10 项目: ion-java   文件: StructTest.java
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();
        }
    }
}
 
源代码11 项目: restcomm-android-sdk   文件: CallActivity.java
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;
}
 
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());

    }
 
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);
}
 
源代码14 项目: Saiy-PS   文件: SaiyTextToSpeech.java
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);
}
 
源代码15 项目: qpid-jms   文件: AmqpConsumer.java
/**
 * 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());
    }
}
 
源代码16 项目: Pushjet-Android   文件: RelativePath.java
public ListIterator<String> segmentIterator() {
    ArrayList<String> content = new ArrayList<String>(Arrays.asList(segments));
    return content.listIterator();
}
 
源代码17 项目: pushfish-android   文件: RelativePath.java
public ListIterator<String> segmentIterator() {
    ArrayList<String> content = new ArrayList<String>(Arrays.asList(segments));
    return content.listIterator();
}
 
源代码18 项目: Saiy-PS   文件: BlackList.java
/**
 * 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;
}
 
源代码19 项目: Pushjet-Android   文件: RelativePath.java
public ListIterator<String> segmentIterator() {
    ArrayList<String> content = new ArrayList<String>(Arrays.asList(segments));
    return content.listIterator();
}
 
源代码20 项目: qpid-broker-j   文件: AESKeyFileEncrypterFactory.java
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);
    }
}