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:org.joda.collect.grid.AbstractGrid.java
@Override public List<V> row(int row) { Preconditions.checkElementIndex(row, rowCount(), "Row index"); return new Inner<V>(this, columnCount(), row, true); }
From source file:org.jboss.pressgang.ccms.util.WebElementUtil.java
public static List<String> getColumnContents(WebDriver driver, final By by, final int columnIndex) { return waitForTenSeconds(driver).until(new Function<WebDriver, List<String>>() { @Override//from ww w.j a v a 2 s .c om public List<String> apply(WebDriver input) { WebElement table = input.findElement(by); List<WebElement> rows = table.findElements(By.xpath(".//tbody[1]/tr")); List<TableRow> tableRows = Lists.transform(rows, WebElementTableRowFunction.FUNCTION); return ImmutableList.copyOf(Lists.transform(tableRows, new Function<TableRow, String>() { @Override public String apply(TableRow from) { List<String> cellContents = from.getCellContents(); Preconditions.checkElementIndex(columnIndex, cellContents.size(), "column index"); return cellContents.get(columnIndex); } })); } }); }
From source file:org.joda.collect.grid.AbstractGrid.java
@Override public List<V> column(int column) { Preconditions.checkElementIndex(column, columnCount(), "Column index"); return new Inner<V>(this, rowCount(), column, false); }
From source file:com.facebook.presto.block.uncompressed.UncompressedBooleanBlockCursor.java
@Override public boolean getBoolean(int index) { checkReadablePosition();/* w w w.j a v a 2 s . c om*/ Preconditions.checkElementIndex(0, 1, "field"); return slice.getByte(offset + SIZE_OF_BYTE) != 0; }
From source file:com.facebook.presto.block.uncompressed.UncompressedLongBlockCursor.java
@Override public long getLong(int field) { checkReadablePosition();/*w w w . j a v a 2s .co m*/ Preconditions.checkElementIndex(0, 1, "field"); return slice.getLong(offset + SIZE_OF_BYTE); }
From source file:com.facebook.presto.block.uncompressed.UncompressedDoubleBlockCursor.java
@Override public double getDouble(int field) { checkReadablePosition();/*from w w w . j a v a2s. c o m*/ Preconditions.checkElementIndex(0, 1, "field"); return slice.getDouble(offset + SIZE_OF_BYTE); }
From source file:io.pravega.common.util.ByteArraySegment.java
/** * Sets the value at the specified index. * * @param index The index to set the value at. * @param value The value to set.//from w ww . j av a 2 s . c o m * @throws IllegalStateException If the ByteArraySegment is readonly. * @throws ArrayIndexOutOfBoundsException If index is invalid. */ public void set(int index, byte value) { Preconditions.checkState(!this.readOnly, "Cannot modify a read-only ByteArraySegment."); Preconditions.checkElementIndex(index, this.length, "index"); this.array[index + this.startOffset] = value; }
From source file:org.objectweb.proactive.extensions.p2p.structured.deployment.gcmdeployment.GcmDeploymentNodeProvider.java
/** * {@inheritDoc}/*from ww w. j ava 2s . c om*/ */ @Override public Node getANode() { Preconditions.checkState(this.isStarted(), "Cannot get a node because the GCM deployment has not yet been started"); if (this.nodes == null) { this.nodes = this.gcma.getAllNodes(); } Preconditions.checkElementIndex(this.nodeIndex, this.nodes.size(), "No node available"); Node node = this.nodes.get(this.nodeIndex); this.nodeIndex++; return node; }
From source file:io.pravega.test.integration.selftest.Event.java
/** * Creates a new instance of the Event class. * * @param source A Source ArrayView to deserialize from. * @param sourceOffset A starting offset within the Source where to begin deserializing from. *//*from www. j ava 2 s .co m*/ @SneakyThrows(IOException.class) public Event(ArrayView source, int sourceOffset) { // Extract prefix and validate. int prefix = BitConverter.readInt(source, sourceOffset); sourceOffset += PREFIX_LENGTH; Preconditions.checkArgument(prefix == PREFIX, "Prefix mismatch."); // Extract ownerId. this.ownerId = BitConverter.readInt(source, sourceOffset); sourceOffset += OWNER_ID_LENGTH; this.routingKey = BitConverter.readInt(source, sourceOffset); sourceOffset += ROUTING_KEY_LENGTH; this.sequence = BitConverter.readInt(source, sourceOffset); sourceOffset += SEQUENCE_LENGTH; // Extract start time. this.startTime = BitConverter.readLong(source, sourceOffset); sourceOffset += START_TIME_LENGTH; // Extract length. this.contentLength = BitConverter.readInt(source, sourceOffset); sourceOffset += LENGTH_LENGTH; Preconditions.checkArgument(this.contentLength >= 0, "Payload length must be a positive integer."); Preconditions.checkElementIndex(sourceOffset + contentLength, source.getLength() + 1, "Insufficient data in given source."); // We make a copy of the necessary range in the input ArrayView since it may be unusable by the time we read from // it again. TODO: make TruncateableArray return a sub-TruncateableArray which does not require copying. if (source instanceof TruncateableArray || sourceOffset != HEADER_LENGTH) { this.serialization = new ByteArraySegment(StreamHelpers .readAll(source.getReader(sourceOffset - HEADER_LENGTH, getTotalLength()), getTotalLength())); } else { this.serialization = source; } }
From source file:com.facebook.presto.block.uncompressed.UncompressedSliceBlockCursor.java
@Override public Slice getSlice(int field) { checkReadablePosition();// w w w .j ava2s . com Preconditions.checkElementIndex(0, 1, "field"); return slice.slice(offset + SIZE_OF_INT + SIZE_OF_BYTE, size - SIZE_OF_INT - SIZE_OF_BYTE); }