List of usage examples for java.util ListIterator ListIterator
ListIterator
From source file:Main.java
/** * Returns a list iterator that swaps all previous/next calls. * <p><b>Important:</b> The returned iterator violates the {@link ListIterator#nextIndex()} and {@link ListIterator#previousIndex()} specifications. *//*from w w w . j ava 2 s. c o m*/ public static <E> ListIterator<E> reverse(ListIterator<E> iterator) { return new ListIterator<E>() { @Override public boolean hasNext() { return iterator.hasPrevious(); } @Override public E next() { return iterator.previous(); } @Override public boolean hasPrevious() { return iterator.hasNext(); } @Override public E previous() { return iterator.next(); } @Override public int nextIndex() { return iterator.previousIndex(); } @Override public int previousIndex() { return iterator.nextIndex(); } @Override public void remove() { iterator.remove(); } @Override public void set(E e) { iterator.set(e); } @Override public void add(E e) { iterator.add(e); } }; }
From source file:Main.java
/** * Wraps an <code>ListIterator</code> and returns a <code>ListIterator</code> * that cannot modify the underlying list. * All methods that could be used to modify the list throw * <code>UnsupportedOperationException</code> * @param underlying original list iterator * @param <T> element type/*from w w w . j a v a 2 s . co m*/ * @return unmodifiable list iterator */ @Nonnull public static <T> ListIterator<T> unmodifiableListIterator(final @Nonnull ListIterator<T> underlying) { return new ListIterator<T>() { public boolean hasNext() { return underlying.hasNext(); } public T next() { return underlying.next(); } public boolean hasPrevious() { return underlying.hasPrevious(); } public T previous() { return underlying.previous(); } public int nextIndex() { return underlying.nextIndex(); } public int previousIndex() { return underlying.previousIndex(); } public void remove() { throw new UnsupportedOperationException(); } public void set(T t) { throw new UnsupportedOperationException(); } public void add(T t) { throw new UnsupportedOperationException(); } }; }
From source file:com.replaymod.replaystudio.studio.StudioReplayPartView.java
@Override public ListIterator<PacketData> iterator() { return new ListIterator<PacketData>() { private final ListIterator<PacketData> org = IteratorUtils.filteredListIterator(viewed.iterator(), (p) -> p.getTime() >= from && p.getTime() <= to); @Override// w w w. j a v a 2 s . co m public boolean hasNext() { return org.hasNext(); } @Override public PacketData next() { PacketData next = org.next(); return new PacketData(next.getTime() - from, next.getPacket()); } @Override public boolean hasPrevious() { return org.hasPrevious(); } @Override public PacketData previous() { PacketData next = org.previous(); return new PacketData(next.getTime() - from, next.getPacket()); } @Override public int nextIndex() { return org.nextIndex(); } @Override public int previousIndex() { return org.previousIndex(); } @Override public void remove() { org.remove(); } @Override public void set(PacketData packetData) { org.set(new PacketData(packetData.getTime() + from, packetData.getPacket())); } @Override public void add(PacketData packetData) { org.add(new PacketData(packetData.getTime() + from, packetData.getPacket())); } }; }
From source file:com.projity.grouping.core.NodeBridge.java
static ListIterator emptyListIterator() { return new ListIterator() { public boolean hasNext() { return false; }/* w ww . j a v a2s . c o m*/ public Object next() { return null; } public void remove() { throw new UnsupportedOperationException(); } public void add(Object o) { } public boolean hasPrevious() { return false; } public int nextIndex() { return 0; } public Object previous() { return null; } public int previousIndex() { return -1; } public void set(Object o) { } }; }
From source file:com.addthis.hydra.data.io.DiskBackedList2.java
@Override public ListIterator<K> listIterator(final int ind) { try {/* w w w. ja v a 2 s.c o m*/ if (currentChunk != null) { currentChunk.saveToFile(); } } catch (IOException ex) { log.warn("[disk.backed.list] exception during saving", ex); return null; } return new ListIterator<K>() { private int index = ind; @Override public boolean hasNext() { return index < totalItems; } @Override public K next() { return get(index++); } @Override public void remove() { throw new UnsupportedOperationException(); } @Override public void add(K e) { DiskBackedList2.this.add(e); } @Override public boolean hasPrevious() { return index > 0; } @Override public int nextIndex() { return index; } @Override public K previous() { return get(index--); } @Override public int previousIndex() { return index - 1; } @Override public void set(K e) { throw new UnsupportedOperationException(); } }; }
From source file:org.apache.hadoop.hive.ql.exec.persistence.FlatRowContainer.java
private ListIterator<Object> listIteratorInternal(final int index, final int iterMinPos, final int iterMaxPos) { return new ListIterator<Object>() { private int pos = index - 1; public int nextIndex() { return pos + 1; }/*from ww w . j av a2 s . co m*/ public int previousIndex() { return pos - 1; } public boolean hasNext() { return nextIndex() < iterMaxPos; } public boolean hasPrevious() { return previousIndex() >= iterMinPos; } public Object next() { if (!hasNext()) throw new NoSuchElementException(); return get(++pos); } public Object previous() { if (!hasPrevious()) throw new NoSuchElementException(); return get(--pos); } public void remove() { throw new UnsupportedOperationException(); } public void set(Object e) { throw new UnsupportedOperationException(); } public void add(Object e) { throw new UnsupportedOperationException(); } }; // end ListIterator }