Example usage for java.lang Byte MAX_VALUE

List of usage examples for java.lang Byte MAX_VALUE

Introduction

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

Prototype

byte MAX_VALUE

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

Click Source Link

Document

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

Usage

From source file:NumberUtils.java

/**
 * Convert the given number into an instance of the given target class.
 * @param number the number to convert//from  w ww.  j av  a 2 s. co  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:mil.jpeojtrs.sca.util.tests.AnyUtilsTest.java

@Test
public void test_convertString() throws Exception {
    this.value = "true";
    this.type = "boolean";

    final Boolean result = (Boolean) AnyUtils.convertString(this.value, this.type);
    Assert.assertTrue(result);/*ww w.  j av  a  2s. c om*/

    Assert.assertNull(AnyUtils.convertString(null, this.type));
    Object val = AnyUtils.convertString("REDHAWK", "string");
    Assert.assertTrue(val instanceof String);
    Assert.assertEquals("REDHAWK", (String) val);
    val = AnyUtils.convertString("KWAHDER", "wstring");
    Assert.assertTrue(val instanceof String);
    Assert.assertEquals("KWAHDER", (String) val);
    val = AnyUtils.convertString("K", "char");
    Assert.assertTrue(val instanceof Character);
    Assert.assertEquals('K', ((Character) val).charValue());
    val = AnyUtils.convertString("H", "wchar");
    Assert.assertTrue(val instanceof Character);
    Assert.assertEquals('H', ((Character) val).charValue());
    val = AnyUtils.convertString("1.0", "double");
    Assert.assertTrue(val instanceof Double);
    Assert.assertEquals(1.0, val);
    val = AnyUtils.convertString("1.0", "float");
    Assert.assertTrue(val instanceof Float);
    Assert.assertEquals(1.0F, val);
    val = AnyUtils.convertString("2", "short");
    Assert.assertTrue(val instanceof Short);
    Assert.assertEquals((short) 2, ((Short) val).shortValue());
    val = AnyUtils.convertString("4", "ushort");
    Assert.assertTrue(val instanceof Integer);
    Assert.assertEquals(4, ((Integer) val).intValue());
    val = AnyUtils.convertString(Integer.MAX_VALUE + "", "long");
    Assert.assertTrue(val instanceof Integer);
    Assert.assertEquals(Integer.MAX_VALUE, ((Integer) val).intValue());
    val = AnyUtils.convertString(Long.valueOf(2L * Integer.MAX_VALUE + 1L).toString(), "ulong");
    Assert.assertTrue(val instanceof Long);
    Assert.assertEquals(2L * Integer.MAX_VALUE + 1L, ((Long) val).longValue());
    val = AnyUtils.convertString(Long.MAX_VALUE + "", "longlong");
    Assert.assertTrue(val instanceof Long);
    Assert.assertEquals(Long.MAX_VALUE, ((Long) val).longValue());
    val = AnyUtils.convertString(Long.MAX_VALUE + "", "ulonglong");
    Assert.assertTrue(val instanceof BigInteger);
    Assert.assertEquals(Long.MAX_VALUE, ((BigInteger) val).longValue());
    val = AnyUtils.convertString(Byte.MAX_VALUE + "", "octet");
    Assert.assertTrue(val instanceof Short);
    Assert.assertEquals(Byte.MAX_VALUE, ((Short) val).byteValue());
}

From source file:com.alvermont.terraj.fracplanet.colour.ByteRGBA.java

/**
 * Creates a new instance of ByteRGBA using the values stored in a FloatRGBA
 *
 * @param c The FloatRGBA object that will be used to initialize this one
 *//* ww  w.  ja va2s  . co  m*/
public ByteRGBA(FloatRGBA c) {
    this((byte) (Byte.MAX_VALUE * c.getR()), (byte) (Byte.MAX_VALUE * c.getG()),
            (byte) (Byte.MAX_VALUE * c.getB()), (byte) (Byte.MAX_VALUE * c.getA()));
}

From source file:Base64.java

/**
 * Decode the base64 data./*from w w w.  java2s  .  c  om*/
 * @param data The base64 encoded data to be decoded
 * @param ostream The OutputStream to which the decoded data should be
 *                written
 */
public static void decode(String data, OutputStream ostream) throws IOException {
    char[] ibuf = new char[BUF_SIZE + 4];
    byte[] obuf = new byte[3];
    int slen = data.length();
    int blen;
    int ibufcount = 0;

    for (int i = 0; i < slen; i += BUF_SIZE) {
        // buffer may contain unprocessed characters from previous step
        if (i + BUF_SIZE <= slen) {
            data.getChars(i, i + BUF_SIZE, ibuf, ibufcount);
            blen = BUF_SIZE + ibufcount;
        } else {
            data.getChars(i, slen, ibuf, ibufcount);
            blen = slen - i + ibufcount;
        }

        for (int j = ibufcount; j < blen; j++) {
            char ch = ibuf[j];
            if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
                ibuf[ibufcount++] = ch;

                // as sson as we have 4 chars process them
                if (ibufcount == 4) {
                    ibufcount = 0;
                    int obufcount = decode0(ibuf, obuf, 0);
                    ostream.write(obuf, 0, obufcount);
                }
            }
        }
    }
}

