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; } }
/** * 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); }
/** * 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; }
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); }
@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)); }
/** * <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; } /**
/** * <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; } /**
/** * 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(""); } }
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); } } }
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)); }
/** * <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; } /**
/** * <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; } /**