Java Code Examples for java.util.ListIterator

The following are top voted examples for showing how to use java.util.ListIterator. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Lagerta   File: MergeUtil.java   Source Code and License 6 votes vote down vote up
/**
 * merges two collections
 *
 * @param first      result list
 * @param second     merges with first list
 * @param comparator
 */
public static <T> void merge(List<T> first, List<T> second, Comparator<T> comparator) {
    ListIterator<T> firstIter = first.listIterator();
    ListIterator<T> secondIter = second.listIterator();

    T a = getNext(firstIter);
    T b = getNext(secondIter);

    while (a != null && b != null) {
        if (comparator.compare(a, b) > 0) {
            firstIter.previous();
            firstIter.add(b);
            firstIter.next();
            b = getNext(secondIter);
        } else {
            a = getNext(firstIter);
        }
    }

    while (b != null) {
        firstIter.add(b);
        b = getNext(secondIter);
    }
}
 
Example 2
Project: node-boilerpipe   File: TrailingHeadlineToBoilerplateFilter.java   Source Code and License 6 votes vote down vote up
public boolean process(TextDocument doc) throws BoilerpipeProcessingException {
  boolean changes = false;

  List<TextBlock> list = doc.getTextBlocks();

  for (ListIterator<TextBlock> it = list.listIterator(list.size()); it.hasPrevious();) {
    TextBlock tb = it.previous();
    if (tb.isContent()) {
      if (tb.hasLabel(DefaultLabels.HEADING)) {
        tb.setIsContent(false);
        changes = true;
      } else {
        break;
      }
    }
  }

  return changes;
}
 
Example 3
Project: GitHub   File: RangeLayoutHelperFinder.java   Source Code and License 6 votes vote down vote up
@Override
protected Iterable<LayoutHelper> reverse() {
    final ListIterator<LayoutHelper> i = mLayoutHelpers.listIterator(mLayoutHelpers.size());
    return new Iterable<LayoutHelper>() {
        @Override
        public Iterator<LayoutHelper> iterator() {
            return new Iterator<LayoutHelper>() {
                public boolean hasNext() {
                    return i.hasPrevious();
                }

                public LayoutHelper next() {
                    return i.previous();
                }

                public void remove() {
                    i.remove();
                }
            };
        }
    };
}
 
Example 4
Project: s-store   File: Lists.java   Source Code and License 6 votes vote down vote up
/**
 * An implementation of {@link List#subList(int, int)}.
 */
static <E> List<E> subListImpl(
    final List<E> list, int fromIndex, int toIndex) {
  List<E> wrapper;
  if (list instanceof RandomAccess) {
    wrapper = new RandomAccessListWrapper<E>(list) {
      @Override public ListIterator<E> listIterator(int index) {
        return backingList.listIterator(index);
      }

      private static final long serialVersionUID = 0;
    };
  } else {
    wrapper = new AbstractListWrapper<E>(list) {
      @Override public ListIterator<E> listIterator(int index) {
        return backingList.listIterator(index);
      }

      private static final long serialVersionUID = 0;
    };
  }
  return wrapper.subList(fromIndex, toIndex);
}
 
Example 5
Project: ZooKeeper   File: ClientCnxnSocketNIO.java   Source Code and License 6 votes vote down vote up
private Packet findSendablePacket(LinkedList<Packet> outgoingQueue,
                                  boolean clientTunneledAuthenticationInProgress) {
    synchronized (outgoingQueue) {
        if (outgoingQueue.isEmpty()) {
            return null;
        }
        if (outgoingQueue.getFirst().bb != null // If we've already starting sending the first packet, we better finish
            || !clientTunneledAuthenticationInProgress) {
            return outgoingQueue.getFirst();
        }

        // Since client's authentication with server is in progress,
        // send only the null-header packet queued by primeConnection().
        // This packet must be sent so that the SASL authentication process
        // can proceed, but all other packets should wait until
        // SASL authentication completes.
        ListIterator<Packet> iter = outgoingQueue.listIterator();
        while (iter.hasNext()) {
            Packet p = iter.next();
            if (p.requestHeader == null) {
                // We've found the priming-packet. Move it to the beginning of the queue.
                iter.remove();
                outgoingQueue.add(0, p);
                return p;
            } else {
                // Non-priming packet: defer it until later, leaving it in the queue
                // until authentication completes.
                if (LOG.isDebugEnabled()) {
                    LOG.debug("deferring non-priming packet: " + p +
                            "until SASL authentication completes.");
                }
            }
        }
        // no sendable packet found.
        return null;
    }
}
 
