/** * 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); } }
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; }
@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(); } }; } }; }
/** * 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); }
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; } }
/** * 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")); }
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; } } } } }
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; }
/** * 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; }
/** * 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")); }
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 }
/** * 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]+")); }
/** * 切分为句子形式 * * @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; }
/** * 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]")); }
/** * 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\"")); }
/** * 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")); }
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); } }); }
<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(); } }
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()); } }
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); } } }
/** * 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); }
/** * 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())); } }
public ListIterator<S> listIterator(int index) { ListIterator<S> iterator = listIterator(); for (int i = 0; i < index; i++) { iterator.next(); } return iterator; }
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; }
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)); }
/** * 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; }
/** * 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) { } } }
/** * 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; }
/** 移除一条数据 */ 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++; } }
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()); }
/** * 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(); } } }
/** * 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)); }
/** * {@inheritDoc} */ @Override @Nonnull public ListIterator<E> listIterator(int location) { if (isManaged()) { return new RealmListItr(location); } else { return super.listIterator(location); } }
/** * 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; }
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; }
/** * 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; } }
private static StationRepresentation extractStation(ListIterator<StationRepresentation> iterator) throws Exception { if (iterator.hasNext()) { return iterator.next(); } else { throw new Exception(); } }
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; }
@Override public ListIterator<T> listIterator(int index) { return new TransformedListIterator<F, T>(fromList.listIterator(index)) { @Override T transform(F from) { return function.apply(from); } }; }
public String getPath() { synchronized (children) { SequenceEncoder se = new SequenceEncoder('/'); List<Node> path = getPathList(); for (ListIterator<Node> i = path.listIterator(path.size()); i.hasPrevious(); ) { se.append(i.previous().getId()); } return se.getValue(); } }