java.util.ListIterator.hasNext()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中java.util.ListIterator.hasNext()方法的一些代码示例,展示了ListIterator.hasNext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ListIterator.hasNext()方法的具体详情如下:
包路径:java.util.ListIterator
类名称:ListIterator
方法名:hasNext

ListIterator.hasNext介绍

[英]Returns true if this list iterator has more elements when traversing the list in the forward direction. (In other words, returns true if #next would return an element rather than throwing an exception.)
[中]如果此列表迭代器在正向遍历列表时包含更多元素,则返回true。(换句话说,如果#next将返回元素而不是抛出异常,则返回true。)

代码示例

代码示例来源: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

public static <E> void fill(List<E> list, E value)
{
  if (list == null) return;
  ListIterator<E> listIterator = list.listIterator();
  while (listIterator.hasNext()) listIterator.set(value);
}

代码示例来源: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: 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

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: 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: 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: 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: google/guava

private void replaceValue(List<Entry<K, V>> expected, Entry<K, V> newEntry) {
 for (ListIterator<Entry<K, V>> i = expected.listIterator(); i.hasNext(); ) {
  if (Helpers.equal(i.next().getKey(), newEntry.getKey())) {
   i.set(newEntry);
   return;
  }
 }
 throw new IllegalArgumentException(
   Platform.format("key %s not found in entries %s", newEntry.getKey(), expected));
}

代码示例来源:origin: org.apache.commons/commons-lang3

int getMaxWidth(final ListIterator<StrategyAndWidth> lt) {
    if(!strategy.isNumber() || !lt.hasNext()) {
      return 0;
    }
    final Strategy nextStrategy = lt.next().strategy;
    lt.previous();
    return nextStrategy.isNumber() ?width :0;
  }
}

代码示例来源:origin: prestodb/presto

/** An implementation of {@link List#indexOf(Object)}. */
static int indexOfImpl(List<?> list, @NullableDecl 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: hankcs/HanLP

/**
 * 随机挑一个近义词
 * @param type 类型
 * @return
 */
public Synonym randomSynonym(Type type, String preWord)
{
  ArrayList<Synonym> synonymArrayList = new ArrayList<Synonym>(synonymList);
  ListIterator<Synonym> listIterator = synonymArrayList.listIterator();
  if (type != null) while (listIterator.hasNext())
  {
    Synonym synonym = listIterator.next();
    if (synonym.type != type || (preWord != null && CoreBiGramTableDictionary.getBiFrequency(preWord, synonym.realWord) == 0)) listIterator.remove();
  }
  if (synonymArrayList.size() == 0) return null;
  return synonymArrayList.get((int) (System.currentTimeMillis() % (long)synonymArrayList.size()));
}

代码示例来源:origin: redisson/redisson

private void testExistingField(String name, String descriptor)
    throws DuplicateMemberException {
  ListIterator it = fields.listIterator(0);
  while (it.hasNext()) {
    FieldInfo minfo = (FieldInfo)it.next();
    if (minfo.getName().equals(name))
      throw new DuplicateMemberException("duplicate field: " + name);
  }
}

代码示例来源: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: redisson/redisson

@Override
  public synchronized T get() {
    if(iter.hasNext()) {
      T obj = iter.next().get();
      if(null != obj) {
        return obj;
      }
    } else if(iter.hasPrevious()) {
      // rewind
      while(iter.hasPrevious()) {
        iter.previous();
      }
      return get();
    }
    return null;
  }
};

代码示例来源:origin: hankcs/HanLP

/**
 * 将一个词语从词网中彻底抹除
 * @param cur 词语
 * @param wordNetAll 词网
 * @param line 当前扫描的行数
 * @param length 当前缓冲区的长度
 */
private static void removeFromWordNet(Vertex cur, WordNet wordNetAll, int line, int length)
{
  LinkedList<Vertex>[] vertexes = wordNetAll.getVertexes();
  // 将其从wordNet中删除
  for (Vertex vertex : vertexes[line + length])
  {
    if (vertex.from == cur)
      vertex.from = null;
  }
  ListIterator<Vertex> iterator = vertexes[line + length - cur.realWord.length()].listIterator();
  while (iterator.hasNext())
  {
    Vertex vertex = iterator.next();
    if (vertex == cur) iterator.remove();
  }
}

代码示例来源:origin: redisson/redisson

private void testExistingMethod(MethodInfo newMinfo)
  throws DuplicateMemberException
{
  String name = newMinfo.getName();
  String descriptor = newMinfo.getDescriptor();
  ListIterator it = methods.listIterator(0);
  while (it.hasNext())
    if (isDuplicated(newMinfo, name, descriptor, (MethodInfo)it.next(), it))
      throw new DuplicateMemberException("duplicate method: " + name
                        + " in " + this.getName());
}

代码示例来源:origin: hankcs/HanLP

protected void filter(List<Term> termList)
{
  ListIterator<Term> listIterator = termList.listIterator();
  while (listIterator.hasNext())
  {
    if (!shouldInclude(listIterator.next()))
      listIterator.remove();
  }
}

相关文章