Example usage for java.lang Byte MIN_VALUE

List of usage examples for java.lang Byte MIN_VALUE

Introduction

In this page you can find the example usage for java.lang Byte MIN_VALUE.

Prototype

byte MIN_VALUE

To view the source code for java.lang Byte MIN_VALUE.

Click Source Link

Document

A constant holding the minimum value a byte can have, -27.

Usage

From source file:org.jts.eclipse.conversion.cjsidl.ConversionUtil.java

/**
 * converts a range of values to a JSIDL type.  This is used where the CJSIDL
 * grammar does not include type in the definition of a range.
 * @param lowerLim - the lower limit of the range
 * @param upperLim - the upper limit of the range
 * @return - a string representing a JSIDL data type that can hold the upper and 
 * lower limits./*from  www .  jav a  2  s.c o m*/
 */
public static String rangeToJSIDLType(long lowerLim, long upperLim) {
    long range = upperLim - lowerLim;
    String type = "unsigned byte";
    if (range >= Byte.MIN_VALUE && range <= Byte.MAX_VALUE) {
        type = "unsigned byte";
    } else if (range >= Short.MIN_VALUE && range <= Short.MAX_VALUE) {
        type = "unsigned short integer";
    } else if (range >= Integer.MIN_VALUE && range <= Integer.MAX_VALUE) {
        type = "unsigned integer";
    } else {
        type = "unsigned long integer";
    }

    return type;
}

From source file:org.mule.util.NumberUtils.java

