本文整理了Java中java.util.ListIterator.next()
方法的一些代码示例,展示了ListIterator.next()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ListIterator.next()
方法的具体详情如下:
包路径:java.util.ListIterator
类名称:ListIterator
方法名:next
[英]Returns the next element in the list and advances the cursor position. This method may be called repeatedly to iterate through the list, or intermixed with calls to #previous to go back and forth. (Note that alternating calls to next and previouswill return the same element repeatedly.)
[中]返回列表中的下一个元素并前进光标位置。此方法可以重复调用以遍历列表,也可以与对#previous的调用混合在一起来回调用。(请注意,交替调用next和previous将重复返回相同的元素。)
代码示例来源:origin: hankcs/HanLP
/**
* Delete removed documents from the internal container.
*/
void refresh()
{
ListIterator<Document<K>> listIterator = documents_.listIterator();
while (listIterator.hasNext())
{
if (listIterator.next() == null)
listIterator.remove();
}
}
代码示例来源:origin: hankcs/HanLP
private static void mergeDate(ListIterator<Vertex> listIterator, Vertex next, Vertex current)
{
current = Vertex.newTimeInstance(current.realWord + next.realWord);
listIterator.previous();
listIterator.previous();
listIterator.set(current);
listIterator.next();
listIterator.next();
listIterator.remove();
}
代码示例来源:origin: google/guava
/** An implementation of {@link List#indexOf(Object)}. */
static int indexOfImpl(List<?> list, @Nullable Object element) {
if (list instanceof RandomAccess) {
return indexOfRandomAccess(list, element);
} else {
ListIterator<?> listIterator = list.listIterator();
while (listIterator.hasNext()) {
if (Objects.equal(element, listIterator.next())) {
return listIterator.previousIndex();
}
}
return -1;
}
}
代码示例来源:origin: spockframework/spock
private void moveInteractions(List<Statement> interactions, ThenBlock block) {
if (interactions.isEmpty()) return;
ListIterator<Statement> listIterator = block.getAst().listIterator();
while (listIterator.hasNext()) {
Statement next = listIterator.next();
if (interactions.contains(next)) listIterator.remove();
}
List<Statement> statsBeforeWhenBlock = block.getPrevious(WhenBlock.class).getPrevious().getAst();
statsBeforeWhenBlock.add(createMockControllerCall(
block.isFirstInChain() ? MockController.ENTER_SCOPE : MockController.ADD_BARRIER));
statsBeforeWhenBlock.addAll(interactions);
if (block.isFirstInChain())
// insert at beginning of then-block rather than end of when-block
// s.t. it's outside of try-block inserted for exception conditions
block.getAst().add(0, createMockControllerCall(MockController.LEAVE_SCOPE));
}
代码示例来源:origin: jphp-group/jphp
@Test
public void testNoArguments() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("function myFunc(){}"));
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
Assert.assertTrue(analyzer.getTree().size() == 1);
Assert.assertTrue(analyzer.getTree().get(0) instanceof FunctionStmtToken);
FunctionStmtToken func = (FunctionStmtToken)analyzer.getTree().listIterator().next();
Assert.assertTrue(func.getArguments().size() == 0);
}
代码示例来源:origin: commons-collections/commons-collections
public void testBugCollections447() {
final List treeList = new TreeList();
treeList.add("A");
treeList.add("B");
treeList.add("C");
treeList.add("D");
final ListIterator li = treeList.listIterator();
assertEquals("A", li.next());
assertEquals("B", li.next());
assertEquals("B", li.previous());
li.remove(); // Deletes "B"
// previous() after remove() should move to
// the element before the one just removed
assertEquals("A", li.previous());
}
}
代码示例来源:origin: jphp-group/jphp
@Override
public boolean hasNext() {
int offset = 0;
while (iterator.hasNext()){
offset++;
if (iterator.next() == null){
} else
break;
}
for(int i = 0; i < offset; i++)
iterator.previous();
return offset > 0;
}
代码示例来源:origin: google/guava
private static void assertTransformListIterator(List<String> list) {
ListIterator<String> iterator = list.listIterator(1);
assertEquals(1, iterator.nextIndex());
assertEquals("2", iterator.next());
assertEquals("3", iterator.next());
assertEquals("4", iterator.next());
assertEquals(4, iterator.nextIndex());
try {
iterator.next();
fail("did not detect end of list");
} catch (NoSuchElementException expected) {
assertEquals("4", iterator.previous());
assertEquals("3", iterator.previous());
assertEquals("2", iterator.previous());
assertTrue(iterator.hasPrevious());
assertEquals("1", iterator.previous());
} catch (NoSuchElementException expected) {
iterator.remove();
assertEquals(asList("2", "3", "4"), list);
assertFalse(list.isEmpty());
iterator.set("1");
fail("transformed list iterator is settable");
} catch (UnsupportedOperationException expected) {
代码示例来源:origin: google/guava
public void testEmptyListIterator() {
ListIterator<String> iterator = Iterators.emptyListIterator();
assertFalse(iterator.hasNext());
assertFalse(iterator.hasPrevious());
assertEquals(0, iterator.nextIndex());
assertEquals(-1, iterator.previousIndex());
try {
iterator.next();
fail("no exception thrown");
} catch (NoSuchElementException expected) {
iterator.previous();
fail("no exception thrown");
} catch (NoSuchElementException expected) {
iterator.remove();
fail("no exception thrown");
} catch (UnsupportedOperationException expected) {
iterator.set("a");
fail("no exception thrown");
} catch (UnsupportedOperationException expected) {
代码示例来源:origin: redisson/redisson
static synchronized AttributeInfo remove(ArrayList list, String name) {
if (list == null)
return null;
AttributeInfo removed = null;
ListIterator iterator = list.listIterator();
while (iterator.hasNext()) {
AttributeInfo ai = (AttributeInfo)iterator.next();
if (ai.getName().equals(name)) {
iterator.remove();
removed = ai;
}
}
return removed;
}
代码示例来源:origin: greenrobot/greenDAO
void appendWhereClause(StringBuilder builder, String tablePrefixOrNull, List<Object> values) {
ListIterator<WhereCondition> iter = whereConditions.listIterator();
while (iter.hasNext()) {
if (iter.hasPrevious()) {
builder.append(" AND ");
}
WhereCondition condition = iter.next();
condition.appendTo(builder, tablePrefixOrNull);
condition.appendValuesTo(values);
}
}
代码示例来源:origin: google/guava
/**
* {@inheritDoc}
*
* <p>If any entries for the specified {@code key} already exist in the multimap, their values are
* changed in-place without affecting the iteration order.
*
* <p>The returned list is immutable and implements {@link java.util.RandomAccess}.
*/
@CanIgnoreReturnValue
@Override
public List<V> replaceValues(@Nullable K key, Iterable<? extends V> values) {
List<V> oldValues = getCopy(key);
ListIterator<V> keyValues = new ValueForKeyIterator(key);
Iterator<? extends V> newValues = values.iterator();
// Replace existing values, if any.
while (keyValues.hasNext() && newValues.hasNext()) {
keyValues.next();
keyValues.set(newValues.next());
}
// Remove remaining old values, if any.
while (keyValues.hasNext()) {
keyValues.next();
keyValues.remove();
}
// Add remaining new values, if any.
while (newValues.hasNext()) {
keyValues.add(newValues.next());
}
return oldValues;
}
代码示例来源:origin: google/guava
public void testSet() {
ListIterator<String> iterator = create();
assertTrue(iterator.hasNext());
assertEquals("a", iterator.next());
assertEquals("b", iterator.next());
assertEquals("b", iterator.previous());
try {
iterator.set("c");
fail();
} catch (UnsupportedOperationException expected) {
}
}
代码示例来源:origin: redisson/redisson
static AttributeInfo lookup(ArrayList list, String name) {
if (list == null)
return null;
ListIterator iterator = list.listIterator();
while (iterator.hasNext()) {
AttributeInfo ai = (AttributeInfo)iterator.next();
if (ai.getName().equals(name))
return ai;
}
return null; // no such attribute
}
代码示例来源:origin: commons-collections/commons-collections
public void testEmptyListIteratorIsIndeedEmpty() {
ListIterator it = makeEmptyListIterator();
assertEquals(false, it.hasNext());
assertEquals(-1, it.nextIndex()); // reversed index
assertEquals(false, it.hasPrevious());
assertEquals(0, it.previousIndex()); // reversed index
// next() should throw a NoSuchElementException
try {
it.next();
fail("NoSuchElementException must be thrown from empty ListIterator");
} catch (NoSuchElementException e) {
}
// previous() should throw a NoSuchElementException
try {
it.previous();
fail("NoSuchElementException must be thrown from empty ListIterator");
} catch (NoSuchElementException e) {
}
}
代码示例来源:origin: hankcs/HanLP
/**
* Remove a document from this cluster.
*
* @param index the index of vector container of documents
*/
void remove_document(int index)
{
ListIterator<Document<K>> listIterator = documents_.listIterator(index);
Document<K> document = listIterator.next();
listIterator.set(null);
composite_.sub_vector(document.feature());
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public XMLEvent peek() throws XMLStreamException {
if (this.bufferReader != null) {
final XMLEvent event = this.bufferReader.next();
this.bufferReader.previous(); //move the iterator back
return event;
}
return super.peek();
}
代码示例来源:origin: commons-collections/commons-collections
public void testRemoveThenSet() {
ListIterator it = makeFullListIterator();
if (supportsRemove() && supportsSet()) {
it.next();
it.remove();
try {
it.set(addSetValue());
fail("IllegalStateException must be thrown from set after remove");
} catch (IllegalStateException e) {
}
}
}
代码示例来源:origin: google/guava
@Override
public int indexOf(Object o) {
if (!(o instanceof List)) {
return -1;
}
List<?> list = (List<?>) o;
if (list.size() != axes.size()) {
return -1;
}
ListIterator<?> itr = list.listIterator();
int computedIndex = 0;
while (itr.hasNext()) {
int axisIndex = itr.nextIndex();
int elemIndex = axes.get(axisIndex).indexOf(itr.next());
if (elemIndex == -1) {
return -1;
}
computedIndex += elemIndex * axesSizeProduct[axisIndex + 1];
}
return computedIndex;
}
代码示例来源:origin: jphp-group/jphp
@Test
public void testSimple() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("foobar;"));
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
Assert.assertTrue(analyzer.getTree().size() == 1);
Assert.assertTrue(analyzer.getTree().listIterator().next() instanceof ExprStmtToken);
}
内容来源于网络,如有侵权,请联系作者删除!