java.util.List.indexOf()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(124)

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

List.indexOf介绍

[英]Searches this List for the specified object and returns the index of the first occurrence.
[中]

代码示例

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

private int removeParent(Node parentNode) {
  int index = parents.indexOf(parentNode);
  parents.remove(parentNode);
  return index;
}

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

@Override
public Object getValueByField(String field) {
  return values.get(keys.indexOf(field));
}

代码示例来源:origin: alibaba/druid

@Override
public void rollback(Savepoint savepoint) throws SQLException {
  checkState();
  int index = this.savepoints.indexOf(savepoint);
  if (index == -1) {
    throw new SQLException("savepoint not contained");
  }
  for (int i = savepoints.size() - 1; i >= index; --i) {
    savepoints.remove(i);
  }
}

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

private void pickAnycastTargets(List<Address> anycast_targets) {
    int index=dests.indexOf(local_addr);
    for(int i=index + 1; i < index + 1 + anycast_count; i++) {
      int new_index=i % dests.size();
      Address tmp=dests.get(new_index);
      if(!anycast_targets.contains(tmp))
        anycast_targets.add(tmp);
    }
  }
}

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

public PartitioningScheme translateOutputLayout(List<Symbol> newOutputLayout)
{
  requireNonNull(newOutputLayout, "newOutputLayout is null");
  checkArgument(newOutputLayout.size() == outputLayout.size());
  Partitioning newPartitioning = partitioning.translate(symbol -> newOutputLayout.get(outputLayout.indexOf(symbol)));
  Optional<Symbol> newHashSymbol = hashColumn
      .map(outputLayout::indexOf)
      .map(newOutputLayout::get);
  return new PartitioningScheme(newPartitioning, newOutputLayout, newHashSymbol, replicateNullsAndAny, bucketToPartition);
}

代码示例来源:origin: ReactiveX/RxJava

assertEquals(0, list.size());
assertFalse(list.contains(1));
assertFalse(list.remove((Integer)1));
assertTrue(list.contains(2));
assertFalse(list.remove((Integer)10));
assertEquals(7, list.size());
assertEquals(7, list.size());
  assertEquals(i, list.get(i - 1).intValue());
assertEquals(2, list.indexOf(3));
assertFalse(list.equals(list3));
list3.add(7);
assertTrue(list3.equals(list));
assertTrue(list.equals(list3));
assertEquals(list.toString(), list3.toString());
list.remove(0);
assertEquals(6, list.size());

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