Example 6
Project: athena   File: KeyListenerTest.java   Source Code and License 6 votes vote down vote up
/**
 * Checks key values are set correctly.
 */
@Test
public void processKeyWithUsesInList() throws IOException, ParserException {
    YangNode node = manager.getDataModel("src/test/resources/KeyWithUsesInList.yang");

    assertThat((node instanceof YangModule), is(true));
    assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
    YangModule yangNode = (YangModule) node;
    assertThat(yangNode.getName(), is("Test"));

    // Check whether the list is child of module
    YangList yangList = (YangList) yangNode.getChild().getNextSibling();
    assertThat(yangList.getName(), is("valid"));

    ListIterator<String> keyList = yangList.getKeyList().listIterator();
    assertThat(keyList.next(), is("invalid-interval"));
}
 
Example 7
Project: RNLearn_Project1   File: NativeAnimatedNodesManager.java   Source Code and License 6 votes vote down vote up
public void removeAnimatedEventFromView(int viewTag, String eventName, int animatedValueTag) {
  String key = viewTag + eventName;
  if (mEventDrivers.containsKey(key)) {
    List<EventAnimationDriver> driversForKey = mEventDrivers.get(key);
    if (driversForKey.size() == 1) {
      mEventDrivers.remove(viewTag + eventName);
    } else {
      ListIterator<EventAnimationDriver> it = driversForKey.listIterator();
      while (it.hasNext()) {
        if (it.next().mValueNode.mTag == animatedValueTag) {
          it.remove();
          break;
        }
      }
    }
  }
}
 
Example 8
Project: mupdf-android-viewer-nui   File: DocPageView.java   Source Code and License 6 votes vote down vote up
private PageAnnotation getSelectedAnnotation()
{
	if (mAnnotations != null)
	{
		//  iterate in reverse order
		ListIterator<PageAnnotation> li = mAnnotations.listIterator(mAnnotations.size());
		while (li.hasPrevious())
		{
			PageAnnotation annot = li.previous();
			if (annot.isSelected())
			{
				return annot;
			}
		}
	}

	return null;
}
 
Example 9
Project: HCFCore   File: ListIteratorWrapper.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the next element from the iterator.
 *
 * @return the next element from the iterator
 * @throws NoSuchElementException if there are no more elements
 */
public E next() throws NoSuchElementException {
    if (iterator instanceof ListIterator) {
        return iterator.next();
    }

    if (currentIndex < wrappedIteratorIndex) {
        ++currentIndex;
        return list.get(currentIndex - 1);
    }

    final E retval = iterator.next();
    list.add(retval);
    ++currentIndex;
    ++wrappedIteratorIndex;
    removeState = true;
    return retval;
}
 
Example 10
Project: athena   File: KeyListenerTest.java   Source Code and License 6 votes vote down vote up
/**
 * Checks key statement as sub-statement of list.
 */
@Test
public void processListSubStatementKey() throws IOException, ParserException {

    YangNode node = manager.getDataModel("src/test/resources/ListSubStatementKey.yang");

    assertThat((node instanceof YangModule), is(true));

    // Check whether the node type is set properly to module.
    assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));

    // Check whether the module name is set correctly.
    YangModule yangNode = (YangModule) node;
    assertThat(yangNode.getName(), is("Test"));

    // Check whether the list is child of module
    YangList yangList = (YangList) yangNode.getChild();
    assertThat(yangList.getName(), is("valid"));

    ListIterator<String> keyList = yangList.getKeyList().listIterator();
    assertThat(keyList.next(), is("invalid-interval"));
}
 
