List of usage examples for com.google.common.base Preconditions checkElementIndex
public static int checkElementIndex(int index, int size)
From source file:com.google.devtools.build.lib.util.LongArrayList.java
/** * Overwrites the element at a certain index with the given value and returns the previous * element./*from www. j av a 2 s .co m*/ * @throws IndexOutOfBoundsException if the index is outside the interval [0, {@link #size()}) */ public long set(int index, long value) { Preconditions.checkElementIndex(index, size); long previous = array[index]; array[index] = value; return previous; }
From source file:ch.ge.ve.protopoc.service.algorithm.VoteConfirmationAuthorityAlgorithms.java
/** * Algorithm 7.37: GetFinalization/* w w w . jav a 2s .co m*/ * * @param i the voter index * @param upper_bold_p the point matrix, one point per voter per candidate * @param upper_b the current ballot list * @return this authority's part of the finalization code */ public FinalizationCodePart getFinalization(Integer i, List<List<Point>> upper_bold_p, Collection<BallotEntry> upper_b) { BigInteger p_prime = publicParameters.getPrimeField().getP_prime(); Preconditions.checkArgument( upper_bold_p.stream().flatMap(Collection::stream) .allMatch(point -> BigInteger.ZERO.compareTo(point.x) <= 0 && point.x.compareTo(p_prime) < 0 && BigInteger.ZERO.compareTo(point.y) <= 0 && point.y.compareTo(p_prime) < 0), "All points' coordinates must be in Z_p_prime"); Preconditions.checkElementIndex(i, upper_bold_p.size()); Object[] bold_p_i = upper_bold_p.get(i).toArray(); byte[] upper_f_i = ByteArrayUtils.truncate(hash.recHash_L(bold_p_i), publicParameters.getUpper_l_f()); BallotEntry ballotEntry = upper_b.stream().filter(b -> Objects.equals(b.getI(), i)).findFirst() .orElseThrow(() -> new BallotNotFoundRuntimeException( String.format("Couldn't find any ballot for voter %d", i))); return new FinalizationCodePart(upper_f_i, ballotEntry.getBold_r()); }
From source file:de.iteratec.iteraplan.presentation.memory.EntityTreeNode.java
EntityTreeNode getChildBySiblingIndex(int lkpSiblingIndex) { Preconditions.checkElementIndex(lkpSiblingIndex, children.size()); return children.get(lkpSiblingIndex); }
From source file:org.sosy_lab.cpachecker.util.VariableClassification.java
/** * This method returns a partition containing all vars, * that are dependent from a specific function parameter at a given edge. *//*w w w . j av a 2 s .com*/ public Partition getPartitionForParameterOfEdge(FunctionCallEdge edge, int param) { Preconditions.checkElementIndex(param, edge.getArguments().size()); return getPartitionForEdge(edge, param); }
From source file:com.opengamma.strata.market.param.ParameterizedDataCombiner.java
private int findUnderlyingIndex(int parameterIndex) { Preconditions.checkElementIndex(parameterIndex, paramCount); for (int i = 1; i < lookup.length; i++) { if (parameterIndex < lookup[i]) { return i - 1; }/*w ww . j a va 2s. co m*/ } return lookup.length - 1; }
From source file:edu.byu.nlp.util.DoubleArrays.java
public static void pointwiseDivideToSelf(final double[] a, int offsetA, double[] b, int offsetB, int length) { Preconditions.checkNotNull(a);/*from w w w . j ava 2s.c om*/ Preconditions.checkNotNull(b); Preconditions.checkElementIndex(offsetA, a.length); Preconditions.checkElementIndex(offsetB, b.length); for (int i = 0; i < length; i++) { a[offsetA + i] /= b[offsetB + i]; } }
From source file:edu.byu.nlp.util.DoubleArrays.java
public static void addToSelf(final double[] a, final int offsetA, final double[] b, final int offsetB, final int length) { Preconditions.checkNotNull(a);//from w ww . ja va 2 s . c om Preconditions.checkNotNull(b); Preconditions.checkElementIndex(offsetA, a.length); Preconditions.checkElementIndex(offsetB, b.length); for (int i = 0; i < length; i++) { a[offsetA + i] += b[offsetB + i]; } }
From source file:net.automatalib.commons.util.array.RichArray.java
@Override public T get(int index) { Preconditions.checkElementIndex(index, length); return contents[start + index]; }
From source file:net.automatalib.commons.util.array.RichArray.java
@Override public T set(int index, T element) { Preconditions.checkElementIndex(index, length); int effIndex = start + index; T old = contents[effIndex];/*from w ww. java2 s . com*/ contents[effIndex] = element; return old; }
From source file:net.automatalib.commons.util.array.RichArray.java
public void update(int index, T element) { Preconditions.checkElementIndex(index, length); contents[start + index] = element; }