java.util.ListIterator Java Examples
The following examples show how to use
java.util.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: SortedListTest.java From consulo with Apache License 2.0 | 6 votes |
public void testListIterator() { final SortedList<String> list = createList(); list.add("b"); list.add("c"); final ListIterator<String> iterator = list.listIterator(); assertEquals("b", iterator.next()); assertEquals("c", iterator.next()); assertEquals("c", iterator.previous()); assertEquals("b", iterator.previous()); iterator.add("a"); assertEquals(3, list.size()); list.add("d"); assertEquals(4, list.size()); assertEquals("a", list.get(0)); assertEquals("b", list.get(1)); assertEquals("c", list.get(2)); assertEquals("d", list.get(3)); }
Example #2
Source File: ClosestTrailResolver.java From scipio-erp with Apache License 2.0 | 6 votes |
@Override protected int scoreTrail(List<String> trail, List<String> hintTrail) { int score = 0; ListIterator<String> hintIt = hintTrail.listIterator(hintTrail.size()); int lastTrailMatchIndex = trail.size(); while(hintIt.hasPrevious()) { String hintCatId = hintIt.previous(); int matchIndex = SeoCatalogUrlWorker.lastIndexOf(trail, hintCatId, lastTrailMatchIndex - 1); if (matchIndex > 0) { score++; lastTrailMatchIndex = matchIndex; } else if (matchIndex == 0) { score++; break; } } return score; }
Example #3
Source File: PendingActionCurator.java From p4ic4idea with Apache License 2.0 | 6 votes |
/** * Modify the list of actions by adding in the new action, along with curation of the list due to the changes * caused by adding the new action. The existing list is appended to with each new action (so oldest first). * * @param added new action * @param actions existing list of actions. */ void curateActionList(@NotNull ActionStore.PendingAction added, @NotNull List<ActionStore.PendingAction> actions) { // Curate the pending list of actions. // Curation MUST be done in reverse order of the existing pending actions. final ListIterator<ActionStore.PendingAction> iter = actions.listIterator(actions.size()); while (iter.hasPrevious()) { final ActionStore.PendingAction existingAction = iter.previous(); PendingActionCurator.CurateResult result = curate(added, existingAction); added = result.replacedAdded(added); if (result.removeExisting) { iter.remove(); } else { iter.set(result.replacedExisting(existingAction)); } if (result.removeAdded) { // Halt the add operation return; } if (result.stopSearch) { // Don't look further for curation. break; } } actions.add(added); }
Example #4
Source File: CompositeResourceFactory_impl.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * @see org.apache.uima.ResourceFactory#produceResource(java.lang.Class, * org.apache.uima.resource.ResourceSpecifier, java.util.Map) */ public Resource produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { // check for factories registered for this resource specifier type // (most recently registered first) ListIterator<Registration> it = mRegisteredFactories.listIterator(mRegisteredFactories.size()); Resource result = null; while (it.hasPrevious()) { Registration reg = it.previous(); if (reg.resourceSpecifierInterface.isAssignableFrom(aSpecifier.getClass())) { result = reg.factory.produceResource(aResourceClass, aSpecifier, aAdditionalParams); if (result != null) { return result; } } } return null; }
Example #5
Source File: Locker.java From sumk with Apache License 2.0 | 6 votes |
void remove(final Lock lock) { if (lock == null || lock == Locked.inst) { return; } List<SLock> list = locks.get(); if (list == null || list.isEmpty()) { return; } ListIterator<SLock> it = list.listIterator(list.size()); while (it.hasPrevious()) { SLock lock2 = it.previous(); if (lock2.getId().equals(lock.getId())) { it.remove(); } } }
Example #6
Source File: ConfigRepositoryImpl.java From glowroot with Apache License 2.0 | 6 votes |
@Override public void deleteInstrumentationConfigs(String agentId, List<String> versions) throws Exception { synchronized (writeLock) { List<InstrumentationConfig> configs = Lists.newArrayList(configService.getInstrumentationConfigs()); List<String> remainingVersions = Lists.newArrayList(versions); for (ListIterator<InstrumentationConfig> i = configs.listIterator(); i.hasNext();) { InstrumentationConfig loopConfig = i.next(); String loopVersion = Versions.getVersion(loopConfig.toProto()); if (remainingVersions.contains(loopVersion)) { i.remove(); remainingVersions.remove(loopVersion); } } if (!remainingVersions.isEmpty()) { throw new OptimisticLockException(); } configService.updateInstrumentationConfigs(configs); } }
Example #7
Source File: FunctionSignature.java From swift-t with Apache License 2.0 | 6 votes |
/** * Switch to passing values directly. * Do this before function inlining since function inlining * will clean it up. * @param logger * @param program */ @Override public void optimize(Logger logger, Program program) { Set<FnID> usedFnIDs = new HashSet<FnID>(program.getFunctionMap().keySet()); Map<FnID, Function> toInline = new HashMap<FnID, Function>(); ListIterator<Function> fnIt = program.functionIterator(); while (fnIt.hasNext()) { Function fn = fnIt.next(); Function newFn = switchToValuePassing(logger, program.foreignFunctions(), fn, usedFnIDs); if (newFn != null) { fnIt.remove(); // Remove old function fnIt.add(newFn); usedFnIDs.add(newFn.id()); // We should inline toInline.put(fn.id(), fn); } } // Inline all calls to the old function FunctionInline.inlineAllOccurrences(logger, program, toInline); }
Example #8
Source File: TestObservableArrayListIterators.java From dolphin-platform with Apache License 2.0 | 6 votes |
@Test public void listIteratorHasNextAndHasPreviousOnThreeElementsList_shouldReturnTrueForEachElement() { final ObservableArrayList<String> list = new ObservableArrayList<>("1", "2", "3"); final ListIterator<String> iterator = list.listIterator(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasPrevious(), is(false)); iterator.next(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasPrevious(), is(true)); iterator.next(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasPrevious(), is(true)); iterator.next(); assertThat(iterator.hasNext(), is(false)); assertThat(iterator.hasPrevious(), is(true)); iterator.previous(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasPrevious(), is(true)); iterator.previous(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasPrevious(), is(true)); iterator.previous(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasPrevious(), is(false)); }
Example #9
Source File: StaggeredDelimiterProcessor.java From commonmark-java with BSD 2-Clause "Simplified" License | 6 votes |
void add(DelimiterProcessor dp) { final int len = dp.getMinLength(); ListIterator<DelimiterProcessor> it = processors.listIterator(); boolean added = false; while (it.hasNext()) { DelimiterProcessor p = it.next(); int pLen = p.getMinLength(); if (len > pLen) { it.previous(); it.add(dp); added = true; break; } else if (len == pLen) { throw new IllegalArgumentException("Cannot add two delimiter processors for char '" + delim + "' and minimum length " + len); } } if (!added) { processors.add(dp); this.minLength = len; } }
Example #10
Source File: ExprGenerator.java From jphp with Apache License 2.0 | 6 votes |
protected void processWhile(WhileStmtToken result, ListIterator<Token> iterator){ analyzer.addScope().setLevelForGoto(true); ExprStmtToken condition = getInBraces(BraceExprToken.Kind.SIMPLE, iterator); if (condition == null) unexpectedToken(iterator); BodyStmtToken body = analyzer.generator(BodyGenerator.class).getToken( nextToken(iterator), iterator, EndwhileStmtToken.class ); if (body != null && body.isAlternativeSyntax()) iterator.next(); result.setCondition(condition); result.setBody(body); result.setLocal(analyzer.removeScope().getVariables()); }
Example #11
Source File: GroupbyKey.java From eagle with Apache License 2.0 | 6 votes |
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof GroupbyKey)) { return false; } GroupbyKey that = (GroupbyKey)obj; ListIterator<BytesWritable> e1 = this.value.listIterator(); ListIterator<BytesWritable> e2 = that.value.listIterator(); while (e1.hasNext() && e2.hasNext()) { if (!Arrays.equals(e1.next().getBytes(), e2.next().getBytes())) { return false; } } return !(e1.hasNext() || e2.hasNext()); }
Example #12
Source File: ListenableArrayListTestCase.java From vespa with Apache License 2.0 | 6 votes |
@Test public void testIt() { ListenableArrayList<String> list = new ListenableArrayList<>(); ArrayListListener listener = new ArrayListListener(); list.addListener(listener); assertEquals(0,listener.invoked); list.add("a"); assertEquals(1,listener.invoked); list.add(0,"b"); assertEquals(2,listener.invoked); list.addAll(Arrays.asList(new String[]{"c", "d"})); assertEquals(3,listener.invoked); list.addAll(1,Arrays.asList(new String[]{"e", "f"})); assertEquals(4,listener.invoked); list.set(0,"g"); assertEquals(5,listener.invoked); ListIterator<String> i = list.listIterator(); i.add("h"); assertEquals(6,listener.invoked); i.next(); i.set("i"); assertEquals(7,listener.invoked); }
Example #13
Source File: ReversedIterator.java From cyclops with Apache License 2.0 | 6 votes |
public Iterator<U> reversedIterator() { final ListIterator<U> iterator = list.listIterator(list.size()); return new Iterator<U>() { @Override public boolean hasNext() { return iterator.hasPrevious(); } @Override public U next() { return iterator.previous(); } }; }
Example #14
Source File: FingerTreeTest.java From ReactFX with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testIteration() { final int n = 50000; final int from = 10000; final int to = 40000; Integer[] arr = new Integer[n]; for(int i=0; i<n; ++i) arr[i] = i; List<Integer> list = Arrays.asList(arr); List<Integer> treeList = FingerTree.mkTree(list).asList(); list = list.subList(from, to); treeList = treeList.subList(from, to); ListIterator<Integer> it = treeList.listIterator(); List<Integer> fwRes = new ArrayList<>(treeList.size()); while(it.hasNext()) fwRes.add(it.next()); assertEquals(list, fwRes); List<Integer> bwRes = new ArrayList<>(treeList.size()); while(it.hasPrevious()) bwRes.add(it.previous()); Collections.reverse(bwRes); assertEquals(list, bwRes); }
Example #15
Source File: DialogFragmentDelegate.java From CompositeAndroid with Apache License 2.0 | 6 votes |
public void dismiss() { if (mPlugins.isEmpty()) { getOriginal().super_dismiss(); return; } final ListIterator<DialogFragmentPlugin> iterator = mPlugins.listIterator(mPlugins.size()); final CallVoid0 superCall = new CallVoid0("dismiss()") { @Override public void call() { if (iterator.hasPrevious()) { iterator.previous().dismiss(this); } else { getOriginal().super_dismiss(); } } }; superCall.call(); }
Example #16
Source File: NameGenPanel.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
private void loadFromDocument(Document nameSet) throws DataConversionException { Element generator = nameSet.getRootElement(); java.util.List<?> rulesets = generator.getChildren("RULESET"); java.util.List<?> lists = generator.getChildren("LIST"); ListIterator<?> listIterator = lists.listIterator(); while (listIterator.hasNext()) { Element list = (Element) listIterator.next(); loadList(list); } for (final Object ruleset : rulesets) { Element ruleSet = (Element) ruleset; RuleSet rs = loadRuleSet(ruleSet); allVars.addDataElement(rs); } }
Example #17
Source File: AbstractComponentBuilder.java From adventure with MIT License | 6 votes |
@Override @SuppressWarnings("unchecked") public @NonNull B mapChildrenDeep(final @NonNull Function<BuildableComponent<? ,?>, ? extends BuildableComponent<? ,?>> function) { if(this.children == AbstractComponent.EMPTY_COMPONENT_LIST) { return (B) this; } final ListIterator<Component> it = this.children.listIterator(); while(it.hasNext()) { final Component child = it.next(); if(!(child instanceof BuildableComponent<?, ?>)) { continue; } final BuildableComponent<?, ?> mappedChild = function.apply((BuildableComponent<?, ?>) child); if(mappedChild.children().isEmpty()) { if(child == mappedChild) { continue; } it.set(mappedChild); } else { final ComponentBuilder<?, ?> builder = mappedChild.toBuilder(); builder.mapChildrenDeep(function); it.set(builder.build()); } } return (B) this; }
Example #18
Source File: GenericParser.java From charliebot with GNU General Public License v2.0 | 6 votes |
public int nodeCount(String s, LinkedList linkedlist, boolean flag) { int i = 0; if (linkedlist == null) return 0; for (ListIterator listiterator = linkedlist.listIterator(0); listiterator.hasNext(); ) { XMLNode xmlnode = (XMLNode) listiterator.next(); if (xmlnode != null) switch (xmlnode.XMLType) { default: break; case 0: // '\0' case 1: // '\001' if (xmlnode.XMLData.equals(s) || flag) i++; break; } } return i; }
Example #19
Source File: TestObservableArrayListIterators.java From dolphin-platform with Apache License 2.0 | 6 votes |
@Test (expectedExceptions = NoSuchElementException.class) public void indexedListIteratorAtEndPreviousOnThreeElements_shouldThrowExceptionAtTheBeginning() { final ObservableArrayList<String> list = new ObservableArrayList<>("1", "2", "3"); final ListIterator<String> iterator = list.listIterator(3); iterator.previous(); iterator.next(); iterator.previous(); iterator.previous(); iterator.next(); iterator.previous(); iterator.previous(); iterator.next(); iterator.previous(); iterator.previous(); }
Example #20
Source File: TestObservableArrayListIterators.java From dolphin-platform with Apache License 2.0 | 6 votes |
@Test public void indexedListIteratorAtEndHasNextAndHasPreviousOnThreeElementsList_shouldReturnTrueForEachElement() { final ObservableArrayList<String> list = new ObservableArrayList<>("1", "2", "3"); final ListIterator<String> iterator = list.listIterator(3); assertThat(iterator.hasNext(), is(false)); assertThat(iterator.hasPrevious(), is(true)); iterator.previous(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasPrevious(), is(true)); iterator.previous(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasPrevious(), is(true)); iterator.previous(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.hasPrevious(), is(false)); }
Example #21
Source File: ListSampler.java From commons-rng with Apache License 2.0 | 6 votes |
/** * Shuffles the entries of the given array, using the * <a href="http://en.wikipedia.org/wiki/Fisher-Yates_shuffle#The_modern_algorithm"> * Fisher-Yates</a> algorithm. * * <p> * Sampling uses {@link UniformRandomProvider#nextInt(int)}. * </p> * * @param <T> Type of the list items. * @param rng Random number generator. * @param list List whose entries will be shuffled (in-place). */ @SuppressWarnings({"rawtypes", "unchecked"}) public static <T> void shuffle(UniformRandomProvider rng, List<T> list) { if (list instanceof RandomAccess || list.size() < RANDOM_ACCESS_SIZE_THRESHOLD) { // Shuffle list in-place for (int i = list.size(); i > 1; i--) { swap(list, i - 1, rng.nextInt(i)); } } else { // Shuffle as an array final Object[] array = list.toArray(); for (int i = array.length; i > 1; i--) { swap(array, i - 1, rng.nextInt(i)); } // Copy back. Use raw types. final ListIterator it = list.listIterator(); for (final Object item : array) { it.next(); it.set(item); } } }
Example #22
Source File: FunctionInline.java From swift-t with Apache License 2.0 | 6 votes |
private static void tryInline(Logger logger, Program prog, Function contextFunction, Block block, ListMultimap<FnID, FnID> inlineLocations, Map<FnID, Function> toInline, Set<FnID> alwaysInline, Set<Pair<FnID, FnID>> blacklist, ListIterator<Statement> it, FunctionCall fcall) { if (toInline.containsKey(fcall.functionID()) || alwaysInline.contains(fcall.functionID())) { boolean canInlineHere; if (inlineLocations == null) { canInlineHere = true; } else { // Check that location is marked for inlining List<FnID> inlineCallers = inlineLocations.get(fcall.functionID()); canInlineHere = inlineCallers.contains(contextFunction.id()); } if (canInlineHere) { // Do the inlining. Note that the iterator will be positioned // after any newly inlined instructions. inlineCall(logger, prog, contextFunction, block, it, fcall, toInline.get(fcall.functionID()), alwaysInline, blacklist); } } }
Example #23
Source File: Lists.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
/** * 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 #24
Source File: DerivedEObjectEList.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@Override public List<E> basicList() { return new DerivedEObjectEList<E>(dataClass, owner, featureID, sourceFeatureIDs) { @Override public ListIterator<E> listIterator(int index) { return basicListIterator(index); } }; }
Example #25
Source File: DisplayImagePanel.java From pdfxtk with Apache License 2.0 | 5 votes |
public void setImage(PlanarImage img) { image = new DisplayImage(img, true, true); JLabel imageLabel = new JLabel(image) { protected void paintChildren(Graphics graphics) { super.paintChildren(graphics); if (!(graphics instanceof Graphics2D)) { throw new RuntimeException("DisplayImagePanel requires Graphics2D."); } Graphics2D g2d = (Graphics2D) graphics; Rectangle clipBounds = g2d.getClipBounds(); if (layers != null) { ListIterator layerIter = layers.listIterator(); while (layerIter.hasNext()) { DisplayImageLayer layer = (DisplayImageLayer) layerIter.next(); layer.paintLayer(g2d, clipBounds); } } } }; imageLabel.setHorizontalAlignment(SwingConstants.LEFT); imageLabel.setVerticalAlignment(SwingConstants.TOP); setViewportView(imageLabel); }
Example #26
Source File: Parser.java From big-c with Apache License 2.0 | 5 votes |
/** * Parse a list of comma-separated nodes. */ public void parse(List<Token> args, Configuration conf) throws IOException { ListIterator<Token> i = args.listIterator(); while (i.hasNext()) { Token t = i.next(); t.getNode().setID(i.previousIndex() >> 1); kids.add(t.getNode()); if (i.hasNext() && !TType.COMMA.equals(i.next().getType())) { throw new IOException("Expected ','"); } } }
Example #27
Source File: DefaultKeyboardFocusManager.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 #28
Source File: EventListenerGroupImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private boolean listenerShouldGetAdded(T listener) { if ( listeners == null ) { listeners = new ArrayList<>(); return true; // no need to do de-dup checks } boolean doAdd = true; strategy_loop: for ( DuplicationStrategy strategy : duplicationStrategies ) { final ListIterator<T> itr = listeners.listIterator(); while ( itr.hasNext() ) { final T existingListener = itr.next(); if ( strategy.areMatch( listener, existingListener ) ) { switch ( strategy.getAction() ) { // todo : add debug logging of what happens here... case ERROR: { throw new EventListenerRegistrationException( "Duplicate event listener found" ); } case KEEP_ORIGINAL: { doAdd = false; break strategy_loop; } case REPLACE_ORIGINAL: { itr.set( listener ); doAdd = false; break strategy_loop; } } } } } return doAdd; }
Example #29
Source File: StandardChartSettings.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * Removes a custom hyperlink parameter. * <p> * If multiple parameters having the specified name exist, all of them * will be removed * </p> * * @param parameterName the parameter name */ public void removeHyperlinkParameter(String parameterName) { for (ListIterator<JRHyperlinkParameter> it = hyperlinkParameters.listIterator(); it.hasNext();) { JRHyperlinkParameter parameter = it.next(); if (parameter.getName() != null && parameter.getName().equals(parameterName)) { it.remove(); getEventSupport().fireCollectionElementRemovedEvent(JRDesignHyperlink.PROPERTY_HYPERLINK_PARAMETERS, parameter, it.nextIndex()); } } }
Example #30
Source File: ConcreteNotificationHandlerRegistration.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void registerNotificationHandler(PathAddress source, NotificationHandler handler, NotificationFilter filter) { NotificationHandlerEntry entry = new NotificationHandlerEntry(handler, filter); if (source == ANY_ADDRESS) { anyAddressEntries.add(entry); return; } ListIterator<PathElement> iterator = source.iterator(); rootRegistry.registerEntry(iterator, entry); }