From source file:hivemall.LearnerBaseUDTF.java

@Nullable
@Override/*from  ww  w .  j  av  a 2s .co  m*/
protected CommandLine processOptions(@Nonnull ObjectInspector[] argOIs) throws UDFArgumentException {
    String modelfile = null;
    boolean denseModel = false;
    int modelDims = -1;
    boolean disableHalfFloat = false;
    int miniBatchSize = 1;
    String mixConnectInfo = null;
    String mixSessionName = null;
    int mixThreshold = -1;
    boolean mixCancel = false;
    boolean ssl = false;

    CommandLine cl = null;
    if (argOIs.length >= 3) {
        String rawArgs = HiveUtils.getConstString(argOIs[2]);
        cl = parseOptions(rawArgs);

        modelfile = cl.getOptionValue("loadmodel");

        denseModel = cl.hasOption("dense");
        if (denseModel) {
            modelDims = Primitives.parseInt(cl.getOptionValue("dims"), 16777216);
        }
        disableHalfFloat = cl.hasOption("disable_halffloat");

        miniBatchSize = Primitives.parseInt(cl.getOptionValue("mini_batch_size"), miniBatchSize);
        if (miniBatchSize <= 0) {
            throw new UDFArgumentException("mini_batch_size must be greater than 0: " + miniBatchSize);
        }

        mixConnectInfo = cl.getOptionValue("mix");
        mixSessionName = cl.getOptionValue("mix_session");
        mixThreshold = Primitives.parseInt(cl.getOptionValue("mix_threshold"), 3);
        if (mixThreshold > Byte.MAX_VALUE) {
            throw new UDFArgumentException("mix_threshold must be in range (0,127]: " + mixThreshold);
        }
        mixCancel = cl.hasOption("mix_cancel");
        ssl = cl.hasOption("ssl");
    }

    this.preloadedModelFile = modelfile;
    this.dense_model = denseModel;
    this.model_dims = modelDims;
    this.disable_halffloat = disableHalfFloat;
    this.is_mini_batch = miniBatchSize > 1;
    this.mini_batch_size = miniBatchSize;
    this.mixConnectInfo = mixConnectInfo;
    this.mixSessionName = mixSessionName;
    this.mixThreshold = mixThreshold;
    this.mixCancel = mixCancel;
    this.ssl = ssl;
    return cl;
}

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

/**
 * Used to fill a gap where a maximum value isn't specified in a range.
 * @param val - the current value, if there is one.
 * @param inputType - the input data type that the maximum should fit within
 * /*ww  w  .  j av a 2s  .  co m*/
 * @return - the original value if it exists, or the maximum value allowed within
 * the inputType specified.
 */
public static String getCountMax(String val, String inputType) {
    String result = val;
    if (result == null || result.isEmpty()) {
        if (inputType.equals("byte") || inputType.equals("int8")) {
            result = Byte.toString(Byte.MAX_VALUE);
        } else if (inputType.equals("short integer") || inputType.equals("int16")) {
            result = Short.toString(Short.MAX_VALUE);
        } else if (inputType.equals("integer") || inputType.equals("int32")) {
            result = Integer.toString(Integer.MAX_VALUE);
        } else if (inputType.equals("long integer") || inputType.equals("int64")) {
            result = Long.toString(Long.MAX_VALUE);
        } else if (inputType.equals("unsigned byte") || inputType.equals("uint8")) {
            result = Short.toString((short) (Byte.MAX_VALUE * 2 + 1));
        } else if (inputType.equals("unsigned short integer") || inputType.equals("uint16")) {
            result = Integer.toString((int) (Short.MAX_VALUE * 2 + 1));
        } else if (inputType.equals("unsigned integer") || inputType.equals("uint32")) {
            result = Long.toString((long) (Integer.MAX_VALUE * 2 + 1));
        } else if (inputType.equals("unsigned long integer") || inputType.equals("uint64")) {
            result = "18446744073709551615";
        } else if (inputType.equals("float") || inputType.equals("float")) {
            result = Float.toString(Float.MAX_VALUE);
        } else if (inputType.equals("long float") || inputType.equals("double")) {
            result = Double.toString(Double.MAX_VALUE);
        }
    }

    return result;
}

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  ww  w.j  a v  a2s .com

    // 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:it.unipmn.di.dcs.common.conversion.Base64.java

/**
 * Decode a Base64 data./*from w w w. jav  a 2s.  c o m*/
 *
 * Original method name is <em>decode</em>.
 */
public static void Decode(String data, OutputStream ostream) throws IOException {
    char[] ibuf = new char[4];
    int ibufcount = 0;
    byte[] obuf = new byte[3];
    for (int i = 0; i < data.length(); i++) {
        char ch = data.charAt(i);
        if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
            ibuf[ibufcount++] = ch;
            if (ibufcount == ibuf.length) {
                ibufcount = 0;
                int obufcount = Decode0(ibuf, obuf, 0);
                ostream.write(obuf, 0, obufcount);
            }
        }
    }
}

From source file:io.horizondb.model.core.fields.DecimalField.java

/**
 * {@inheritDoc}/*from  ww w. j  a  v a2 s.  com*/
 */
@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.
 *//* w  w w.  j  a va 2 s  .  co  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;
}