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

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

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

ListIterator.set介绍

[英]Replaces the last element returned by #next or #previous with the specified element (optional operation). This call can be made only if neither #remove nor #add have been called after the last call to next or previous.
[中]将#next或#previous返回的最后一个元素替换为指定的元素(可选操作)。只有在上次调用“下一个”或“上一个”后未调用“删除”或“添加”时,才能进行此调用。

代码示例

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

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: 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: 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: robovm/robovm

@Override
  public E set(int location, E object) {
    ListIterator<E> it = listIterator(location);
    if (!it.hasNext()) {
      throw new IndexOutOfBoundsException();
    }
    E result = it.next();
    it.set(object);
    return result;
  }
}

代码示例来源:origin: spockframework/spock

void replaceMatcherValues(List<Object> values) {
 boolean firstOccurrence = true;
 ListIterator<Object> iter = values.listIterator(values.size());
 while (iter.hasPrevious()) {
  Object value = iter.previous();
  if (!HamcrestFacade.isMatcher(value)) continue;
  if (firstOccurrence) {
   // indicate mismatch in condition output
   iter.set(shortSyntax ? false : ExpressionInfo.VALUE_NOT_AVAILABLE);
   firstOccurrence = false;
  } else {
   // don't show in condition output
   iter.set(ExpressionInfo.VALUE_NOT_AVAILABLE);
  }
 }
}

代码示例来源:origin: code4craft/webmagic

/**
 * Only document can be select
 * See: https://github.com/code4craft/webmagic/issues/113
 *
 * @param elementIterator elementIterator
 * @return element element
 */
private Element checkElementAndConvert(ListIterator<Element> elementIterator) {
  Element element = elementIterator.next();
  if (!(element instanceof Document)) {
    Document root = new Document(element.ownerDocument().baseUri());
    Element clone = element.clone();
    root.appendChild(clone);
    elementIterator.set(root);
    return root;
  }
  return element;
}

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

if (bytesToTrim >= c.length) {
  bytesToTrim -= c.length;
  i.remove();
  continue;
newC.offset = c.offset;
newC.endOffset = newC.offset + newC.length;
i.set(newC);
break;

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

/**
   * 将所有音调都转为1
   * @param pinyinList
   * @return
   */
  public static List<Pinyin> makeToneToTheSame(List<Pinyin> pinyinList)
  {
    ListIterator<Pinyin> listIterator = pinyinList.listIterator();
    while (listIterator.hasNext())
    {
      listIterator.set(convert2Tone5(listIterator.next()));
    }

    return pinyinList;
  }
}

代码示例来源:origin: stackoverflow.com

public static void shuffle(List<?> list, Random rnd) {
  int size = list.size();
  if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
    for (int i=size; i>1; i--)
      swap(list, i-1, rnd.nextInt(i));
  } else {
    Object arr[] = list.toArray();

    // Shuffle array
    for (int i=size; i>1; i--)
      swap(arr, i-1, rnd.nextInt(i));

    // Dump array back into list
    ListIterator it = list.listIterator();
    for (int i=0; i<arr.length; i++) {
      it.next();
      it.set(arr[i]);
    }
  }
}

代码示例来源:origin: org.freemarker/freemarker

@Override
protected Expression deepCloneWithIdentifierReplaced_inner(
    String replacedIdentifier, Expression replacement, ReplacemenetState replacementState) {
  ArrayList clonedValues = (ArrayList) items.clone();
  for (ListIterator iter = clonedValues.listIterator(); iter.hasNext(); ) {
    iter.set(((Expression) iter.next()).deepCloneWithIdentifierReplaced(
        replacedIdentifier, replacement, replacementState));
  }
  return new ListLiteral(clonedValues);
}

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

public void testAddThenSet() {
  ListIterator it = makeFullListIterator();        
  // add then set
  if (supportsAdd() && supportsSet()) {
    it.next();
    it.add(addSetValue());
    try {
      it.set(addSetValue());
      fail("IllegalStateException must be thrown from set after add");
    } catch (IllegalStateException e) {
    }
  }
}

代码示例来源:origin: apache/hive

private List<String> getLowerCaseRoleNames(List<String> roles) {
 ListIterator<String> roleIter = roles.listIterator();
 while (roleIter.hasNext()) {
  roleIter.set(roleIter.next().toLowerCase());
 }
 return roles;
}

代码示例来源:origin: stackoverflow.com

public static void shuffle(List<?> list, Random rnd) {
  int size = list.size();
  if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
    for (int i=size; i>1; i--)
      swap(list, i-1, rnd.nextInt(i));
  } else {
    Object arr[] = list.toArray();

    // Shuffle array
    for (int i=size; i>1; i--)
      swap(arr, i-1, rnd.nextInt(i));

    // Dump array back into list
    ListIterator it = list.listIterator();
    for (int i=0; i<arr.length; i++) {
      it.next();
      it.set(arr[i]);
    }
  }
}

代码示例来源:origin: org.freemarker/freemarker

@Override
protected Expression deepCloneWithIdentifierReplaced_inner(
    String replacedIdentifier, Expression replacement, ReplacemenetState replacementState) {
  ArrayList clonedKeys = (ArrayList) keys.clone();
  for (ListIterator iter = clonedKeys.listIterator(); iter.hasNext(); ) {
    iter.set(((Expression) iter.next()).deepCloneWithIdentifierReplaced(
        replacedIdentifier, replacement, replacementState));
  }
  ArrayList clonedValues = (ArrayList) values.clone();
  for (ListIterator iter = clonedValues.listIterator(); iter.hasNext(); ) {
    iter.set(((Expression) iter.next()).deepCloneWithIdentifierReplaced(
        replacedIdentifier, replacement, replacementState));
  }
  return new HashLiteral(clonedKeys, clonedValues);
}

代码示例来源:origin: commons-collections/commons-collections

listIterator.remove();
  listIterator.set("a");
listIterator.next();
  listIterator.remove();
  listIterator.set("a");

代码示例来源:origin: jenkinsci/jenkins

@Override
  public ConsoleAnnotator annotate(T context, MarkupText text) {
    ListIterator<ConsoleAnnotator<T>> itr = list.listIterator();
    while (itr.hasNext()) {
      ConsoleAnnotator a =  itr.next();
      ConsoleAnnotator b = a.annotate(context,text);
      if (a!=b) {
        if (b==null)    itr.remove();
        else            itr.set(b);
      }
    }
    switch (list.size()) {
      case 0:     return null;    // no more annotator left
      case 1:     return list.get(0); // no point in aggregating
      default:    return this;
    }
  }
}

代码示例来源:origin: commons-collections/commons-collections

public void testListIteratorSet() {
  // override to block
  resetFull();
  ListIterator it = getList().listIterator();
  it.next();
  try {
    it.set(null);
    fail();
  } catch (UnsupportedOperationException ex) {}
}

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

static List<Term> trimLeadingIndent(List<Term> code) {
 ArrayList<Term> result = new ArrayList<>(code);
 ListIterator<Term> it = result.listIterator();
 while (it.hasNext()) {
  Term t = it.next();
  if (t.isWhitespace()) {
   String whitespace = t.toString();
   int indexOf = whitespace.indexOf('\n');
   if (indexOf >= 0) {
    it.set(new Whitespace(whitespace.substring(0, indexOf + 1)));
   }
  }
 }
 return result;
}

相关文章