@SuppressWarnings("unchecked")
public static <T extends Number> T convertNumberToTargetClass(Number number, Class<T> targetClass)
        throws IllegalArgumentException {

    if (targetClass.isInstance(number)) {
        return (T) number;
    } else if (targetClass.equals(Byte.class)) {
        long value = number.longValue();
        if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }/*from   w ww. j  a  v  a2s .com*/
        return (T) 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 (T) 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 (T) new Integer(number.intValue());
    } else if (targetClass.equals(Long.class)) {
        return (T) new Long(number.longValue());
    } else if (targetClass.equals(BigInteger.class)) {
        if (number instanceof BigDecimal) {
            // do not lose precision - use BigDecimal's own conversion
            return (T) ((BigDecimal) number).toBigInteger();
        } else {
            // original value is not a Big* number - use standard long conversion
            return (T) BigInteger.valueOf(number.longValue());
        }
    } else if (targetClass.equals(Float.class)) {
        return (T) new Float(number.floatValue());
    } else if (targetClass.equals(Double.class)) {
        return (T) new Double(number.doubleValue());
    } else if (targetClass.equals(BigDecimal.class)) {
        // always use BigDecimal(String) here to avoid unpredictability of
        // BigDecimal(double)
        // (see BigDecimal javadoc for details)
        return (T) 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.omnaest.utils.codec.EncoderAndDecoderAlphanumericTokens.java

@Override
public String decode(String source) {
    ////from ww  w.j  a  v a2  s  .com
    final StringBuilder stringBuilder = new StringBuilder();

    //
    if (source != null) {
        //
        final ElementConverter<String, Byte> elementConverterTokenToByte = new ElementConverter<String, Byte>() {
            @Override
            public Byte convert(String element) {
                short convert = Short.valueOf(element);
                return (byte) (convert + Byte.MIN_VALUE);
            }
        };

        //
        final Pattern pattern = Pattern.compile("(" + ALPHA_LETTER_REGEX + "+)|([0-9]+)");
        final Matcher matcher = pattern.matcher(source);

        while (matcher.find()) {
            //
            final String groupAlphaLetters = matcher.group(1);
            final String groupNumbers = matcher.group(2);

            //
            if (StringUtils.isNotBlank(groupAlphaLetters)) {
                stringBuilder.append(groupAlphaLetters);
            } else if (StringUtils.isNotBlank(groupNumbers)) {
                //
                try {
                    //
                    Assert.isTrue(groupNumbers.length() % INTERVAL == 0,
                            "Decoding encountered an numeric group with illegal length. The length must be a multiple of "
                                    + INTERVAL);

                    //
                    final String[] numberTokens = org.omnaest.utils.strings.StringUtils
                            .splitByInterval(groupNumbers, INTERVAL);
                    final byte[] byteTokens = org.apache.commons.lang3.ArrayUtils
                            .toPrimitive(ArrayUtils.convertArray(numberTokens, new Byte[numberTokens.length],
                                    elementConverterTokenToByte));

                    //
                    final String text = new String(byteTokens, CHARSET_UTF_8);
                    stringBuilder.append(text);
                } catch (Exception e) {
                    Assert.fails(e);
                }
            } else {
                Assert.fails("Decoding encountered an illegal character group: " + matcher.group());
            }
        }

    }

    // 
    return stringBuilder.toString();
}

From source file:org.openCage.gpad.FaustByteNum.java

@Override
public String encode(Byte ch, int idx) {
    if (pad == null) {
        throw new IllegalStateException("no pad yet");
    }//  ww  w . ja v  a 2s.c o m

    List<String> posi = num2line[xor(ch, getByte(idx)) - Byte.MIN_VALUE];
    return posi.get(((int) (Math.random() * posi.size())));
}

From source file:org.openCage.gpad.FaustByteNum.java

@Override
public Byte decode(String line, int idx) {
    if (pad == null) {
        throw new IllegalStateException("no pad yet");
    }//w  w w  . j  av a  2  s.  co m

    return xor((byte) ((line2num.get(line)) + Byte.MIN_VALUE), getByte(idx));
}

From source file:com.facebook.presto.operator.scalar.MathFunctions.java

@Description("absolute value")
@ScalarFunction("abs")
@SqlType(StandardTypes.TINYINT)// ww  w .jav  a  2s.c  om
public static long absTinyint(@SqlType(StandardTypes.TINYINT) long num) {
    checkCondition(num != Byte.MIN_VALUE, NUMERIC_VALUE_OUT_OF_RANGE,
            "Value -128 is out of range for abs(tinyint)");
    return Math.abs(num);
}

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  va  2s.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.voltdb.ClientResponseImpl.java

public void init(Long txn_id, long client_handle, int basePartition, Status status, VoltTable[] results,
        String statusString, SerializableException e) {
    this.init(txn_id, client_handle, basePartition, status, Byte.MIN_VALUE, null, results, statusString, e);
}

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  ww w  .  ja  v a  2s  . co  m*/
        return null;
    }

}

From source file:com.rapidminer.operator.preprocessing.filter.InfiniteValueReplenishment.java

/**
 * Replaces the values//  ww  w.  j  a  va  2 s .  c  o  m
 *
 * @throws UndefinedParameterError
 */
@Override
public double getReplenishmentValue(int functionIndex, ExampleSet exampleSet, Attribute attribute)
        throws UndefinedParameterError {
    int chosen = getParameterAsInt(PARAMETER_REPLENISHMENT_WHAT);
    switch (functionIndex) {
    case NONE:
        return Double.POSITIVE_INFINITY;
    case ZERO:
        return 0.0;
    case MAX_BYTE:
        return (chosen == 0) ? Byte.MAX_VALUE : Byte.MIN_VALUE;
    case MAX_INT:
        return (chosen == 0) ? Integer.MAX_VALUE : Integer.MIN_VALUE;
    case MAX_DOUBLE:
        return (chosen == 0) ? Double.MAX_VALUE : -Double.MAX_VALUE;
    case MISSING:
        return Double.NaN;
    case VALUE:
        return getParameterAsDouble(PARAMETER_REPLENISHMENT_VALUE);
    default:
        throw new RuntimeException("Illegal value functionIndex: " + functionIndex);
    }
}