Example 11
Project: DicomViewer   File: SortedListTools.java   Source Code and License 6 votes vote down vote up
private static <T> int iteratorBinarySearch(final List<? extends Comparable<? super T>> list, final T key, int low, int high)  {
    final ListIterator<? extends Comparable<? super T>> i = list.listIterator();
    int mid, cmp;
    while (low <= high) {
        mid = (low + high) >>> 1;
        cmp = get(i, mid).compareTo(key);

        if (cmp < 0) {
            low = mid + 1;
        } else if (cmp > 0) {
            high = mid - 1;
        } else {
            return mid;
        } // key found
    }
    return -(low + 1);  // key not found
}
 
Example 12
Project: athena   File: PatternRestrictionListenerTest.java   Source Code and License 6 votes vote down vote up
/**
 * Checks valid pattern statement with plus symbol in pattern.
 */
@Test
public void processPatternStatementWithPlus() throws IOException, ParserException {

    YangNode node = manager.getDataModel("src/test/resources/PatternStatementWithPlus.yang");

    assertThat((node instanceof YangModule), is(true));
    assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
    YangModule yangNode = (YangModule) node;
    assertThat(yangNode.getName(), is("Test"));

    ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
    YangLeafList leafListInfo = leafListIterator.next();

    assertThat(leafListInfo.getName(), is("invalid-interval"));
    assertThat(leafListInfo.getDataType().getDataTypeName(), is("string"));
    assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
    YangStringRestriction stringRestriction = (YangStringRestriction) leafListInfo
            .getDataType().getDataTypeExtendedInfo();
    ListIterator<String> patternListIterator = stringRestriction.getPatternRestriction()
            .getPatternList().listIterator();
    assertThat(patternListIterator.next(), is("-[0-9]+|[0-9]+"));
}
 
Example 13
Project: hanlpStudy   File: NotionalTokenizer.java   Source Code and License 6 votes vote down vote up
/**
 * 切分为句子形式
 *
 * @param text
 * @return
 */
public static List<List<Term>> seg2sentence(String text)
{
    List<List<Term>> sentenceList = SEGMENT.seg2sentence(text);
    for (List<Term> sentence : sentenceList)
    {
        ListIterator<Term> listIterator = sentence.listIterator();
        while (listIterator.hasNext())
        {
            if (!CoreStopWordDictionary.shouldInclude(listIterator.next()))
            {
                listIterator.remove();
            }
        }
    }

    return sentenceList;
}
 
Example 14
Project: athena   File: PatternRestrictionListenerTest.java   Source Code and License 6 votes vote down vote up
/**
 * Checks valid pattern statement as sub-statement of leaf statement.
 */
@Test
public void processValidPatternStatement() throws IOException, ParserException {

    YangNode node = manager.getDataModel("src/test/resources/ValidPatternStatement.yang");

    assertThat((node instanceof YangModule), is(true));
    assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
    YangModule yangNode = (YangModule) node;
    assertThat(yangNode.getName(), is("Test"));

    ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
    YangLeaf leafInfo = leafIterator.next();

    assertThat(leafInfo.getName(), is("invalid-interval"));
    assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
    assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
    YangStringRestriction stringRestriction = (YangStringRestriction) leafInfo
            .getDataType().getDataTypeExtendedInfo();
    ListIterator<String> patternListIterator = stringRestriction.getPatternRestriction()
            .getPatternList().listIterator();
    assertThat(patternListIterator.next(), is("[a-zA-Z]"));
}
 
Example 15
Project: athena   File: DescriptionListenerTest.java   Source Code and License 6 votes vote down vote up
/**
 * Checks valid description statement.
 */
