List of usage examples for com.google.common.primitives Ints checkedCast
public static int checkedCast(long value)
From source file:fr.rjoakim.android.jonetouch.bean.AuthenticationTypeEnum.java
public static AuthenticationTypeEnum fromId(long id) { switch (Ints.checkedCast(id)) { case 1://from w ww . j a va 2 s.co m return AuthenticationTypeEnum.NO_AUTHENTICATION; case 2: return AuthenticationTypeEnum.SSH_AUTHENTICATION_PASSWORD; default: throw new IllegalArgumentException("authentication type :" + id + " not supported"); } }
From source file:ratpack.util.internal.IoUtils.java
public static ByteBuf read(ByteBufAllocator allocator, Path path) throws IOException { try (SeekableByteChannel sbc = Files.newByteChannel(path); InputStream in = Channels.newInputStream(sbc)) { int size = Ints.checkedCast(sbc.size()); ByteBuf byteBuf = allocator.directBuffer(size, size); byteBuf.writeBytes(in, size);//w ww .j a v a 2 s .c o m return byteBuf; } }
From source file:at.ac.univie.isc.asio.junit.Rules.java
/** * @param value max duration of test/*from w w w . j a v a 2s . c o m*/ * @param unit unit of the max duration * @return A new {@link org.junit.rules.Timeout} rule with the given value. */ public static Timeout timeout(final int value, final TimeUnit unit) { return new Timeout(Ints.checkedCast(unit.toMillis(value))); }
From source file:io.github.mywarp.mywarp.bukkit.util.material.MaterialInfo.java
/** * Gets the {@code Material} of the block at the given position within the given world. * * @param world the world/*from www. j a v a2 s.c om*/ * @param position the position * @return the Material of the block at the given position */ static Material getMaterial(LocalWorld world, Vector3i position) { return BukkitAdapter.adapt(world).getBlockAt(Ints.checkedCast(position.getX()), Ints.checkedCast(position.getY()), Ints.checkedCast(position.getZ())).getType(); }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.util.ConfigUtil.java
public static int getOptionalValue(NodeState definition, String propName, int defaultVal) { PropertyState ps = definition.getProperty(propName); return ps == null ? defaultVal : Ints.checkedCast(ps.getValue(Type.LONG)); }
From source file:org.opendaylight.openflowjava.nx.codec.match.NxmHeader.java
public NxmHeader(long header) { this.headerAsLong = header; this.oxmClass = Ints.checkedCast(extractSub(header, 16, 16)); this.nxmField = Ints.checkedCast(extractSub(header, 7, 9)); this.hasMask = extractSub(header, 1, 8) == 1 ? true : false; this.length = Ints.checkedCast(extractSub(header, 8, 0)); }
From source file:org.obm.push.utils.jvm.JvmUtils.java
public static int maxRuntimeJvmMemoryInMB() { return Ints.checkedCast(Runtime.getRuntime().maxMemory() / (1024 * 1024)); }
From source file:de.softwareforge.kafka.LongPartitioner.java
@Override public int partition(Object value, int numPartitions) { if (value instanceof Long) { return Ints.checkedCast(((Long) value) % numPartitions); } else {/* w w w . j av a 2 s . com*/ return 0; } }
From source file:com.facebook.presto.kafka.util.NumberPartitioner.java
@Override public int partition(Object key, int numPartitions) { if (key instanceof Number) { return Ints.checkedCast(((Number) key).longValue() % numPartitions); }// www . j a v a2 s . co m return 0; }
From source file:org.apache.spark.unsafe.hash.Murmur3_x86_32.java
public static int hashUnsafeWordsBlock(MemoryBlock base, int seed) { // This is based on Guava's `Murmur32_Hasher.processRemaining(ByteBuffer)` method. int lengthInBytes = Ints.checkedCast(base.size()); assert (lengthInBytes % 8 == 0) : "lengthInBytes must be a multiple of 8 (word-aligned)"; int h1 = hashBytesByIntBlock(base, seed); return fmix(h1, lengthInBytes); }