List of usage examples for java.lang Byte MIN_VALUE
byte MIN_VALUE
To view the source code for java.lang Byte MIN_VALUE.
Click Source Link
From source file:NumberUtils.java
/** * Convert the given number into an instance of the given target class. * @param number the number to convert//from www . j a v a 2s . 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:org.vertx.java.http.eventbusbridge.integration.MessagePublishTest.java
@Test public void testPublishingByteJson() throws IOException { final EventBusMessageType messageType = EventBusMessageType.Byte; final Byte sentByte = Byte.MIN_VALUE; Map<String, String> expectations = createExpectations(generateUniqueAddress(), Base64.encodeAsString(sentByte.toString()), messageType); final AtomicInteger completedCount = new AtomicInteger(0); Handler<Message> messagePublishHandler = new MessagePublishHandler(sentByte, expectations, completedCount); registerListenersAndCheckForResponses(messagePublishHandler, expectations, NUMBER_OF_PUBLISH_HANDLERS, completedCount);/*from w w w . j av a 2 s .c om*/ String body = TemplateHelper.generateOutputUsingTemplate(SEND_REQUEST_TEMPLATE_JSON, expectations); HttpRequestHelper.sendHttpPostRequest(url, body, (VertxInternal) vertx, Status.ACCEPTED.getStatusCode(), MediaType.APPLICATION_JSON); }
From source file:org.apache.accumulo.examples.simple.client.ReadWriteExample.java
private void execute() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, MutationsRejectedException { // create table if (hasOpt(createtableOpt)) { SortedSet<Text> partitionKeys = new TreeSet<Text>(); for (int i = Byte.MIN_VALUE; i < Byte.MAX_VALUE; i++) partitionKeys.add(new Text(new byte[] { (byte) i })); conn.tableOperations().create(getOpt(tableNameOpt, DEFAULT_TABLE_NAME)); conn.tableOperations().addSplits(getOpt(tableNameOpt, DEFAULT_TABLE_NAME), partitionKeys); }/*from w w w. ja v a 2 s . co m*/ // create entries if (hasOpt(createEntriesOpt)) createEntries(false); // delete entries if (hasOpt(deleteEntriesOpt)) createEntries(true); // read entries if (hasOpt(readEntriesOpt)) { // Note that the user needs to have the authorizations for the specified scan authorizations // by an administrator first Authorizations scanauths = new Authorizations(getOpt(scanAuthsOpt, DEFAULT_AUTHS).split(",")); Scanner scanner = conn.createScanner(getOpt(tableNameOpt, DEFAULT_TABLE_NAME), scanauths); for (Entry<Key, Value> entry : scanner) System.out.println(entry.getKey().toString() + " -> " + entry.getValue().toString()); } // delete table if (hasOpt(deletetableOpt)) conn.tableOperations().delete(getOpt(tableNameOpt, DEFAULT_TABLE_NAME)); }
From source file:io.horizondb.model.core.fields.DecimalField.java
/** * {@inheritDoc}/* w ww.j a va 2 s . c o m*/ */ @Override public Field setDecimal(long mantissa, int exponent) { Validate.isTrue(exponent <= Byte.MAX_VALUE && exponent >= Byte.MIN_VALUE, "the specified exponent is not a byte value"); this.mantissa = mantissa; this.exponent = (byte) exponent; return this; }
From source file:org.apache.accumulo.core.client.mapreduce.RangeInputSplit.java
/** * This implementation of length is only an estimate, it does not provide exact values. Do not have your code rely on this return value. *///from w w w. jav a2s . c o m @Override public long getLength() throws IOException { Text startRow = range.isInfiniteStartKey() ? new Text(new byte[] { Byte.MIN_VALUE }) : range.getStartKey().getRow(); Text stopRow = range.isInfiniteStopKey() ? new Text(new byte[] { Byte.MAX_VALUE }) : range.getEndKey().getRow(); int maxCommon = Math.min(7, Math.min(startRow.getLength(), stopRow.getLength())); long diff = 0; byte[] start = startRow.getBytes(); byte[] stop = stopRow.getBytes(); for (int i = 0; i < maxCommon; ++i) { diff |= 0xff & (start[i] ^ stop[i]); diff <<= Byte.SIZE; } if (startRow.getLength() != stopRow.getLength()) diff |= 0xff; return diff + 1; }
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);/*from w w w .ja v a2 s . c o m*/ 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); }
From source file:streamflow.model.generator.RandomGenerator.java
public static Byte randomByte() { return (byte) (Byte.MIN_VALUE + RandomUtils.nextInt(Byte.MAX_VALUE - Byte.MIN_VALUE)); }
From source file:com.mozilla.hadoop.hbase.mapreduce.MultiScanTableMapReduceUtil.java
/** * Same as above version but allows for specifying batch size as well * @param startCal// w ww. j a v a 2 s . com * @param endCal * @param dateFormat * @param columns * @param caching * @param cacheBlocks * @param batch * @return */ public static Scan[] generateBytePrefixScans(Calendar startCal, Calendar endCal, String dateFormat, List<Pair<String, String>> columns, int caching, boolean cacheBlocks, int batch) { ArrayList<Scan> scans = new ArrayList<Scan>(); SimpleDateFormat rowsdf = new SimpleDateFormat(dateFormat); long endTime = DateUtil.getEndTimeAtResolution(endCal.getTimeInMillis(), Calendar.DATE); byte[] temp = new byte[1]; while (startCal.getTimeInMillis() < endTime) { for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) { int d = Integer.parseInt(rowsdf.format(startCal.getTime())); Scan s = new Scan(); s.setCaching(caching); s.setCacheBlocks(cacheBlocks); if (batch > 1) { s.setBatch(batch); } // add columns for (Pair<String, String> pair : columns) { s.addColumn(pair.getFirst().getBytes(), pair.getSecond().getBytes()); } temp[0] = b; s.setStartRow(Bytes.add(temp, Bytes.toBytes(String.format("%06d", d)))); s.setStopRow(Bytes.add(temp, Bytes.toBytes(String.format("%06d", d + 1)))); if (LOG.isDebugEnabled()) { LOG.info("Adding start-stop range: " + temp + String.format("%06d", d) + " - " + temp + String.format("%06d", d + 1)); } scans.add(s); } startCal.add(Calendar.DATE, 1); } return scans.toArray(new Scan[scans.size()]); }
From source file:it.geosolutions.jaiext.range.RangeTest.java
@BeforeClass public static void initialSetup() { arrayB = new byte[] { 0, 1, 5, 50, 100 }; arrayUS = new short[] { 0, 1, 5, 50, 100 }; arrayS = new short[] { -10, 0, 5, 50, 100 }; arrayI = new int[] { -10, 0, 5, 50, 100 }; arrayF = new float[] { -10, 0, 5, 50, 100 }; arrayD = new double[] { -10, 0, 5, 50, 100 }; arrayL = new long[] { -10, 0, 5, 50, 100 }; rangeB2bounds = RangeFactory.create((byte) 2, true, (byte) 60, true); rangeBpoint = RangeFactory.create(arrayB[2], true, arrayB[2], true); rangeU2bounds = RangeFactory.createU((short) 2, true, (short) 60, true); rangeUpoint = RangeFactory.createU(arrayUS[2], true, arrayUS[2], true); rangeS2bounds = RangeFactory.create((short) 1, true, (short) 60, true); rangeSpoint = RangeFactory.create(arrayS[2], true, arrayS[2], true); rangeI2bounds = RangeFactory.create(1, true, 60, true); rangeIpoint = RangeFactory.create(arrayI[2], true, arrayI[2], true); rangeF2bounds = RangeFactory.create(0.5f, true, 60.5f, true, false); rangeFpoint = RangeFactory.create(arrayF[2], true, arrayF[2], true, false); rangeD2bounds = RangeFactory.create(1.5d, true, 60.5d, true, false); rangeDpoint = RangeFactory.create(arrayD[2], true, arrayD[2], true, false); rangeL2bounds = RangeFactory.create(1L, true, 60L, true); rangeLpoint = RangeFactory.create(arrayL[2], true, arrayL[2], true); arrayBtest = new Byte[100]; arrayStest = new Short[100]; arrayItest = new Integer[100]; arrayFtest = new Float[100]; arrayDtest = new Double[100]; // Random value creation for the various Ranges for (int j = 0; j < 100; j++) { double randomValue = Math.random(); arrayBtest[j] = (byte) (randomValue * (Byte.MAX_VALUE - Byte.MIN_VALUE) + Byte.MIN_VALUE); arrayStest[j] = (short) (randomValue * (Short.MAX_VALUE - Short.MIN_VALUE) + Short.MIN_VALUE); arrayItest[j] = (int) (randomValue * (Integer.MAX_VALUE - Integer.MIN_VALUE) + Integer.MIN_VALUE); arrayFtest[j] = (float) (randomValue * (Float.MAX_VALUE - Float.MIN_VALUE) + Float.MIN_VALUE); arrayDtest[j] = (randomValue * (Double.MAX_VALUE - Double.MIN_VALUE) + Double.MIN_VALUE); }/*from w w w. j a v a2 s. c o m*/ // JAI tools Ranges rangeJTB = org.jaitools.numeric.Range.create((byte) 1, true, (byte) 60, true); rangeJTS = org.jaitools.numeric.Range.create((short) 1, true, (short) 60, true); rangeJTI = org.jaitools.numeric.Range.create(1, true, 60, true); rangeJTF = org.jaitools.numeric.Range.create(0.5f, true, 60.5f, true); rangeJTD = org.jaitools.numeric.Range.create(1.5d, true, 60.5d, true); // 1 point Ranges rangeJTBpoint = org.jaitools.numeric.Range.create((byte) 5, true, (byte) 5, true); rangeJTSpoint = org.jaitools.numeric.Range.create((short) 5, true, (short) 5, true); rangeJTIpoint = org.jaitools.numeric.Range.create(5, true, 5, true); rangeJTFpoint = org.jaitools.numeric.Range.create(5f, true, 5f, true); rangeJTDpoint = org.jaitools.numeric.Range.create(5d, true, 5d, true); // JAI Ranges rangeJAIB = new javax.media.jai.util.Range(Byte.class, (byte) 1, true, (byte) 60, true); rangeJAIS = new javax.media.jai.util.Range(Short.class, (short) 1, true, (short) 60, true); rangeJAII = new javax.media.jai.util.Range(Integer.class, 1, true, 60, true); rangeJAIF = new javax.media.jai.util.Range(Float.class, 0.5f, true, 60.5f, true); rangeJAID = new javax.media.jai.util.Range(Double.class, 1.5d, true, 60.5d, true); // 1 point Ranges rangeJAIBpoint = new javax.media.jai.util.Range(Byte.class, (byte) 5, true, (byte) 5, true); rangeJAISpoint = new javax.media.jai.util.Range(Short.class, (short) 5, true, (short) 5, true); rangeJAIIpoint = new javax.media.jai.util.Range(Integer.class, 5, true, 5, true); rangeJAIFpoint = new javax.media.jai.util.Range(Float.class, 5f, true, 5f, true); rangeJAIDpoint = new javax.media.jai.util.Range(Double.class, 5d, true, 5d, true); // Apache Common Ranges rangeCommonsB = new org.apache.commons.lang.math.IntRange((byte) 1, (byte) 60); rangeCommonsS = new org.apache.commons.lang.math.IntRange((short) 1, (short) 60); rangeCommonsI = new org.apache.commons.lang.math.IntRange(1, 60); rangeCommonsF = new org.apache.commons.lang.math.FloatRange(0.5f, 60.5f); rangeCommonsD = new org.apache.commons.lang.math.DoubleRange(1.5d, 60.5d); // 1 point Ranges rangeCommonsBpoint = new org.apache.commons.lang.math.IntRange(5); rangeCommonsSpoint = new org.apache.commons.lang.math.IntRange(5); rangeCommonsIpoint = new org.apache.commons.lang.math.IntRange(5); rangeCommonsFpoint = new org.apache.commons.lang.math.FloatRange(5f); rangeCommonsDpoint = new org.apache.commons.lang.math.DoubleRange(5d); // // GeoTools Ranges // rangeGeoToolsB = new org.geotools.util.NumberRange<Byte>(Byte.class, (byte) 1, (byte) 60); // rangeGeoToolsS = new org.geotools.util.NumberRange<Short>(Short.class, (short) 1, // (short) 60); // rangeGeoToolsI = new org.geotools.util.NumberRange<Integer>(Integer.class, 1, 60); // rangeGeoToolsF = new org.geotools.util.NumberRange<Float>(Float.class, 0.5f, 60.5f); // rangeGeoToolsD = new org.geotools.util.NumberRange<Double>(Double.class, 1.5d, 60.5d); // // 1 point Ranges // rangeGeoToolsBpoint = new org.geotools.util.NumberRange<Byte>(Byte.class, (byte) 5, // (byte) 5); // rangeGeoToolsSpoint = new org.geotools.util.NumberRange<Short>(Short.class, (short) 5, // (short) 5); // rangeGeoToolsIpoint = new org.geotools.util.NumberRange<Integer>(Integer.class, 5, 5); // rangeGeoToolsFpoint = new org.geotools.util.NumberRange<Float>(Float.class, 5f, 5f); // rangeGeoToolsDpoint = new org.geotools.util.NumberRange<Double>(Double.class, 5d, 5d); // // Guava Ranges // rangeGuavaB = com.google.common.collect.Range.closed((byte) 1, (byte) 60); // rangeGuavaS = com.google.common.collect.Range.closed((short) 1, (short) 60); // rangeGuavaI = com.google.common.collect.Range.closed(1, 60); // rangeGuavaF = com.google.common.collect.Range.closed(0.5f, 60.5f); // rangeGuavaD = com.google.common.collect.Range.closed(1.5d, 60.5d); // // 1 point Ranges // rangeGuavaBpoint = com.google.common.collect.Range.singleton((byte) 5); // rangeGuavaSpoint = com.google.common.collect.Range.singleton((short) 5); // rangeGuavaIpoint = com.google.common.collect.Range.singleton(5); // rangeGuavaFpoint = com.google.common.collect.Range.singleton(5f); // rangeGuavaDpoint = com.google.common.collect.Range.singleton(5d); }
From source file:org.diorite.utils.math.ByteRange.java
/** * Parses given string to range, string is valid range when contains 2 numbers (second greater than first) and splt char: <br> * " - ", " : ", " ; ", ", ", " ", ",", ";", ":", "-" * * @param string string to parse./*from ww w . j av a 2 s.co m*/ * * @return parsed range or null. */ public static ByteRange valueOf(String string) { if (string.isEmpty()) { return null; } String[] nums = null; int i = 0; final boolean firstMinus = string.charAt(0) == '-'; if (firstMinus) { string = string.substring(1); } while ((i < SPLITS.length) && ((nums == null) || (nums.length != 2))) { nums = StringUtils.splitByWholeSeparator(string, SPLITS[i++], 2); } if ((nums == null) || (nums.length != 2)) { return null; } final Integer min = DioriteMathUtils.asInt(firstMinus ? ("-" + nums[0]) : nums[0]); if ((min == null) || (min < Byte.MIN_VALUE)) { return null; } final Integer max = DioriteMathUtils.asInt(nums[1]); if ((max == null) || (max > Byte.MAX_VALUE) || (min > max)) { return null; } return new ByteRange(min.byteValue(), max.byteValue()); }