@Test
public void processDescriptionValidStatement() throws IOException, ParserException {

    YangNode node = manager.getDataModel("src/test/resources/DescriptionValidStatement.yang");

    // Check whether the data model tree returned is of type module.
    assertThat((node instanceof YangModule), is(true));

    // Check whether the node type is set properly to module.
    assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));

    // Check whether the module name is set correctly.
    YangModule yangNode = (YangModule) node;
    assertThat(yangNode.getName(), is("Test"));

    ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
    YangLeaf leafInfo = leafIterator.next();

    // Check whether the description is set correctly.
    assertThat(leafInfo.getName(), is("invalid-interval"));
    assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\""));
}
 
Example 16
Project: athena   File: ContainerListenerTest.java   Source Code and License 6 votes vote down vote up
/**
 * Checks container statement as sub-statement of list.
 */
@Test
public void processListSubStatementContainer() throws IOException, ParserException {

    YangNode node = manager.getDataModel("src/test/resources/ListSubStatementContainer.yang");

    assertThat((node instanceof YangModule), is(true));

    // Check whether the node type is set properly to module.
    assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));

    // Check whether the module name is set correctly.
    YangModule yangNode = (YangModule) node;
    assertThat(yangNode.getName(), is("Test"));

    // Check whether the list is child of module
    YangList yangList1 = (YangList) yangNode.getChild();
    assertThat(yangList1.getName(), is("ospf"));

    ListIterator<String> keyList = yangList1.getKeyList().listIterator();
    assertThat(keyList.next(), is("process-id"));

    // Check whether the list is child of list
    YangContainer yangContainer = (YangContainer) yangList1.getChild();
    assertThat(yangContainer.getName(), is("interface"));
}
 
Example 17
Project: Hydrograph   File: HiveFieldDialogHelper.java   Source Code and License 6 votes vote down vote up
/**
 * 
 * Compares available fields and selected partition key fields for 
 *   hive input and output components. 
 * 
 */
public boolean compare_fields(TableItem[] items,List<String> sourceFieldsList)
{
	ListIterator<String> t_itr,s_itr;
	boolean is_equal=true;
	
	List<String> target_fields = new ArrayList<String>();
	if(items.length > 0){
		for (TableItem tableItem : items){
			target_fields.add((String) tableItem.getText());
		}
	
	
	List<String> source_field = new ArrayList<String>(sourceFieldsList);
	
	t_itr=target_fields.listIterator(target_fields.size());
	s_itr = source_field.listIterator(source_field.size());
	
	
	while(t_itr.hasPrevious() & s_itr.hasPrevious()){
		if(StringUtils.equals(s_itr.previous(),t_itr.previous())){
			is_equal=true;
		}
		else{
			is_equal=false;
			break;
		}
	}
	}
	return is_equal;
	
}
 
Example 18
Project: Equella   File: InstitutionImportServiceImpl.java   Source Code and License 6 votes vote down vote up
protected void doErrorCleanup(final TemporaryFileHandle staging, final List<String> tasksDone,
	final Institution institution, final ConverterParams params)
{
	runAs.executeAsSystem(institution, new Runnable()
	{
		@Override
		public void run()
		{
			tasksDone.add(0, ConverterId.CLEANUPFILES.name());
			ListIterator<String> iter = tasksDone.listIterator(tasksDone.size());

			while( iter.hasPrevious() )
			{
				String task = iter.previous();
				getConverter(task).deleteIt(staging, institution, params, task);
			}
			instService.deleteInstitution(institution);
		}
	});
}
 
Example 19
Project: xsharing-services-router   File: AbstractModeStrategy.java   Source Code and License 5 votes vote down vote up
<TUPLE extends StationTuple> ListIterator<TUPLE> getListIterator(List<TUPLE> fromTuples) {
    if (useLiveStatus) {
        return fromTuples.listIterator();
    } else {
        List<TUPLE> out;
        if (fromTuples.isEmpty()) {
            out = Collections.emptyList();
        } else {
            out = fromTuples.subList(0, 1);
        }
        return out.listIterator();
    }
}
 
