Java Code Examples for com.google.common.primitives.Ints#checkedCast()
The following examples show how to use
com.google.common.primitives.Ints#checkedCast() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraAccessTokenDAO.java From james-project with Apache License 2.0 | 6 votes |
@Inject public CassandraAccessTokenDAO(Session session, @Named(TOKEN_EXPIRATION_IN_MS) long durationInMilliseconds) { this.cassandraAsyncExecutor = new CassandraAsyncExecutor(session); this.durationInSeconds = Ints.checkedCast(TimeUnit.MILLISECONDS.toSeconds(durationInMilliseconds)); this.removeStatement = session.prepare(delete() .from(CassandraAccessTokenTable.TABLE_NAME) .where(eq(CassandraAccessTokenTable.TOKEN, bindMarker(CassandraAccessTokenTable.TOKEN)))); this.insertStatement = session.prepare(insertInto(CassandraAccessTokenTable.TABLE_NAME) .value(CassandraAccessTokenTable.TOKEN, bindMarker(CassandraAccessTokenTable.TOKEN)) .value(CassandraAccessTokenTable.USERNAME, bindMarker(CassandraAccessTokenTable.USERNAME)) .using(ttl(bindMarker(TTL)))); this.selectStatement = session.prepare(select() .from(CassandraAccessTokenTable.TABLE_NAME) .where(eq(CassandraAccessTokenTable.TOKEN, bindMarker(CassandraAccessTokenTable.TOKEN)))); }
Example 2
Source File: SegmentNonMemoryPool.java From HaloDB with Apache License 2.0 | 6 votes |
SegmentNonMemoryPool(OffHeapHashTableBuilder<V> builder) { super(builder.getValueSerializer(), builder.getFixedValueSize(), builder.getHasher()); this.hashAlgorithm = builder.getHashAlgorighm(); int hts = builder.getHashTableSize(); if (hts <= 0) { hts = 8192; } if (hts < 256) { hts = 256; } int msz = Ints.checkedCast(HashTableUtil.roundUpToPowerOf2(hts, MAX_TABLE_SIZE)); table = Table.create(msz, throwOOME); if (table == null) { throw new RuntimeException("unable to allocate off-heap memory for segment"); } float lf = builder.getLoadFactor(); if (lf <= .0d) { lf = .75f; } this.loadFactor = lf; threshold = (long) ((double) table.size() * loadFactor); }
Example 3
Source File: Neo4jHelper.java From trainbenchmark with Eclipse Public License 1.0 | 5 votes |
public static int numberToInt(Number n) { if (n instanceof Integer) { return (Integer) n; } else if (n instanceof Long) { return Ints.checkedCast((Long) n); } else { throw new IllegalStateException("Length should be int or long"); } }
Example 4
Source File: DnsMessageTransport.java From nomulus with Apache License 2.0 | 5 votes |
/** * Class constructor. * * @param factory a factory for TCP sockets * @param updateHost host name of the DNS server * @param updateTimeout update I/O timeout */ @Inject public DnsMessageTransport( SocketFactory factory, @Config("dnsUpdateHost") String updateHost, @Config("dnsUpdateTimeout") Duration updateTimeout) { this.factory = factory; this.updateHost = updateHost; this.updateTimeout = Ints.checkedCast(updateTimeout.getMillis()); }
Example 5
Source File: SalesforceStep.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * normalize object for future sent in Salesforce * * @param valueMeta value meta * @param value pentaho internal value object * @return object for sending in Salesforce * @throws KettleValueException */ public Object normalizeValue( ValueMetaInterface valueMeta, Object value ) throws KettleValueException { if ( valueMeta.isDate() ) { // Pass date field converted to UTC, see PDI-10836 Calendar cal = Calendar.getInstance( valueMeta.getDateFormatTimeZone() ); cal.setTime( valueMeta.getDate( value ) ); Calendar utc = Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ); // Reset time-related fields utc.clear(); utc.set( cal.get( Calendar.YEAR ), cal.get( Calendar.MONTH ), cal.get( Calendar.DATE ), cal.get( Calendar.HOUR_OF_DAY ), cal.get( Calendar.MINUTE ), cal.get( Calendar.SECOND ) ); value = utc; } else if ( valueMeta.isStorageBinaryString() ) { value = valueMeta.convertToNormalStorageType( value ); } if ( ValueMetaInterface.TYPE_INTEGER == valueMeta.getType() ) { // Salesforce integer values can be only http://www.w3.org/2001/XMLSchema:int // see org.pentaho.di.ui.trans.steps.salesforceinput.SalesforceInputDialog#addFieldToTable // So we need convert Hitachi Vantara integer (real java Long value) to real int. // It will be sent correct as http://www.w3.org/2001/XMLSchema:int // use checked cast for prevent losing data value = Ints.checkedCast( (Long) value ); } return value; }
Example 6
Source File: PoolBasedLimiter.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Override public Closeable acquirePermits(long permits) throws InterruptedException { int permitsToAcquire = Ints.checkedCast(permits); this.permitPool.acquire(permitsToAcquire); return new PoolPermitCloseable(this.permitPool, permitsToAcquire); }
Example 7
Source File: Utils.java From autorest-clientruntime-for-java with MIT License | 5 votes |
/** * Converts an object Long to a primitive int. * * @param value the <tt>Long</tt> value * @return <tt>0</tt> if the given Long value is null else <tt>integer value</tt> */ public static int toPrimitiveInt(Long value) { if (value == null) { return 0; } // throws IllegalArgumentException - if value is greater than Integer.MAX_VALUE // or less than Integer.MIN_VALUE return Ints.checkedCast(value); }
Example 8
Source File: TimestampWatermark.java From incubator-gobblin with Apache License 2.0 | 5 votes |
/** * recalculate interval(in hours) if total number of partitions greater than maximum number of allowed partitions * * @param diffInMilliSecs difference in range * @param hourInterval hour interval (ex: 4 hours) * @param maxIntervals max number of allowed partitions * @return calculated interval in hours */ private static int getInterval(long diffInMilliSecs, long hourInterval, int maxIntervals) { long totalHours = DoubleMath.roundToInt((double) diffInMilliSecs / (60 * 60 * 1000), RoundingMode.CEILING); long totalIntervals = DoubleMath.roundToInt((double) totalHours / hourInterval, RoundingMode.CEILING); if (totalIntervals > maxIntervals) { hourInterval = DoubleMath.roundToInt((double) totalHours / maxIntervals, RoundingMode.CEILING); } return Ints.checkedCast(hourInterval); }
Example 9
Source File: ByteArrayPersistence.java From c5-replicator with Apache License 2.0 | 5 votes |
@Override public void truncate(long size) throws IOException { ensureNotClosed(); int intSize = Ints.checkedCast(size); byte[] bytes = stream.toByteArray(); stream = new ByteArrayOutputStream(intSize); stream.write(bytes, 0, intSize); }
Example 10
Source File: QuotientFilter.java From nuls-v2 with MIT License | 5 votes |
long getElement(long idx) { long elt = 0; long bitpos = ELEMENT_BITS * idx; int tabpos = Ints.checkedCast(bitpos / 64); long slotpos = bitpos % 64; long spillbits = (slotpos + ELEMENT_BITS) - 64; elt = (table[tabpos] >>> slotpos) & ELEMENT_MASK; if (spillbits > 0) { ++tabpos; long x = table[tabpos] & LOW_MASK(spillbits); elt |= x << (ELEMENT_BITS - spillbits); } return elt; }
Example 11
Source File: TftpFileChannelDataProvider.java From tftp4j with Apache License 2.0 | 5 votes |
@Override // @IgnoreJRERequirement public TftpData open(String filename) throws IOException { File file = toFile(filename); if (file == null) return null; RandomAccessFile raf = new RandomAccessFile(file, "r"); FileChannel channel = raf.getChannel(); // FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.READ); return new TftpFileChannelData(channel, Ints.checkedCast(channel.size())); }
Example 12
Source File: QuotientFilter.java From nuls-v2 with MIT License | 4 votes |
static int TABLE_SIZE(int quotientBits, int remainderBits) { long bits = (1L << quotientBits) * (remainderBits + 3); long longs = bits / 64; return Ints.checkedCast((bits % 64) > 0 ? (longs + 1) : longs); }
Example 13
Source File: SubstationImpl.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Override public int getTwoWindingsTransformerCount() { return Ints.checkedCast(getTwoWindingsTransformerStream() .count()); }
Example 14
Source File: NetworkImpl.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Override public <C extends Connectable> int getConnectableCount(Class<C> clazz) { return Ints.checkedCast(getConnectableStream(clazz).count()); }
Example 15
Source File: BloomFilterStrategies.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
BitArray(long bits) { this( new long[Ints.checkedCast(LongMath.divide(bits, 64, RoundingMode.CEILING))]); }
Example 16
Source File: BloomFilter.java From Elasticsearch with Apache License 2.0 | 4 votes |
BitArray(long bits) { this(new long[Ints.checkedCast(LongMath.divide(bits, 64, RoundingMode.CEILING))]); }
Example 17
Source File: RabbitMQWaitStrategy.java From james-project with Apache License 2.0 | 4 votes |
@Override public void waitUntilReady(WaitStrategyTarget waitStrategyTarget) { int seconds = Ints.checkedCast(this.timeout.getSeconds()); Unreliables.retryUntilTrue(seconds, TimeUnit.SECONDS, this::isConnected); }
Example 18
Source File: XdsTestClient.java From grpc-java with Apache License 2.0 | 4 votes |
private XdsStatsWatcher(long startId, long endId) { latch = new CountDownLatch(Ints.checkedCast(endId - startId)); this.startId = startId; this.endId = endId; }
Example 19
Source File: HeaderDecoder.java From opc-ua-stack with Apache License 2.0 | 2 votes |
/** * Get the message length from a {@link ByteBuf} containing a {@link TcpMessageEncoder}. The reader index will not be * advanced. * * @param buffer {@link ByteBuf} to extract from. * @return The message length, which includes the size of the header. */ default int getMessageLength(ByteBuf buffer) { return Ints.checkedCast(buffer.getUnsignedInt(buffer.readerIndex() + HEADER_LENGTH_INDEX)); }
Example 20
Source File: ShortCircuitShm.java From hadoop with Apache License 2.0 | 2 votes |
/** * Get the Slot index. * * @return The index of this slot. */ public int getSlotIdx() { return Ints.checkedCast( (slotAddress - baseAddress) / BYTES_PER_SLOT); }