private static int registerExpression(List<RexNode> exprList, RexNode node) {
 int i = exprList.indexOf(node);
 if (i < 0) {
  i = exprList.size();
  exprList.add(node);
 }
 return i;
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
public void testReplaceAllRotate() {
 getMap()
   .replaceAll(
     (K k, V v) -> {
      int index = keys().asList().indexOf(k);
      return values().asList().get(index + 1);
     });
 List<Entry<K, V>> expectedEntries = new ArrayList<>();
 for (Entry<K, V> entry : getSampleEntries()) {
  int index = keys().asList().indexOf(entry.getKey());
  expectedEntries.add(Helpers.mapEntry(entry.getKey(), values().asList().get(index + 1)));
 }
 expectContents(expectedEntries);
}

代码示例来源:origin: stanfordnlp/CoreNLP

private void changeStartTimes(List<LatticeWord> words, int newStartTime) {
 ArrayList<LatticeWord> toRemove = new ArrayList<>();
 for (LatticeWord lw : words) {
  latticeWords.remove(lw);
  int oldStartTime = lw.startNode;
  lw.startNode = newStartTime;
  if (latticeWords.contains(lw)) {
   if (DEBUG) {
    log.info("duplicate found");
   LatticeWord twin = latticeWords.get(latticeWords.indexOf(lw));
   latticeWords.add(lw);
   if (oldStartTime != newStartTime) {

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

private void mappingKeys(int key, Pair<RexNode, String> project, List<Pair<RexNode, String>> projects, Map<Integer, Integer> mapping) {
  if (!projects.contains(project)) {
    projects.add(project);
  }
  mapping.put(key, projects.indexOf(project));
}

代码示例来源:origin: airbnb/epoxy

void addAttributes(Collection<AttributeInfo> attributesToAdd) {
 removeMethodIfDuplicatedBySetter(attributesToAdd);
 for (AttributeInfo info : attributesToAdd) {
  int existingIndex = attributeInfo.indexOf(info);
  if (existingIndex > -1) {
   // Don't allow duplicates.
   attributeInfo.set(existingIndex, info);
  } else {
   attributeInfo.add(info);
  }
 }
}

代码示例来源:origin: apache/incubator-shardingsphere

private static void changeColumnDefinitionPosition(final ColumnAfterPositionSegment columnAfterPositionSegment, final List<ColumnMetaData> columnMetaDataList) {
  Optional<ColumnMetaData> columnMetaData = find(columnAfterPositionSegment.getColumnName(), columnMetaDataList);
  Optional<ColumnMetaData> afterColumnMetaData = find(columnAfterPositionSegment.getAfterColumnName(), columnMetaDataList);
  if (columnMetaData.isPresent() && afterColumnMetaData.isPresent()) {
    columnMetaDataList.remove(columnMetaData.get());
    columnMetaDataList.add(columnMetaDataList.indexOf(afterColumnMetaData.get()) + 1, columnMetaData.get());
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private boolean assertValidVertex(Vertex v) {
  // Allows to find bugs in collapsing.
  //       System.out.println("Asserting " + v.index);
  for (Triangle t : v.triangles) {
    for (int i = 0; i < 3; i++) {
      //             System.out.println("check " + t.vertex[i].index);
      //assert (collapseCostSet.contains(t.vertex[i]));
      assert (find(collapseCostSet, t.vertex[i]));
      
      assert (t.vertex[i].edges.contains(new Edge(t.vertex[i].collapseTo)));
      for (int n = 0; n < 3; n++) {
        if (i != n) {
          
          int id = t.vertex[i].edges.indexOf(new Edge(t.vertex[n]));
          Edge ed = t.vertex[i].edges.get(id);
          //assert (ed.collapseCost != UNINITIALIZED_COLLAPSE_COST);
        } else {
          assert (!t.vertex[i].edges.contains(new Edge(t.vertex[n])));
        }
      }
    }
  }
  return true;
}

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

public void setAlternateRecipientInfo(List<Recipient> recipients) {
  this.recipients = recipients;
  int indexOfCurrentRecipient = recipients.indexOf(currentRecipient);
  if (indexOfCurrentRecipient >= 0) {
    currentRecipient = recipients.get(indexOfCurrentRecipient);
  }
  recipients.remove(currentRecipient);
  notifyDataSetChanged();
}

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

private void checkValueProviders(ResourceMethod method) {
  List<? extends Function<ContainerRequest, ?>> valueProviders =
      ParameterValueHelper.createValueProviders(valueParamProviders, method.getInvocable());
  if (valueProviders.contains(null)) {
    int index = valueProviders.indexOf(null);
    Errors.fatal(method, LocalizationMessages.ERROR_PARAMETER_MISSING_VALUE_PROVIDER(index, method.getInvocable()
        .getHandlingMethod()));
  }
}

代码示例来源:origin: aragozin/jvm-tools

public void append(String[] hdr, String[] values) {
  for(String h: hdr) {
    if (!header.contains(h)) {
      header.add(h);
    }
  }
  String[] row = new String[header.size()];
  for(int i = 0; i != hdr.length; ++i) {
    int n = header.indexOf(hdr[i]);
    row[n] = values[i];
  }
  rows.add(row);
}

代码示例来源:origin: JetBrains/ideavim

private void selectWindow(@NotNull EditorWindow currentWindow, @NotNull List<EditorWindow> windows,
             int relativePosition) {
 final int pos = windows.indexOf(currentWindow);
 final int selected = pos + relativePosition;
 final int normalized = Math.max(0, Math.min(selected, windows.size() - 1));
 windows.get(normalized).setAsCurrentWindow(true);
}

代码示例来源:origin: aragozin/jvm-tools

private void ensureCounter(String key) throws IOException {
  int n = counterKeys.indexOf(key);
  if (n < 0) {
    n = counterKeys.size();
    counterKeys.add(key);
    dos.write(StackTraceCodec.TAG_COUNTER);
    dos.writeUTF(key);
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Inserts the given specific portion of an uncollapsed relation back into the
 * targetList
 *
 * @param specific Specific relation to put in.
 * @param relnTgtNode Node governed by the uncollapsed relation
 * @param tgtList Target List of words
 */
private void insertSpecificIntoList(String specific, IndexedWord relnTgtNode, List<IndexedWord> tgtList) {
 int currIndex = tgtList.indexOf(relnTgtNode);
 Set<IndexedWord> descendants = descendants(relnTgtNode);
 IndexedWord specificNode = new IndexedWord();
 specificNode.set(CoreAnnotations.LemmaAnnotation.class, specific);
 specificNode.set(CoreAnnotations.TextAnnotation.class, specific);
 specificNode.set(CoreAnnotations.OriginalTextAnnotation.class, specific);
 while ((currIndex >= 1) && descendants.contains(tgtList.get(currIndex - 1))) {
  currIndex--;
 }
 tgtList.add(currIndex, specificNode);
}

相关文章