Example 20
Project: hadoop-oss   File: Configuration.java   Source Code and License 5 votes vote down vote up
private <T> void toString(List<T> resources, StringBuilder sb) {
  ListIterator<T> i = resources.listIterator();
  while (i.hasNext()) {
    if (i.nextIndex() != 0) {
      sb.append(", ");
    }
    sb.append(i.next());
  }
}
 
Example 21
Project: Reer   File: AstUtils.java   Source Code and License 5 votes vote down vote up
public static void filterAndTransformStatements(SourceUnit source, StatementTransformer transformer) {
    ListIterator<Statement> statementIterator = source.getAST().getStatementBlock().getStatements().listIterator();
    while (statementIterator.hasNext()) {
        Statement originalStatement = statementIterator.next();
        Statement transformedStatement = transformer.transform(source, originalStatement);
        if (transformedStatement == null) {
            statementIterator.remove();
        } else if (transformedStatement != originalStatement) {
            statementIterator.set(transformedStatement);
        }
    }
}
 
Example 22
Project: athena   File: BgpFlowSpecNlri.java   Source Code and License 5 votes vote down vote up
/**
 * Update buffer with non-identical flow types.
 *
 * @param cb channel buffer
 */
public static void updateBufferNonIdenticalFlowTypes(ChannelBuffer cb, BgpFlowSpecNlri bgpFlowSpecNlri) {
    ChannelBuffer flowSpecTmpBuff = ChannelBuffers.dynamicBuffer();
    List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents();
    ListIterator<BgpValueType> listIterator = flowSpec.listIterator();
    int tmpBuffStartIndx = flowSpecTmpBuff.writerIndex();

    flowSpec = bgpFlowSpecNlri.flowSpecComponents();
    listIterator = flowSpec.listIterator();

    while (listIterator.hasNext()) {
        BgpValueType tlv = listIterator.next();
        writeFlowType(tlv, flowSpecTmpBuff);
    }

    /* RFC 5575: section 4,  If the NLRI length value is smaller than 240 (0xf0 hex), the length
                             field can be encoded as a single octet.  Otherwise, it is encoded as
                             an extended-length 2-octet values */
    int len = flowSpecTmpBuff.writerIndex() - tmpBuffStartIndx;
    if (len >= FLOW_SPEC_LEN) {
        cb.writeShort(len);
    } else {
        cb.writeByte(len);
    }
    //Copy from bynamic buffer to channel buffer
    cb.writeBytes(flowSpecTmpBuff);
}
 
Example 23
Project: Reer   File: StatementReplacingVisitorSupport.java   Source Code and License 5 votes vote down vote up
/**
 * Visits the statements in the specified mutable list. If a statement's
 * visit method calls replaceVisitedMethodWith(), the statement will be
 * replaced.
 */
@SuppressWarnings("unchecked")
protected <T extends Statement> void replaceAll(List<T> stats) {
  ListIterator<T> iter = stats.listIterator();
    while (iter.hasNext()) {
        iter.set((T) replace(iter.next()));
    }
}
 
Example 24
Project: Reer   File: FilteredList.java   Source Code and License 5 votes vote down vote up
public ListIterator<S> listIterator(int index) {
    ListIterator<S> iterator = listIterator();
    for (int i = 0; i < index; i++) {
        iterator.next();
    }
    return iterator;
}
 
Example 25
Project: node-boilerpipe   File: IgnoreBlocksAfterContentFromEndFilter.java   Source Code and License 5 votes vote down vote up
public boolean process(TextDocument doc) throws BoilerpipeProcessingException {
  boolean changes = false;

  int words = 0;

  List<TextBlock> blocks = doc.getTextBlocks();
  if (!blocks.isEmpty()) {
    ListIterator<TextBlock> it = blocks.listIterator(blocks.size());

    TextBlock tb;

    while (it.hasPrevious()) {
      tb = it.previous();
      if (tb.hasLabel(DefaultLabels.INDICATES_END_OF_TEXT)) {
        tb.addLabel(DefaultLabels.STRICTLY_NOT_CONTENT);
        tb.removeLabel(DefaultLabels.MIGHT_BE_CONTENT);
        tb.setIsContent(false);
        changes = true;
      } else if (tb.isContent()) {
        words += tb.getNumWords();
        if (words > 200) {
          break;
        }
      }

    }
  }

  return changes;
}
 
