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

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

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

List.set介绍

[英]Replaces the element at the specified location in this List with the specified object. This operation does not change the size of the List.
[中]用指定的对象替换此列表中指定位置的元素。此操作不会更改列表的大小。

代码示例

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

public class Collections { 
 public static <T> void copy(List<? super T> dest, List<? extends T> src) 
 {
   for (int i=0; i<src.size(); i++) 
    dest.set(i,src.get(i)); 
 } 
}

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

/**
 * push.
 *
 * @param ele
 */
public void push(E ele) {
  if (mElements.size() > mSize) {
    mElements.set(mSize, ele);
  } else {
    mElements.add(ele);
  }
  mSize++;
}

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

public void setPenalty(int i, int j, double penalty)
{
  if (penalty_.isEmpty())
  {
    for (int s = 0; s < node_.size(); s++)
    {
      List<Double> penaltys = Arrays.asList(new Double[ysize_]);
      penalty_.add(penaltys);
    }
  }
  penalty_.get(i).set(j, penalty);
}

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

private void cleanUp() {
  // invalidate row
  final Row deleteRow = materializedTable.get(validRowPosition);
  if (rowPositionCache.get(deleteRow) == validRowPosition) {
    // this row has no duplicates in the materialized table,
    // it can be removed from the cache
    rowPositionCache.remove(deleteRow);
  }
  materializedTable.set(validRowPosition, null);
  validRowPosition++;
  // perform clean up in batches
  if (validRowPosition >= overcommitThreshold) {
    materializedTable.subList(0, validRowPosition).clear();
    // adjust all cached indexes
    rowPositionCache.replaceAll((k, v) -> v - validRowPosition);
    validRowPosition = 0;
  }
}

代码示例来源:origin: skylot/jadx

/**
 * Replace insn by index i in block,
 * for proper copy attributes, assume attributes are not overlap
 */
private static void replaceInsn(BlockNode block, int i, InsnNode insn) {
  InsnNode prevInsn = block.getInstructions().get(i);
  insn.copyAttributesFrom(prevInsn);
  insn.setSourceLine(prevInsn.getSourceLine());
  block.getInstructions().set(i, insn);
}

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

/**
 * Shuffle the assignment plan by switching two favored node positions.
 * @param plan The assignment plan
 * @param p1 The first switch position
 * @param p2 The second switch position
 * @return
 */
private FavoredNodesPlan shuffleAssignmentPlan(FavoredNodesPlan plan,
  FavoredNodesPlan.Position p1, FavoredNodesPlan.Position p2) throws IOException {
 FavoredNodesPlan shuffledPlan = new FavoredNodesPlan();
 Map<String, RegionInfo> regionToHRegion =
   rp.getRegionAssignmentSnapshot().getRegionNameToRegionInfoMap();
 for (Map.Entry<String, List<ServerName>> entry :
  plan.getAssignmentMap().entrySet()) {
  // copy the server list from the original plan
  List<ServerName> shuffledServerList = new ArrayList<>();
  shuffledServerList.addAll(entry.getValue());
  // start to shuffle
  shuffledServerList.set(p1.ordinal(), entry.getValue().get(p2.ordinal()));
  shuffledServerList.set(p2.ordinal(), entry.getValue().get(p1.ordinal()));
  // update the plan
  shuffledPlan.updateFavoredNodesMap(regionToHRegion.get(entry.getKey()), shuffledServerList);
 }
 return shuffledPlan;
}

代码示例来源:origin: fesh0r/fernflower

@Override
public void initExprents() {
 SwitchExprent swexpr = (SwitchExprent)first.getExprents().remove(first.getExprents().size() - 1);
 swexpr.setCaseValues(caseValues);
 headexprent.set(0, swexpr);
}

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

private static void assertTransformModifiable(List<String> list) {
 try {
  list.add("5");
  fail("transformed list is addable");
 } catch (UnsupportedOperationException expected) {
 }
 list.remove(0);
 assertEquals(asList("2", "3", "4"), list);
 list.remove("3");
 assertEquals(asList("2", "4"), list);
 try {
  list.set(0, "5");
  fail("transformed list is setable");
 } catch (UnsupportedOperationException expected) {
 }
 list.clear();
 assertEquals(Collections.emptyList(), list);
}

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

@CollectionSize.Require(absent = CollectionSize.ZERO)
public void testEquals_otherListContainingNull() {
 List<E> other = new ArrayList<>(getSampleElements());
 other.set(other.size() / 2, null);
 assertFalse(
   "Two Lists should not be equal if exactly one of them has null at a given index.",
   getList().equals(other));
}

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

/**
 * <code>repeated .edu.stanford.nlp.loglinear.model.proto.ConcatVector factorTable = 2;</code>
 */
public Builder setFactorTable(
  int index, edu.stanford.nlp.loglinear.model.proto.ConcatVectorProto.ConcatVector value) {
 if (factorTableBuilder_ == null) {
  if (value == null) {
   throw new NullPointerException();
  }
  ensureFactorTableIsMutable();
  factorTable_.set(index, value);
  onChanged();
 } else {
  factorTableBuilder_.setMessage(index, value);
 }
 return this;
}
/**

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

/**
 * <code>repeated .authpb.Permission keyPermission = 2;</code>
 */
