List of usage examples for com.google.common.base Preconditions checkElementIndex
public static int checkElementIndex(int index, int size, @Nullable String desc)
From source file:ch.ge.ve.protopoc.service.protocol.DefaultBulletinBoard.java
@Override public void publishKeyPart(int j, EncryptionPublicKey publicKey) { Preconditions.checkState(publicParameters != null, "The public parameters need to have been defined first"); Preconditions.checkElementIndex(j, publicParameters.getS(), "The index j should be lower than the number of authorities"); publicKeyParts.put(j, publicKey);// w w w . j a v a 2s . c o m }
From source file:com.facebook.presto.block.uncompressed.UncompressedLongBlockCursor.java
@Override public boolean isNull(int field) { checkReadablePosition();//from ww w . j a va2 s .co m Preconditions.checkElementIndex(0, 1, "field"); return slice.getByte(offset) != 0; }
From source file:ch.ge.ve.protopoc.service.algorithm.DecryptionAuthorityAlgorithms.java
/** * Algorithms 7.47: checkShuffleProofs// w ww . ja v a 2s . c om * * @param bold_pi the shuffle proofs generated by the authorities * @param e_0 the original encryption * @param bold_E the vector of the re-encryption lists, per authority * @param publicKey the public key * @param j the index of this authority * @return true if all the proofs generated by the other authorities are valid, false otherwise */ public boolean checkShuffleProofs(List<ShuffleProof> bold_pi, List<Encryption> e_0, List<List<Encryption>> bold_E, EncryptionPublicKey publicKey, int j) { int s = publicParameters.getS(); int N = e_0.size(); Preconditions.checkArgument(bold_pi.size() == s, "there should be as many proofs as there are authorities"); Preconditions.checkArgument(bold_E.size() == s, "there should be as many lists of re-encryptions as there are authorities"); Preconditions.checkArgument(bold_E.stream().map(List::size).allMatch(l -> l == N), "every re-encryption list should have length N"); Preconditions.checkElementIndex(j, s, "The index of the authority should be valid with respect to the number of authorities"); // insert e_0 at index 0, thus offsetting all indices for bold_E by 1 List<List<Encryption>> tmp_bold_e = new ArrayList<>(); tmp_bold_e.add(0, e_0); tmp_bold_e.addAll(bold_E); for (int i = 0; i < s; i++) { if (i != j) { if (!checkShuffleProof(bold_pi.get(i), tmp_bold_e.get(i), tmp_bold_e.get(i + 1), publicKey)) { return false; } } } return true; }
From source file:org.zanata.util.WebElementUtil.java
public static List<String> getColumnContents(WebDriver driver, final By by, final int columnIndex) { return waitForAMoment(driver).until(webDriver -> { if (webDriver == null) { throw new RuntimeException("Driver is null"); }/*from ww w . j a va 2s. com*/ WebElement table; try { table = webDriver.findElement(by); } catch (NoSuchElementException noElement) { // Some pages don't show a table, if there's no // items to show return Collections.emptyList(); } List<WebElement> rows = table.findElements(By.xpath(".//tbody[1]/tr")); List<TableRow> tableRows = Lists.transform(rows, WebElementTableRowFunction.FUNCTION); return ImmutableList.copyOf(Lists.transform(tableRows, row -> { List<String> cellContents = row.getCellContents(); Preconditions.checkElementIndex(columnIndex, cellContents.size(), "column index"); return cellContents.get(columnIndex); })); }); }
From source file:io.pravega.common.util.ByteArraySegment.java
/** * Copies a specified number of bytes from the given ByteArraySegment into this ByteArraySegment. * * @param source The ByteArraySegment to copy bytes from. * @param targetOffset The offset within this ByteArraySegment to start copying at. * @param length The number of bytes to copy. * @throws IllegalStateException If the ByteArraySegment is readonly. * @throws ArrayIndexOutOfBoundsException If targetOffset or length are invalid. *//*from w ww. ja v a 2s .c om*/ public void copyFrom(ByteArraySegment source, int targetOffset, int length) { Preconditions.checkState(!this.readOnly, "Cannot modify a read-only ByteArraySegment."); Exceptions.checkArrayRange(targetOffset, length, this.length, "index", "values.length"); Preconditions.checkElementIndex(length, source.getLength() + 1, "length"); System.arraycopy(source.array, source.startOffset, this.array, targetOffset + this.startOffset, length); }
From source file:org.codice.ddf.libs.klv.data.Klv.java
/** * Creates a KLV set from the given byte array, the given offset in that array, * the total length of the KLV set in the byte array, the specified key length, * and the specified length field encoding. * <p>/*w w w .j av a2s. c om*/ * If there are not as many bytes in the array as the length field * suggests, as many bytes as possible will be stored as the value, and * the length field will reflect the actual length. * * @param theBytes The bytes that make up the entire KLV set * @param offset The offset from beginning of theBytes * @param keyLength The number of bytes in the key. * @param lengthEncoding The length field encoding type. * @throws IndexOutOfBoundsException If offset is out of range of the byte array. */ private Klv(final byte[] theBytes, final int offset, final KeyLength keyLength, final LengthEncoding lengthEncoding) { Preconditions.checkElementIndex(offset, theBytes.length, String.format("Offset %d is out of range (byte array length: %d).", offset, theBytes.length)); // These methods will interpret the byte array // and set the appropriate key length and length encoding flags. // setLength returns the offset of where the length field ends // and the value portion begins. It also initializes an array in // this.value of the appropriate length. setKey(theBytes, offset, keyLength); // Set length and verify enough bytes exist // setLength(..) also establishes a this.value array. final int valueOffset = setLength(theBytes, offset + keyLength.value(), lengthEncoding); final int remaining = theBytes.length - valueOffset; checkEnoughBytesRemaining(remaining, this.value.length, String.format( "Not enough bytes left in array (%d) for the declared length (%d).", remaining, this.value.length)); System.arraycopy(theBytes, valueOffset, this.value, 0, this.value.length); // Private field used when creating a list of KLVs from a long array. this.offsetAfterInstantiation = valueOffset + this.value.length; }
From source file:ch.ge.ve.protopoc.service.protocol.DefaultBulletinBoard.java
@Override public void publishPublicCredentials(int j, List<Point> publicCredentials) { Preconditions.checkState(publicParameters != null, "The public parameters need to have been defined first"); Preconditions.checkElementIndex(j, publicParameters.getS(), "The index j should be lower than the number of authorities"); publicCredentialsParts.put(j, publicCredentials); }
From source file:io.pravega.common.util.ByteArraySegment.java
/** * Copies a specified number of bytes from this ByteArraySegment into the given target array. * * @param target The target array. * @param targetOffset The offset within the target array to start copying data at. * @param length The number of bytes to copy. * @throws ArrayIndexOutOfBoundsException If targetOffset or length are invalid. *//*from w ww . j av a 2 s . c o m*/ public void copyTo(byte[] target, int targetOffset, int length) { Preconditions.checkElementIndex(length, this.length + 1, "length"); Exceptions.checkArrayRange(targetOffset, length, target.length, "index", "values.length"); System.arraycopy(this.array, this.startOffset, target, targetOffset, length); }
From source file:de.kussm.chain.Chain.java
/** * Returns the chain link at the given index. * * @param index of the element to return * @return the chain link at the given index * @throws IndexOutOfBoundsException if {@code index} is out of bounds. *///from w ww . ja va2 s . co m public ChainLinkType get(int index) { Preconditions.checkElementIndex(index, chainLinks.length, "chain link index"); return chainLinks[index]; }
From source file:ch.ge.ve.protopoc.service.protocol.DefaultBulletinBoard.java
@Override public void publishShuffleAndProof(int j, List<Encryption> shuffle, ShuffleProof proof) { Preconditions.checkElementIndex(j, publicParameters.getS(), "j needs to be within bounds"); Preconditions.checkArgument(shuffles.size() == j, "Shuffle j can only be inserted after the previous shuffles"); Preconditions.checkArgument(shuffleProofs.size() == j, "Shuffle proof j can only be inserted after the previous shuffle proof"); shuffles.put(j, shuffle);/*from w ww . ja va2 s .c o m*/ shuffleProofs.put(j, proof); }