Example 26
Project: hanlpStudy   File: WordBasedGenerativeModelSegment.java   Source Code and License 5 votes vote down vote up
private static void SplitMiddleSlashFromDigitalWords(
		List<Vertex> linkedArray) {
	if (linkedArray.size() < 2)
		return;

	ListIterator<Vertex> listIterator = linkedArray.listIterator();
	Vertex next = listIterator.next();
	Vertex current = next;
	while (listIterator.hasNext()) {
		next = listIterator.next();
		// System.out.println("current:" + current + " next:" + next);
		Nature currentNature = current.getNature();
		if (currentNature == Nature.nx
				&& (next.hasNature(Nature.q) || next.hasNature(Nature.n))) {
			String[] param = current.realWord.split("-", 1);
			if (param.length == 2) {
				if (TextUtility.isAllNum(param[0])
						&& TextUtility.isAllNum(param[1])) {
					current = current.copy();
					current.realWord = param[0];
					current.confirmNature(Nature.m);
					listIterator.previous();
					listIterator.previous();
					listIterator.set(current);
					listIterator.next();
					listIterator.add(Vertex.newPunctuationInstance("-"));
					listIterator.add(Vertex.newNumberInstance(param[1]));
				}
			}
		}
		current = next;
	}

	// logger.trace("杠号识别后:" + Graph.parseResult(linkedArray));
}
 
Example 27
Project: ContentAssist   File: diff_match_patch.java   Source Code and License 5 votes vote down vote up
/**
 * Do a quick line-level diff on both strings, then rediff the parts for
 * greater accuracy.
 * This speedup can produce non-minimal diffs.
 * @param text1 Old string to be diffed.
 * @param text2 New string to be diffed.
 * @param deadline Time when the diff should be complete by.
 * @return Linked List of Diff objects.
 */
private LinkedList<Diff> diff_lineMode(String text1, String text2,
                                       long deadline) {
  // Scan the text on a line-by-line basis first.
  LinesToCharsResult b = diff_linesToChars(text1, text2);
  text1 = b.chars1;
  text2 = b.chars2;
  List<String> linearray = b.lineArray;

  LinkedList<Diff> diffs = diff_main(text1, text2, false, deadline);

  // Convert the diff back to original text.
  diff_charsToLines(diffs, linearray);
  // Eliminate freak matches (e.g. blank lines)
  diff_cleanupSemantic(diffs);

  // Rediff any replacement blocks, this time character-by-character.
  // Add a dummy entry at the end.
  diffs.add(new Diff(Operation.EQUAL, ""));
  int count_delete = 0;
  int count_insert = 0;
  String text_delete = "";
  String text_insert = "";
  ListIterator<Diff> pointer = diffs.listIterator();
  Diff thisDiff = pointer.next();
  while (thisDiff != null) {
    switch (thisDiff.operation) {
    case INSERT:
      count_insert++;
      text_insert += thisDiff.text;
      break;
    case DELETE:
      count_delete++;
      text_delete += thisDiff.text;
      break;
    case EQUAL:
      // Upon reaching an equality, check for prior redundancies.
      if (count_delete >= 1 && count_insert >= 1) {
        // Delete the offending records and add the merged ones.
        pointer.previous();
        for (int j = 0; j < count_delete + count_insert; j++) {
          pointer.previous();
          pointer.remove();
        }
        for (Diff newDiff : diff_main(text_delete, text_insert, false,
            deadline)) {
          pointer.add(newDiff);
        }
      }
      count_insert = 0;
      count_delete = 0;
      text_delete = "";
      text_insert = "";
      break;
    }
    thisDiff = pointer.hasNext() ? pointer.next() : null;
  }
  diffs.removeLast();  // Remove the dummy entry at the end.

  return diffs;
}
 
