List of usage examples for java.lang Short MIN_VALUE
short MIN_VALUE
To view the source code for java.lang Short MIN_VALUE.
Click Source Link
From source file:org.apache.hadoop.hive.hbase.HBaseTestSetup.java
private void createHBaseTable() throws IOException { final String HBASE_TABLE_NAME = "HiveExternalTable"; HTableDescriptor htableDesc = new HTableDescriptor(HBASE_TABLE_NAME.getBytes()); HColumnDescriptor hcolDesc = new HColumnDescriptor("cf".getBytes()); htableDesc.addFamily(hcolDesc);//from w ww . j a v a2 s . c o m boolean[] booleans = new boolean[] { true, false, true }; byte[] bytes = new byte[] { Byte.MIN_VALUE, -1, Byte.MAX_VALUE }; short[] shorts = new short[] { Short.MIN_VALUE, -1, Short.MAX_VALUE }; int[] ints = new int[] { Integer.MIN_VALUE, -1, Integer.MAX_VALUE }; long[] longs = new long[] { Long.MIN_VALUE, -1, Long.MAX_VALUE }; String[] strings = new String[] { "Hadoop, HBase,", "Hive", "Test Strings" }; float[] floats = new float[] { Float.MIN_VALUE, -1.0F, Float.MAX_VALUE }; double[] doubles = new double[] { Double.MIN_VALUE, -1.0, Double.MAX_VALUE }; HBaseAdmin hbaseAdmin = null; HTableInterface htable = null; try { hbaseAdmin = new HBaseAdmin(hbaseConn.getConfiguration()); if (Arrays.asList(hbaseAdmin.listTables()).contains(htableDesc)) { // if table is already in there, don't recreate. return; } hbaseAdmin.createTable(htableDesc); htable = hbaseConn.getTable(HBASE_TABLE_NAME); // data Put[] puts = new Put[] { new Put("key-1".getBytes()), new Put("key-2".getBytes()), new Put("key-3".getBytes()) }; // store data for (int i = 0; i < puts.length; i++) { puts[i].add("cf".getBytes(), "cq-boolean".getBytes(), Bytes.toBytes(booleans[i])); puts[i].add("cf".getBytes(), "cq-byte".getBytes(), new byte[] { bytes[i] }); puts[i].add("cf".getBytes(), "cq-short".getBytes(), Bytes.toBytes(shorts[i])); puts[i].add("cf".getBytes(), "cq-int".getBytes(), Bytes.toBytes(ints[i])); puts[i].add("cf".getBytes(), "cq-long".getBytes(), Bytes.toBytes(longs[i])); puts[i].add("cf".getBytes(), "cq-string".getBytes(), Bytes.toBytes(strings[i])); puts[i].add("cf".getBytes(), "cq-float".getBytes(), Bytes.toBytes(floats[i])); puts[i].add("cf".getBytes(), "cq-double".getBytes(), Bytes.toBytes(doubles[i])); htable.put(puts[i]); } } finally { if (htable != null) htable.close(); if (hbaseAdmin != null) hbaseAdmin.close(); } }
From source file:org.apache.camel.dataformat.bindy.BindyAbstractFactory.java
public static Object getDefaultValueForPrimitive(Class<?> clazz) throws Exception { if (clazz == byte.class) { return Byte.MIN_VALUE; } else if (clazz == short.class) { return Short.MIN_VALUE; } else if (clazz == int.class) { return Integer.MIN_VALUE; } else if (clazz == long.class) { return Long.MIN_VALUE; } else if (clazz == float.class) { return Float.MIN_VALUE; } else if (clazz == double.class) { return Double.MIN_VALUE; } else if (clazz == char.class) { return Character.MIN_VALUE; } else if (clazz == boolean.class) { return false; } else {/*from w ww . ja v a 2s. com*/ return null; } }
From source file:com.facebook.presto.operator.scalar.MathFunctions.java
@Description("absolute value") @ScalarFunction("abs") @SqlType(StandardTypes.SMALLINT)/*w w w. j a va2 s . c o m*/ public static long absSmallint(@SqlType(StandardTypes.SMALLINT) long num) { checkCondition(num != Short.MIN_VALUE, NUMERIC_VALUE_OUT_OF_RANGE, "Value -32768 is out of range for abs(smallint)"); return Math.abs(num); }
From source file:com.streamsets.pipeline.stage.origin.jdbc.table.AllTypesIT.java
private static void populateRecords() { Record record = RecordCreator.create(); LinkedHashMap<String, Field> fields; AtomicInteger id_field = new AtomicInteger(0); //CHAR_AND_BINARY fields = new LinkedHashMap<>(); createIdField(fields, id_field);/*from w w w . j a va 2 s . com*/ fields.put("char1", Field.create("abcdefghij")); fields.put("varchar1", Field.create(UUID.randomUUID().toString())); fields.put("clob1", Field.create(UUID.randomUUID().toString())); fields.put("varbinary1", Field.create(UUID.randomUUID().toString().getBytes())); fields.put("blob1", Field.create(UUID.randomUUID().toString().getBytes())); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("CHAR_AND_BINARY").getRight().add(record); //Date and time record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); fields.put("date1", Field.create(Field.Type.DATE, calendar.getTime())); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.MILLISECOND, 0); fields.put("timestamp1", Field.create(Field.Type.DATETIME, calendar.getTime())); fields.put("datetime1", Field.create(Field.Type.DATETIME, calendar.getTime())); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.YEAR, 1970); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.MILLISECOND, 0); fields.put("time1", Field.create(Field.Type.TIME, calendar.getTime())); calendar.setTimeInMillis(System.currentTimeMillis()); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("DATE_AND_TIME").getRight().add(record); //DIFFERENT_INTS record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("int1", Field.create(Field.Type.INTEGER, Integer.MIN_VALUE)); fields.put("int2", Field.create(Field.Type.INTEGER, Integer.MIN_VALUE)); fields.put("mediumint1", Field.create(Field.Type.INTEGER, Integer.MIN_VALUE)); fields.put("tinyint1", Field.create(Field.Type.SHORT, -128)); fields.put("smallint1", Field.create(Field.Type.SHORT, Short.MIN_VALUE)); fields.put("bigint1", Field.create(Field.Type.LONG, Long.MIN_VALUE)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("DIFFERENT_INTS").getRight().add(record); record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("int1", Field.create(Field.Type.INTEGER, Integer.MAX_VALUE)); fields.put("int2", Field.create(Field.Type.INTEGER, Integer.MAX_VALUE)); fields.put("mediumint1", Field.create(Field.Type.INTEGER, Integer.MAX_VALUE)); fields.put("tinyint1", Field.create(Field.Type.SHORT, 127)); fields.put("smallint1", Field.create(Field.Type.SHORT, Short.MAX_VALUE)); fields.put("bigint1", Field.create(Field.Type.LONG, Long.MAX_VALUE)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("DIFFERENT_INTS").getRight().add(record); //FLOATING_PT_INTS record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("decimal1", Field.create(Field.Type.DECIMAL, new BigDecimal("12.345"))); fields.put("number1", Field.create(Field.Type.DECIMAL, new BigDecimal("0.12345"))); fields.put("double1", Field.create(Field.Type.DOUBLE, 123.456)); fields.put("real1", Field.create(Field.Type.FLOAT, 12.34)); fields.put("floatdouble1", Field.create(Field.Type.DOUBLE, Double.MAX_VALUE)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("FLOATING_PT_INTS").getRight().add(record); record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("decimal1", Field.create(Field.Type.DECIMAL, new BigDecimal("-12.345"))); fields.put("number1", Field.create(Field.Type.DECIMAL, new BigDecimal("-0.12345"))); fields.put("double1", Field.create(Field.Type.DOUBLE, -123.456)); fields.put("real1", Field.create(Field.Type.FLOAT, -12.34)); fields.put("floatdouble1", Field.create(Field.Type.DOUBLE, Double.MIN_VALUE)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("FLOATING_PT_INTS").getRight().add(record); //OTHER_TYPES record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("boolean1", Field.create(Field.Type.BOOLEAN, true)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("OTHER_TYPES").getRight().add(record); record = RecordCreator.create(); fields = new LinkedHashMap<>(); createIdField(fields, id_field); fields.put("boolean1", Field.create(Field.Type.BOOLEAN, false)); record.set(Field.createListMap(fields)); TABLE_TO_TEMPLATE_AND_RECORDS_MAP.get("OTHER_TYPES").getRight().add(record); }
From source file:com.alibaba.simpleimage.util.ImageUtils.java
public static final short clampRoundShort(double in) { return (in > Short.MAX_VALUE ? Short.MAX_VALUE : (in >= Short.MIN_VALUE ? (short) Math.floor(in + 0.5) : Short.MIN_VALUE)); }
From source file:ac.elements.parser.SimpleDBConverter.java
/** * Decodes zero-padded positive short value from the string representation * /* w w w. jav a 2 s . co m*/ * com.xerox.amazonws.sdb.DataUtils * * @param value * zero-padded string representation of the short * @return original short value */ private static short decodeShort(String value) { return (short) (Long.parseLong(value, RADIX) - Short.MIN_VALUE); }
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert// w w w. j av a2 s .c o m * @param targetClass the target class to convert to * @return the converted number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte * @see java.lang.Short * @see java.lang.Integer * @see java.lang.Long * @see java.math.BigInteger * @see java.lang.Float * @see java.lang.Double * @see java.math.BigDecimal */ public static Number convertNumberToTargetClass(Number number, Class<?> targetClass) throws IllegalArgumentException { // Assert.notNull(number, "Number must not be null"); // Assert.notNull(targetClass, "Target class must not be null"); if (targetClass.isInstance(number)) { return number; } else if (targetClass.equals(Byte.class)) { long value = number.longValue(); if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Byte(number.byteValue()); } else if (targetClass.equals(Short.class)) { long value = number.longValue(); if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Short(number.shortValue()); } else if (targetClass.equals(Integer.class)) { long value = number.longValue(); if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { raiseOverflowException(number, targetClass); } return new Integer(number.intValue()); } else if (targetClass.equals(Long.class)) { return new Long(number.longValue()); } else if (targetClass.equals(Float.class)) { return new Float(number.floatValue()); } else if (targetClass.equals(Double.class)) { return new Double(number.doubleValue()); } else if (targetClass.equals(BigInteger.class)) { return BigInteger.valueOf(number.longValue()); } else if (targetClass.equals(BigDecimal.class)) { // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double) // (see BigDecimal javadoc for details) return new BigDecimal(number.toString()); } else { throw new IllegalArgumentException("Could not convert number [" + number + "] of type [" + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]"); } }
From source file:ac.elements.parser.SimpleDBConverter.java
/** * Encodes real long value into a string by offsetting and zero-padding * number up to the specified number of digits. Use this encoding method if * the data range set includes both positive and negative values. * /*from www.j a va2 s. c o m*/ * com.xerox.amazonws.sdb.DataUtils * * @param number * short to be encoded * @return string representation of the short */ private static String encodeShort(short number) { int maxNumDigits = BigInteger.valueOf(Short.MAX_VALUE).subtract(BigInteger.valueOf(Short.MIN_VALUE)) .toString(RADIX).length(); long offsetValue = Short.MIN_VALUE; BigInteger offsetNumber = BigInteger.valueOf(number).subtract(BigInteger.valueOf(offsetValue)); String longString = offsetNumber.toString(RADIX); int numZeroes = maxNumDigits - longString.length(); StringBuffer strBuffer = new StringBuffer(numZeroes + longString.length()); for (int i = 0; i < numZeroes; i++) { strBuffer.insert(i, '0'); } strBuffer.append(longString); return strBuffer.toString(); }
From source file:com.github.rvesse.airline.restrictions.factories.RangeRestrictionFactory.java
protected RangeRestriction createShortRange(Annotation annotation) { ShortRange sRange = (ShortRange) annotation; return new RangeRestriction( sRange.min() != Short.MIN_VALUE || !sRange.minInclusive() ? Short.valueOf(sRange.min()) : null, sRange.minInclusive(),/*from w ww .j a v a 2s . c om*/ sRange.max() != Short.MAX_VALUE || !sRange.maxInclusive() ? Short.valueOf(sRange.max()) : null, sRange.maxInclusive(), SHORT_COMPARATOR); }
From source file:org.janusgraph.graphdb.serializer.SerializerTest.java
License:asdf
@Test public void primitiveSerialization() { DataOutput out = serialize.getDataOutput(128); out.writeObjectNotNull(Boolean.FALSE); out.writeObjectNotNull(Boolean.TRUE); out.writeObjectNotNull(Byte.MIN_VALUE); out.writeObjectNotNull(Byte.MAX_VALUE); out.writeObjectNotNull((byte) 0); out.writeObjectNotNull(Short.MIN_VALUE); out.writeObjectNotNull(Short.MAX_VALUE); out.writeObjectNotNull((short) 0); out.writeObjectNotNull(Character.MIN_VALUE); out.writeObjectNotNull(Character.MAX_VALUE); out.writeObjectNotNull('a'); out.writeObjectNotNull(Integer.MIN_VALUE); out.writeObjectNotNull(Integer.MAX_VALUE); out.writeObjectNotNull(0);// w w w . ja v a2 s. c om out.writeObjectNotNull(Long.MIN_VALUE); out.writeObjectNotNull(Long.MAX_VALUE); out.writeObjectNotNull(0L); out.writeObjectNotNull((float) 0.0); out.writeObjectNotNull(0.0); ReadBuffer b = out.getStaticBuffer().asReadBuffer(); assertEquals(Boolean.FALSE, serialize.readObjectNotNull(b, Boolean.class)); assertEquals(Boolean.TRUE, serialize.readObjectNotNull(b, Boolean.class)); assertEquals(Byte.MIN_VALUE, serialize.readObjectNotNull(b, Byte.class).longValue()); assertEquals(Byte.MAX_VALUE, serialize.readObjectNotNull(b, Byte.class).longValue()); assertEquals(0, serialize.readObjectNotNull(b, Byte.class).longValue()); assertEquals(Short.MIN_VALUE, serialize.readObjectNotNull(b, Short.class).longValue()); assertEquals(Short.MAX_VALUE, serialize.readObjectNotNull(b, Short.class).longValue()); assertEquals(0, serialize.readObjectNotNull(b, Short.class).longValue()); assertEquals(Character.MIN_VALUE, serialize.readObjectNotNull(b, Character.class).charValue()); assertEquals(Character.MAX_VALUE, serialize.readObjectNotNull(b, Character.class).charValue()); assertEquals(new Character('a'), serialize.readObjectNotNull(b, Character.class)); assertEquals(Integer.MIN_VALUE, serialize.readObjectNotNull(b, Integer.class).longValue()); assertEquals(Integer.MAX_VALUE, serialize.readObjectNotNull(b, Integer.class).longValue()); assertEquals(0, serialize.readObjectNotNull(b, Integer.class).longValue()); assertEquals(Long.MIN_VALUE, serialize.readObjectNotNull(b, Long.class).longValue()); assertEquals(Long.MAX_VALUE, serialize.readObjectNotNull(b, Long.class).longValue()); assertEquals(0, serialize.readObjectNotNull(b, Long.class).longValue()); assertEquals(0.0, serialize.readObjectNotNull(b, Float.class), 1e-20); assertEquals(0.0, serialize.readObjectNotNull(b, Double.class), 1e-20); }