public Builder setKeyPermission(
  int index, authpb.Auth.Permission value) {
 if (keyPermissionBuilder_ == null) {
  if (value == null) {
   throw new NullPointerException();
  }
  ensureKeyPermissionIsMutable();
  keyPermission_.set(index, value);
  onChanged();
 } else {
  keyPermissionBuilder_.setMessage(index, value);
 }
 return this;
}
/**

代码示例来源:origin: square/okhttp

/**
 * Removes a path segment. When this method returns the last segment is always "", which means
 * the encoded path will have a trailing '/'.
 *
 * <p>Popping "/a/b/c/" yields "/a/b/". In this case the list of path segments goes from ["a",
 * "b", "c", ""] to ["a", "b", ""].
 *
 * <p>Popping "/a/b/c" also yields "/a/b/". The list of path segments goes from ["a", "b", "c"]
 * to ["a", "b", ""].
 */
private void pop() {
 String removed = encodedPathSegments.remove(encodedPathSegments.size() - 1);
 // Make sure the path ends with a '/' by either adding an empty string or clearing a segment.
 if (removed.isEmpty() && !encodedPathSegments.isEmpty()) {
  encodedPathSegments.set(encodedPathSegments.size() - 1, "");
 } else {
  encodedPathSegments.add("");
 }
}

代码示例来源:origin: spring-projects/spring-framework

@SuppressWarnings({"unchecked", "rawtypes"})
protected void visitList(List listVal) {
  for (int i = 0; i < listVal.size(); i++) {
    Object elem = listVal.get(i);
    Object newVal = resolveValue(elem);
    if (!ObjectUtils.nullSafeEquals(newVal, elem)) {
      listVal.set(i, newVal);
    }
  }
}

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

/**
 * push.
 *
 * @param ele
 */
public void push(E ele) {
  if (mElements.size() > mSize) {
    mElements.set(mSize, ele);
  } else {
    mElements.add(ele);
  }
  mSize++;
}

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

private void lazyNext(PriorityQueue<Derivation> candV, Derivation derivation, int kPrime) {
 List<Vertex> tails = derivation.arc.tails;
 for  (int i = 0, sz = derivation.arc.size(); i < sz; i++) {
  List<Integer> j = new ArrayList<>(derivation.j);
  j.set(i, j.get(i)+1);
  Vertex Ti = tails.get(i);
  lazyKthBest(Ti, j.get(i), kPrime);
  LinkedList<Derivation> dHatTi = dHat.get(Ti);
  // compute score for this derivation
  if (j.get(i)-1 >= dHatTi.size()) { continue; }
  Derivation d = dHatTi.get(j.get(i)-1);
  double newScore = derivation.score - derivation.childrenScores.get(i) + d.score;
  List<Double> childrenScores = new ArrayList<>(derivation.childrenScores);
  childrenScores.set(i, d.score);
  Derivation newDerivation = new Derivation(derivation.arc, j, newScore, childrenScores);
  if (!candV.contains(newDerivation) && newScore > Double.NEGATIVE_INFINITY) {
   candV.add(newDerivation, newScore);
  }
 }
}

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

public void testAsList_toArray_roundTrip() {
 short[] array = {(short) 0, (short) 1, (short) 2};
 List<Short> list = Shorts.asList(array);
 short[] newArray = Shorts.toArray(list);
 // Make sure it returned a copy
 list.set(0, (short) 4);
 assertTrue(Arrays.equals(new short[] {(short) 0, (short) 1, (short) 2}, newArray));
 newArray[1] = (short) 5;
 assertEquals((short) 1, (short) list.get(1));
}

代码示例来源:origin: fesh0r/fernflower

@Override
public void initExprents() {
 IfExprent ifexpr = (IfExprent)first.getExprents().remove(first.getExprents().size() - 1);
 if (negated) {
  ifexpr = (IfExprent)ifexpr.copy();
  ifexpr.negateIf();
 }
 headexprent.set(0, ifexpr);
}

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

/**
 * <code>repeated .edu.stanford.nlp.loglinear.model.proto.ConcatVector.Component component = 1;</code>
 */
public Builder setComponent(
  int index, edu.stanford.nlp.loglinear.model.proto.ConcatVectorProto.ConcatVector.Component.Builder builderForValue) {
 if (componentBuilder_ == null) {
  ensureComponentIsMutable();
  component_.set(index, builderForValue.build());
  onChanged();
 } else {
  componentBuilder_.setMessage(index, builderForValue.build());
 }
 return this;
}
/**

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

/**
 * <code>repeated .authpb.Permission keyPermission = 2;</code>
 */
public Builder setKeyPermission(
  int index, authpb.Auth.Permission.Builder builderForValue) {
 if (keyPermissionBuilder_ == null) {
  ensureKeyPermissionIsMutable();
  keyPermission_.set(index, builderForValue.build());
  onChanged();
 } else {
  keyPermissionBuilder_.setMessage(index, builderForValue.build());
 }
 return this;
}
/**

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

@Override
public synchronized void onSlotResult(List<Boolean> result) {
  for (int i = 0; i < result.size(); i++) {
    if (this.result.size() == i) {
      this.result.add(false);
    }
    this.result.set(i, this.result.get(i) | result.get(i));
  }
}

相关文章