Example 28
Project: LightSIP   File: SIPMessage.java   Source Code and License 5 votes vote down vote up
/**
 * Set a header from a linked list of headers.
 *
 * @param headers -- a list of headers to set.
 */
public void setHeaders(java.util.List<SIPHeader> headers) {
    ListIterator<SIPHeader> listIterator = headers.listIterator();
    while (listIterator.hasNext()) {
        SIPHeader sipHeader = (SIPHeader) listIterator.next();
        try {
            this.attachHeader(sipHeader, false);
        } catch (SIPDuplicateHeaderException ex) {
        }
    }
}
 
Example 29
Project: athena   File: BgpFlowSpecNlri.java   Source Code and License 5 votes vote down vote up
/**
 * Update buffer with identical flow types.
 *
 * @param cb channel buffer
 */
public static void updateBufferIdenticalFlowTypes(ChannelBuffer cb, BgpFlowSpecNlri bgpFlowSpecNlri) {

    List<BgpValueType> flowSpec = bgpFlowSpecNlri.flowSpecComponents();
    ListIterator<BgpValueType> listIterator = flowSpec.listIterator();

    while (listIterator.hasNext()) {
        ChannelBuffer flowSpecTmpBuff = ChannelBuffers.dynamicBuffer();
        int tmpBuffStartIndx = flowSpecTmpBuff.writerIndex();

        BgpValueType tlv = listIterator.next();
        writeFlowType(tlv, flowSpecTmpBuff);

        /* RFC 5575: section 4,  If the NLRI length value is smaller than 240 (0xf0 hex), the length
                                 field can be encoded as a single octet.  Otherwise, it is encoded as
                                 an extended-length 2-octet values */
        int len = flowSpecTmpBuff.writerIndex() - tmpBuffStartIndx;
        if (len >= FLOW_SPEC_LEN) {
            cb.writeShort(len);
        } else {
            cb.writeByte(len);
        }
        //Copy from bynamic buffer to channel buffer
        cb.writeBytes(flowSpecTmpBuff);
    }
    return;
}
 
Example 30
Project: GitHub   File: BaseRecyclerAdapter.java   Source Code and License 5 votes vote down vote up
/** 移除一条数据 */
public void removeItem(T item) {
    int position = 0;
    ListIterator<T> iterator = mDatas.listIterator();
    while (iterator.hasNext()) {
        T next = iterator.next();
        if (next == item) {
            iterator.remove();
            notifyItemRemoved(position);
        }
        position++;
    }
}
 
Example 31
Project: LivroJavaComoProgramar10Edicao   File: ListTest.java   Source Code and License 5 votes vote down vote up
private static void printReversedList(List<String> list)
{
   ListIterator<String> iterator = list.listIterator(list.size());

   System.out.printf("%nReversed List:%n");

   // print list in reverse order
   while (iterator.hasPrevious()) 
      System.out.printf("%s ", iterator.previous()); 
}
 
Example 32
Project: KSP-AGuS-Automatic-Guidance-System   File: TRANSFER_HOHMANN.java   Source Code and License 5 votes vote down vote up
/**
 * Will delete Maneuvers that had errors while creating
 */
private void deleteEmptyManeuver() {
	List<Integer> li = new ArrayList<Integer>();
	ListIterator<MANEUVER> mi = getManeuverList().listIterator();
	while (mi.hasNext()) {
		if (mi.next().errors()) {
			mi.remove();
		}
	}

}
 
Example 33
Project: OpenJSharp   File: DefaultKeyboardFocusManager.java   Source Code and License 5 votes vote down vote up
/**
 * Delays dispatching of KeyEvents until the specified Component becomes
 * the focus owner. KeyEvents with timestamps later than the specified
 * timestamp will be enqueued until the specified Component receives a
 * FOCUS_GAINED event, or the AWT cancels the delay request by invoking
 * <code>dequeueKeyEvents</code> or <code>discardKeyEvents</code>.
 *
 * @param after timestamp of current event, or the current, system time if
 *        the current event has no timestamp, or the AWT cannot determine
 *        which event is currently being handled
 * @param untilFocused Component which will receive a FOCUS_GAINED event
 *        before any pending KeyEvents
 * @see #dequeueKeyEvents
 * @see #discardKeyEvents
 */
