List of usage examples for com.google.common.base Preconditions checkElementIndex
public static int checkElementIndex(int index, int size)
From source file:org.eclipse.incquery.runtime.localsearch.MatchingFrame.java
/** * Sets the value of the variable at the given position * // w w w . j a v a 2s .c om * @param position the position of the variable within the frame * @param value the value to be set for the variable */ public void setValue(Integer position, Object value) { Preconditions.checkElementIndex(position, frame.length); frame[position] = value; }
From source file:org.lenskit.data.ratings.PackedRatingCollection.java
@Override public RatingMatrixEntry get(int index) { Preconditions.checkElementIndex(index, indices.size()); return data.getEntry(index); }
From source file:org.ambraproject.rhino.util.NodeListAdapter.java
/** * {@inheritDoc}//from w w w . j a va2 s . c om */ @Override public Node get(int index) { // To match the List contract (nodes.item returns null on invalid index) Preconditions.checkElementIndex(index, size()); Node node = getImpl(index); if (node == null) { throw new NullPointerException("Delegate object returned null for a valid index"); } return node; }
From source file:com.facebook.presto.testing.MaterializedRow.java
public Object getField(int field) { Preconditions.checkElementIndex(field, values.size()); return processField(values.get(field)); }
From source file:com.cloudera.impala.catalog.HdfsPartitionLocationCompressor.java
private String indexToPrefix(int i) { // Uncompressed location are represented by -1: if (i == -1)/* w w w . j a va2 s. c o m*/ return ""; Preconditions.checkElementIndex(i, prefixMap_.size()); return prefixMap_.getEntry(i); }
From source file:org.grouplens.lenskit.vectors.MutableVec.java
/** * Add a value to an entry in this vector. * * @param i The index./*ww w .ja va2 s . co m*/ * @param v The value to set. * @return The old value at {@code i}. * @throws IllegalArgumentException if {@code i} is not a valid index in this vector. */ public double add(int i, double v) { Preconditions.checkElementIndex(i, size()); final double old = data[i]; data[i] = v + old; return old; }
From source file:com.mycelium.net.ServerEndpoints.java
public ServerEndpoints(HttpEndpoint endpoints[], int initialEndpoint) { this.endpoints = Lists.newArrayList(endpoints); Preconditions.checkElementIndex(initialEndpoint, endpoints.length); currentEndpoint = initialEndpoint;/*from w ww. java 2s . co m*/ }
From source file:com.palantir.atlasdb.schema.RowTransformers.java
/** * Returns a function that changes the type and ordering of the components in each row. *//*www. ja v a 2 s.c o m*/ public static Function<byte[], byte[]> rowNamePermuformation(final List<EncodingType> initialTypes, List<RowComponent> permutation) { Preconditions.checkArgument(initialTypes.size() == permutation.size()); Set<Integer> outputIndices = ImmutableSet.copyOf(Iterables.transform(permutation, RowComponent.TO_INDEX)); Preconditions.checkArgument(outputIndices.size() == permutation.size(), "Permutation maps multiple components to the same index."); for (int index : outputIndices) { Preconditions.checkElementIndex(index, permutation.size()); } final List<Integer> indexPermutation = ImmutableList .copyOf(Lists.transform(permutation, RowComponent.TO_INDEX)); final List<EncodingType> finalTypes = ImmutableList .copyOf(Lists.transform(permutation, RowComponent.TO_TYPE)); return new Function<byte[], byte[]>() { @Override public byte[] apply(byte[] input) { List<Object> initialValues = EncodingUtils.fromBytes(input, initialTypes); List<Object> finalValues = Lists.newArrayListWithCapacity(indexPermutation.size()); for (int i = 0; i < indexPermutation.size(); i++) { finalValues.add(initialValues.get(indexPermutation.get(i))); } return EncodingUtils.toBytes(finalTypes, finalValues); } }; }
From source file:de.javauni.jarcade.utils.IdList.java
@Override public E get(int index) { Preconditions.checkElementIndex(index, elems.length); return elems[index]; }
From source file:com.bazaarvoice.jless.ast.node.InternalNode.java
@Override public void addChild(int index, Node child) { Preconditions.checkElementIndex(index, _children.size() + 1); // ignore empty nodes if (child == null || !child.hasData()) { return;// w w w .j a va 2 s . c o m } // check addition visitor if (!child.add(_additionVisitor)) { return; } // detach new child from old parent InternalNode parent = child.getParent(); if (parent == this) { return; } if (parent != null) { TreeUtils.removeChild(parent, child); } // attach new child _children.add(index, child); child.setParent(this); // notify iterators for (MutableChildIterator it : _childIteratorStack) { it.addEvent(index, child); } }