@Override Integer offset(Integer origin, long distance) { checkNonnegative(distance, "distance"); return Ints.checkedCast(origin.longValue() + distance); }
LockFreeBitArray(long bits) { this(new long[Ints.checkedCast(LongMath.divide(bits, 64, RoundingMode.CEILING))]); }
int maxEventLimit() throws Exception { if (eventTo < eventFrom) { throw new Exception("Invalid event ID input received in TO clause"); } Integer maxRange = Ints.checkedCast(this.eventTo - eventFrom + 1); if ((maxEventLimit == null) || (maxEventLimit > maxRange)) { maxEventLimit = maxRange; } return maxEventLimit; }
@Override protected final long evalLong(long left, long right) { return LongMath.pow(left, Ints.checkedCast(right)); }
@Override Integer offset(Integer origin, long distance) { checkNonnegative(distance, "distance"); return Ints.checkedCast(origin.longValue() + distance); }
LockFreeBitArray(long bits) { this(new long[Ints.checkedCast(LongMath.divide(bits, 64, RoundingMode.CEILING))]); }
@Override Integer offset(Integer origin, long distance) { checkNonnegative(distance, "distance"); return Ints.checkedCast(origin.longValue() + distance); }
assertEquals(Ints.checkedCast(estimatedSize), resultsForStrategy.size());
private static void assertCastFails(long value) { try { Ints.checkedCast(value); fail("Cast to int should have failed: " + value); } catch (IllegalArgumentException ex) { assertTrue( value + " not found in exception text: " + ex.getMessage(), ex.getMessage().contains(String.valueOf(value))); } }
@Nullable public T get(int index) throws IOException { long startOffset; if (index == 0) { startOffset = Integer.BYTES; } else { startOffset = getOffset(index - 1) + Integer.BYTES; } long endOffset = getOffset(index); int valueSize = Ints.checkedCast(endOffset - startOffset); if (valueSize == 0) { return null; } ByteBuffer bb = ByteBuffer.allocate(valueSize); valuesOut.readFully(startOffset, bb); bb.clear(); return strategy.fromByteBuffer(bb, valueSize); }
private int verifySize(long bytesWrittenInChunk) { bytesWritten += bytesWrittenInChunk; if (bytesWritten != currOut.getCurrOffset() - startOffset) { throw new ISE("WTF? Perhaps there is some concurrent modification going on?"); } if (bytesWritten > size) { throw new ISE("Wrote[%,d] bytes for something of size[%,d]. Liar!!!", bytesWritten, size); } return Ints.checkedCast(bytesWrittenInChunk); }
public int addToOffset(long numBytesWritten) { if (numBytesWritten > bytesLeft()) { throw new ISE("Wrote more bytes[%,d] than available[%,d]. Don't do that.", numBytesWritten, bytesLeft()); } currOffset += numBytesWritten; return Ints.checkedCast(numBytesWritten); }
public int addToOffset(long numBytesWritten) { if (numBytesWritten > bytesLeft()) { throw new ISE("Wrote more bytes[%,d] than available[%,d]. Don't do that.", numBytesWritten, bytesLeft()); } currOffset += numBytesWritten; return Ints.checkedCast(numBytesWritten); }
@Override public void addValues(IndexedInts ints) throws IOException { if (numBytesForMaxWritten) { throw new IllegalStateException("written out already"); } for (int i = 0, size = ints.size(); i < size; i++) { int value = ints.get(i); Preconditions.checkState(value >= 0 && value <= maxId); writeInt.write(valuesOut, value); } headerOut.writeInt(Ints.checkedCast(valuesOut.size())); ++numWritten; }
public void write(T objectToWrite) throws IOException { long sizeBefore = valueOut.size(); strategy.writeTo(objectToWrite, valueOut); headerOut.writeInt(Ints.checkedCast(valueOut.size() - sizeBefore)); }
@Override public void writeTo(WritableByteChannel channel, FileSmoosher smoosher) throws IOException { SerializerUtils.writeInt(channel, Ints.checkedCast(writer.getSerializedSize())); writer.writeTo(channel, smoosher); if (!nullRowsBitmap.isEmpty()) { nullValueBitmapWriter.writeTo(channel, smoosher); } } }
@Override public void writeTo(WritableByteChannel channel, FileSmoosher smoosher) throws IOException { SerializerUtils.writeInt(channel, Ints.checkedCast(writer.getSerializedSize())); writer.writeTo(channel, smoosher); if (!nullRowsBitmap.isEmpty()) { nullValueBitmapWriter.writeTo(channel, smoosher); } }
@Override public void writeTo(WritableByteChannel channel, FileSmoosher smoosher) throws IOException { SerializerUtils.writeInt(channel, Ints.checkedCast(writer.getSerializedSize())); writer.writeTo(channel, smoosher); if (!nullRowsBitmap.isEmpty()) { nullValueBitmapWriter.writeTo(channel, smoosher); } } }
public void testCheckedCast() { for (int value : VALUES) { assertEquals(value, Ints.checkedCast((long) value)); } assertCastFails(GREATEST + 1L); assertCastFails(LEAST - 1L); assertCastFails(Long.MAX_VALUE); assertCastFails(Long.MIN_VALUE); }
@AndroidIncompatible // slow public void testBitSize() { double fpp = 0.03; for (int i = 1; i < 10000; i++) { long numBits = BloomFilter.optimalNumOfBits(i, fpp); int arraySize = Ints.checkedCast(LongMath.divide(numBits, 64, RoundingMode.CEILING)); assertEquals( arraySize * Long.SIZE, BloomFilter.create(Funnels.unencodedCharsFunnel(), i, fpp).bitSize()); } }