protected synchronized void enqueueKeyEvents(long after,
                                             Component untilFocused) {
    if (untilFocused == null) {
        return;
    }

    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
        focusLog.finer("Enqueue at {0} for {1}",
                   after, untilFocused);
    }

    int insertionIndex = 0,
        i = typeAheadMarkers.size();
    ListIterator<TypeAheadMarker> iter = typeAheadMarkers.listIterator(i);

    for (; i > 0; i--) {
        TypeAheadMarker marker = iter.previous();
        if (marker.after <= after) {
            insertionIndex = i;
            break;
        }
    }

    typeAheadMarkers.add(insertionIndex,
                         new TypeAheadMarker(after, untilFocused));
}
 
Example 34
Project: GitHub   File: RealmList.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@Nonnull
public ListIterator<E> listIterator(int location) {
    if (isManaged()) {
        return new RealmListItr(location);
    } else {
        return super.listIterator(location);
    }
}
 
Example 35
Project: xdman   File: UnixFTPEntryParser.java   Source Code and License 5 votes vote down vote up
/**
 * Preparse the list to discard "total nnn" lines
 */
@Override
public List<String> preParse(List<String> original) {
    ListIterator<String> iter = original.listIterator();
    while (iter.hasNext()) {
        String entry = iter.next();
        if (entry.matches("^total \\d+$")) { // NET-389
            iter.remove();
        }
    }
    return original;
}
 
Example 36
Project: FactionsXL   File: FDefaultSidebar.java   Source Code and License 5 votes vote down vote up
public List<String> getOutput(FPlayer fplayer, List<String> content) {
    content = new ArrayList<>(content);
    ListIterator<String> it = content.listIterator();
    while (it.hasNext()) {
        it.set(replaceTags(fplayer, it.next()));
    }

    return content;
}
 
Example 37
Project: googles-monorepo-demo   File: Lists.java   Source Code and License 5 votes vote down vote up
/**
 * An implementation of {@link List#lastIndexOf(Object)}.
 */
static int lastIndexOfImpl(List<?> list, @Nullable Object element) {
  if (list instanceof RandomAccess) {
    return lastIndexOfRandomAccess(list, element);
  } else {
    ListIterator<?> listIterator = list.listIterator(list.size());
    while (listIterator.hasPrevious()) {
      if (Objects.equal(element, listIterator.previous())) {
        return listIterator.nextIndex();
      }
    }
    return -1;
  }
}
 
Example 38
Project: xsharing-services-router   File: RouteLegFactory.java   Source Code and License 5 votes vote down vote up
private static StationRepresentation extractStation(ListIterator<StationRepresentation> iterator) throws Exception {
    if (iterator.hasNext()) {
        return iterator.next();

    } else {
        throw new Exception();
    }
}
 
Example 39
Project: openjdk-jdk10   File: GraalCompilerTest.java   Source Code and License 5 votes vote down vote up
protected PhaseSuite<HighTierContext> getCustomGraphBuilderSuite(GraphBuilderConfiguration gbConf) {
    PhaseSuite<HighTierContext> suite = getDefaultGraphBuilderSuite();
    ListIterator<BasePhase<? super HighTierContext>> iterator = suite.findPhase(GraphBuilderPhase.class);
    initializeInvocationPluginExtensions();
    GraphBuilderConfiguration gbConfCopy = editGraphBuilderConfiguration(gbConf.copy());
    iterator.remove();
    iterator.add(new GraphBuilderPhase(gbConfCopy));
    return suite;
}
 
Example 40
Project: googles-monorepo-demo   File: Lists.java   Source Code and License 5 votes vote down vote up
@Override
public ListIterator<T> listIterator(int index) {
  return new TransformedListIterator<F, T>(fromList.listIterator(index)) {
    @Override
    T transform(F from) {
      return function.apply(from);
    }
  };
}