Example usage for java.lang Byte valueOf

List of usage examples for java.lang Byte valueOf

Introduction

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

Prototype

public static Byte valueOf(String s) throws NumberFormatException 

Source Link

Document

Returns a Byte object holding the value given by the specified String .

Usage

From source file:co.marcin.novaguilds.manager.ConfigManager.java

public byte getMaterialData(String path) {
    return Byte.valueOf(
            getString(path).contains(":") ? org.apache.commons.lang.StringUtils.split(getString(path), ':')[1]
                    : "0");
}

From source file:org.hellojavaer.testcase.generator.TestCaseGenerator.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private static <T> T produceBean(Class<T> clazz, ControlParam countrolParam, Stack<Class> parseClassList) {
    try {//  www.  ja v  a2 s  .  c  o m
        T item = clazz.newInstance();
        for (PropertyDescriptor pd : BeanUtils.getPropertyDescriptors(clazz)) {
            Method writeMethod = pd.getWriteMethod();
            if (writeMethod == null || pd.getReadMethod() == null || //
                    countrolParam.getExcludeFieldList() != null
                            && countrolParam.getExcludeFieldList().contains(pd.getName())//
            ) {//
                continue;
            }
            Class fieldClazz = pd.getPropertyType();
            Long numIndex = countrolParam.getNumIndex();
            // int enumIndex = countrolParam.getEnumIndex();
            Random random = countrolParam.getRandom();
            long strIndex = countrolParam.getStrIndex();
            int charIndex = countrolParam.getCharIndex();
            Calendar time = countrolParam.getTime();
            if (TypeUtil.isBaseType(fieldClazz)) {
                if (TypeUtil.isNumberType(fieldClazz)) {
                    if (fieldClazz == Byte.class) {
                        writeMethod.invoke(item, Byte.valueOf((byte) (numIndex & 0x7F)));
                    } else if (fieldClazz == Short.class) {
                        writeMethod.invoke(item, Short.valueOf((short) (numIndex & 0x7FFF)));
                    } else if (fieldClazz == Integer.class) {
                        writeMethod.invoke(item, Integer.valueOf((int) (numIndex & 0x7FFFFFFF)));
                    } else if (fieldClazz == Long.class) {
                        writeMethod.invoke(item, Long.valueOf((long) numIndex));
                    } else if (fieldClazz == Float.class) {
                        writeMethod.invoke(item, Float.valueOf((float) numIndex));
                    } else if (fieldClazz == Double.class) {
                        writeMethod.invoke(item, Double.valueOf((double) numIndex));
                    } else if (fieldClazz == byte.class) {//
                        writeMethod.invoke(item, (byte) (numIndex & 0x7F));
                    } else if (fieldClazz == short.class) {
                        writeMethod.invoke(item, (short) (numIndex & 0x7FFF));
                    } else if (fieldClazz == int.class) {
                        writeMethod.invoke(item, (int) (numIndex & 0x7FFFFFFF));
                    } else if (fieldClazz == long.class) {
                        writeMethod.invoke(item, (long) numIndex);
                    } else if (fieldClazz == float.class) {
                        writeMethod.invoke(item, (float) numIndex);
                    } else if (fieldClazz == double.class) {
                        writeMethod.invoke(item, (double) numIndex);
                    }
                    numIndex++;
                    if (numIndex < 0) {
                        numIndex &= 0x7FFFFFFFFFFFFFFFL;
                    }
                    countrolParam.setNumIndex(numIndex);
                } else if (fieldClazz == boolean.class) {
                    writeMethod.invoke(item, random.nextBoolean());
                } else if (fieldClazz == Boolean.class) {
                    writeMethod.invoke(item, Boolean.valueOf(random.nextBoolean()));
                } else if (fieldClazz == char.class) {
                    writeMethod.invoke(item, CHAR_RANGE[charIndex]);
                    charIndex++;
                    if (charIndex >= CHAR_RANGE.length) {
                        charIndex = 0;
                    }
                    countrolParam.setCharIndex(charIndex);
                } else if (fieldClazz == Character.class) {
                    writeMethod.invoke(item, Character.valueOf(CHAR_RANGE[charIndex]));
                    charIndex++;
                    if (charIndex >= CHAR_RANGE.length) {
                        charIndex = 0;
                    }
                    countrolParam.setCharIndex(charIndex);
                } else if (fieldClazz == String.class) {
                    if (countrolParam.getUniqueFieldList() != null
                            && countrolParam.getUniqueFieldList().contains(pd.getName())) {
                        StringBuilder sb = new StringBuilder();
                        convertNum(strIndex, STRING_RANGE, countrolParam.getRandom(), sb);
                        writeMethod.invoke(item, sb.toString());
                        strIndex += countrolParam.getStrStep();
                        if (strIndex < 0) {
                            strIndex &= 0x7FFFFFFFFFFFFFFFL;
                        }
                        countrolParam.setStrIndex(strIndex);
                    } else {
                        writeMethod.invoke(item, String.valueOf(CHAR_RANGE[charIndex]));
                        charIndex++;
                        if (charIndex >= CHAR_RANGE.length) {
                            charIndex = 0;
                        }
                        countrolParam.setCharIndex(charIndex);
                    }

                } else if (fieldClazz == Date.class) {
                    writeMethod.invoke(item, time.getTime());
                    time.add(Calendar.DAY_OF_YEAR, 1);
                } else if (fieldClazz.isEnum()) {
                    int index = random.nextInt(fieldClazz.getEnumConstants().length);
                    writeMethod.invoke(item, fieldClazz.getEnumConstants()[index]);
                } else {
                    //
                    throw new RuntimeException("out of countrol Class " + fieldClazz.getName());
                }
            } else {
                parseClassList.push(fieldClazz);
                // TODO ?
                Set<Class> set = new HashSet<Class>(parseClassList);
                if (parseClassList.size() - set.size() <= countrolParam.getRecursiveCycleLimit()) {
                    Object bean = produceBean(fieldClazz, countrolParam, parseClassList);
                    writeMethod.invoke(item, bean);
                }
                parseClassList.pop();
            }
        }
        return item;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.dataset.ByteDataset.java

@Override
public Object getObject(final int... pos) {
    return Byte.valueOf(get(pos)); // CLASS_TYPE
}

From source file:com.workday.autoparse.xml.demo.XmlParserTest.java

@Test
public void testMissingAttributesAreNotSet()
        throws ParseException, UnexpectedChildException, UnknownElementException {
    XmlStreamParser parser = XmlStreamParserFactory.newXmlStreamParser();
    InputStream in = getInputStreamOf("missing-attributes.xml");

    DemoModel model = (DemoModel) parser.parseStream(in);

    assertTrue(model.myBoxedBoolean);//from   ww  w . j  a  v  a 2 s.co m
    assertTrue(model.myPrimitiveBoolean);
    assertEquals(BigDecimal.ONE, model.myBigDecimal);
    assertEquals(BigInteger.TEN, model.myBigInteger);
    assertEquals(-1, model.myPrimitiveByte);
    assertEquals(Byte.valueOf((byte) -1), model.myBoxedByte);
    assertEquals('a', model.myPrimitiveChar);
    assertEquals(Character.valueOf('a'), model.myBoxedChar);
    assertEquals(-1.0, model.myPrimitiveDouble, DOUBLE_E);
    assertEquals(Double.valueOf(-1.0), model.myBoxedDouble);
    assertEquals(-1f, model.myPrimitiveFloat, FLOAT_E);
    assertEquals(Float.valueOf(-1f), model.myBoxedFloat);
    assertEquals(-1, model.myPrimitiveInt);
    assertEquals(Integer.valueOf(-1), model.myBoxedInt);
    assertEquals(-1, model.myPrimitiveLong);
    assertEquals(Long.valueOf(-1), model.myBoxedLong);
    assertEquals(-1, model.myPrimitiveShort);
    assertEquals(Short.valueOf((short) -1), model.myBoxedShort);
    assertEquals("default", model.myString);
    assertEquals("default", model.myTextContent);
}

From source file:de.blizzy.backup.backup.BackupRun.java

private int backupFolder(IFolder folder, int parentFolderId, String overrideName) throws IOException {
    currentFileOrFolder.add(folder);//from   ww  w  .  j  a v a2 s.  co m
    try {
        FileTime creationTime = folder.getCreationTime();
        FileTime lastModificationTime = folder.getLastModificationTime();
        database.factory().insertInto(Tables.ENTRIES)
                .set(Tables.ENTRIES.PARENT_ID, (parentFolderId > 0) ? Integer.valueOf(parentFolderId) : null)
                .set(Tables.ENTRIES.BACKUP_ID, Integer.valueOf(backupId))
                .set(Tables.ENTRIES.TYPE, Byte.valueOf((byte) EntryType.FOLDER.getValue()))
                .set(Tables.ENTRIES.CREATION_TIME,
                        (creationTime != null) ? new Timestamp(creationTime.toMillis()) : null)
                .set(Tables.ENTRIES.MODIFICATION_TIME,
                        (lastModificationTime != null) ? new Timestamp(lastModificationTime.toMillis()) : null)
                .set(Tables.ENTRIES.HIDDEN, Boolean.valueOf(folder.isHidden()))
                .set(Tables.ENTRIES.NAME,
                        StringUtils.isNotBlank(overrideName) ? overrideName : folder.getName())
                .set(Tables.ENTRIES.NAME_LOWER,
                        StringUtils.isNotBlank(overrideName) ? overrideName.toLowerCase()
                                : folder.getName().toLowerCase())
                .execute();
        int id = database.factory().lastID().intValue();
        List<IFileSystemEntry> entries = new ArrayList<>(folder.list());
        Collections.sort(entries, new Comparator<IFileSystemEntry>() {
            @Override
            public int compare(IFileSystemEntry e1, IFileSystemEntry e2) {
                return e1.getName().compareTo(e2.getName());
            }
        });
        for (IFileSystemEntry entry : entries) {
            if (!running) {
                break;
            }
            doPause();

            if (entry.isFolder()) {
                try {
                    backupFolder((IFolder) entry, id, null);
                } catch (IOException e) {
                    BackupPlugin.getDefault().logError("error while backing up folder: " + //$NON-NLS-1$
                            entry.getAbsolutePath(), e);
                    fireBackupErrorOccurred(e, BackupErrorEvent.Severity.ERROR);
                }
            } else {
                try {
                    backupFile((IFile) entry, id);
                } catch (IOException e) {
                    BackupPlugin.getDefault().logError("error while backing up file: " + //$NON-NLS-1$
                            entry.getAbsolutePath(), e);
                    fireBackupErrorOccurred(e, BackupErrorEvent.Severity.ERROR);
                }
            }
        }

        return id;
    } finally {
        currentFileOrFolder.remove(currentFileOrFolder.size() - 1);
    }
}

From source file:org.brekka.stillingar.spring.bpp.ConfigurationBeanPostProcessorTest.java

@Test
public void primitiveDefaultByte() {
    assertSame(ConfigurationBeanPostProcessor.primitiveDefault(Byte.TYPE), Byte.valueOf((byte) 0));
}

From source file:org.apache.hadoop.hive.ql.exec.SkewJoinHandler.java

private void commit() throws IOException {
    for (int bigKeyTbl = 0; bigKeyTbl < numAliases; bigKeyTbl++) {

        // if we did not see a skew key in this table, continue to next table
        // we are trying to avoid an extra call of FileSystem.exists()
        Boolean existing = bigKeysExistingMap.get(Byte.valueOf((byte) bigKeyTbl));
        if (existing == null || !existing) {
            continue;
        }/* w  w w. j  a  v a2s .  c o  m*/

        Path specPath = conf.getBigKeysDirMap().get(Byte.valueOf((byte) bigKeyTbl));
        commitOutputPathToFinalPath(specPath, false);
        for (int smallKeyTbl = 0; smallKeyTbl < numAliases; smallKeyTbl++) {
            if (smallKeyTbl == bigKeyTbl) {
                continue;
            }
            specPath = conf.getSmallKeysDirMap().get(Byte.valueOf((byte) bigKeyTbl))
                    .get(Byte.valueOf((byte) smallKeyTbl));
            // the file may not exist, and we just ignore this
            commitOutputPathToFinalPath(specPath, true);
        }
    }
}

From source file:org.eclipse.january.dataset.ByteDataset.java

@Override
public Object getObject() {
    return Byte.valueOf(get()); // CLASS_TYPE
}

From source file:org.objectstyle.cayenne.dataview.DataTypeSpec.java

public Object fromDataType(Class untypedValueClass, DataTypeEnum dataType, Object typedValue) {
    if (typedValue == null)
        return null;
    Class dataTypeClass = getJavaClass(dataType);
    //    Validate.isTrue(typedValue.getClass().equals(dataTypeClass));

    if (untypedValueClass == null)
        return typedValue;

    if (ClassUtils.isAssignable(dataTypeClass, untypedValueClass))
        return typedValue;

    String strTypedValue = null;/*from   w  w w.ja va  2 s. c om*/
    boolean isStringTypedValue;
    Number numTypedValue = null;
    boolean isNumberTypedValue;
    Boolean boolTypedValue = null;
    boolean isBooleanTypedValue;
    Date dateTypedValue = null;
    boolean isDateTypedValue;

    if (isStringTypedValue = typedValue instanceof String)
        strTypedValue = (String) typedValue;
    if (isNumberTypedValue = typedValue instanceof Number)
        numTypedValue = (Number) typedValue;
    if (isBooleanTypedValue = typedValue instanceof Boolean)
        boolTypedValue = (Boolean) typedValue;
    if (isDateTypedValue = typedValue instanceof Date)
        dateTypedValue = (Date) typedValue;

    Object v = null;
    if (String.class.equals(untypedValueClass)) {
        v = ObjectUtils.toString(typedValue);
    } else if (BigDecimal.class.equals(untypedValueClass)) {
        if (isStringTypedValue)
            v = NumberUtils.createBigDecimal(strTypedValue);
        else if (isNumberTypedValue)
            v = new BigDecimal(numTypedValue.doubleValue());
        else if (isBooleanTypedValue)
            v = new BigDecimal(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        else if (isDateTypedValue)
            v = new BigDecimal(dateTypedValue.getTime());
    } else if (Boolean.class.equals(untypedValueClass)) {
        if (isStringTypedValue)
            v = BooleanUtils.toBooleanObject(strTypedValue);
        else if (isNumberTypedValue)
            v = BooleanUtils.toBooleanObject(numTypedValue.intValue());
        else if (isDateTypedValue)
            v = BooleanUtils.toBooleanObject((int) dateTypedValue.getTime());
    } else if (Byte.class.equals(untypedValueClass)) {
        if (isStringTypedValue)
            v = Byte.valueOf(strTypedValue);
        else if (isNumberTypedValue)
            v = new Byte(numTypedValue.byteValue());
        else if (isBooleanTypedValue)
            v = new Byte((byte) BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        else if (isDateTypedValue)
            v = new Byte((byte) dateTypedValue.getTime());
    } else if (byte[].class.equals(untypedValueClass)) {
        if (isStringTypedValue)
            v = strTypedValue.getBytes();
    } else if (Double.class.equals(untypedValueClass)) {
        if (isStringTypedValue)
            v = NumberUtils.createDouble(strTypedValue);
        else if (isNumberTypedValue)
            v = new Double(numTypedValue.doubleValue());
        else if (isBooleanTypedValue)
            v = new Double(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        else if (isDateTypedValue)
            v = new Double(dateTypedValue.getTime());
    } else if (Float.class.equals(untypedValueClass)) {
        if (isStringTypedValue)
            v = NumberUtils.createFloat(strTypedValue);
        else if (isNumberTypedValue)
            v = new Float(numTypedValue.floatValue());
        else if (isBooleanTypedValue)
            v = new Float(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        else if (isDateTypedValue)
            v = new Float(dateTypedValue.getTime());
    } else if (Integer.class.equals(untypedValueClass)) {
        if (isStringTypedValue)
            v = NumberUtils.createInteger(strTypedValue);
        else if (isNumberTypedValue)
            v = new Integer(numTypedValue.intValue());
        else if (isBooleanTypedValue)
            v = BooleanUtils.toIntegerObject(boolTypedValue.booleanValue());
        else if (isDateTypedValue)
            v = new Integer((int) dateTypedValue.getTime());
    } else if (Long.class.equals(untypedValueClass)) {
        if (isStringTypedValue)
            v = NumberUtils.createLong(strTypedValue);
        else if (isNumberTypedValue)
            v = new Long(numTypedValue.longValue());
        else if (isBooleanTypedValue)
            v = new Long(BooleanUtils.toInteger(boolTypedValue.booleanValue()));
        else if (isDateTypedValue)
            v = new Long(dateTypedValue.getTime());
    } else if (java.sql.Date.class.equals(untypedValueClass)) {
        if (isNumberTypedValue)
            v = new java.sql.Date(numTypedValue.longValue());
        else if (isDateTypedValue)
            v = new java.sql.Date(dateTypedValue.getTime());
    } else if (java.sql.Time.class.equals(untypedValueClass)) {
        if (isNumberTypedValue)
            v = new java.sql.Time(numTypedValue.longValue());
        else if (isDateTypedValue)
            v = new java.sql.Time(dateTypedValue.getTime());
    } else if (java.sql.Timestamp.class.equals(untypedValueClass)) {
        if (isNumberTypedValue)
            v = new java.sql.Timestamp(numTypedValue.longValue());
        else if (isDateTypedValue)
            v = new java.sql.Timestamp(dateTypedValue.getTime());
    } else if (Date.class.equals(untypedValueClass)) {
        if (isNumberTypedValue)
            v = new Date(numTypedValue.longValue());
    }
    return v;
}

From source file:org.cloudata.core.common.io.CObjectWritable.java

/** Read a {@link CWritable}, {@link String}, primitive type, or an array of
 * the preceding. *//*from ww  w.  j  a  v  a2s. c om*/
@SuppressWarnings("unchecked")
public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf,
        boolean arrayComponent, Class componentClass) throws IOException {
    String className;
    if (arrayComponent) {
        className = componentClass.getName();
    } else {
        className = CUTF8.readString(in);
        //SANGCHUL
        //   System.out.println("SANGCHUL] className:" + className);
    }

    Class<?> declaredClass = PRIMITIVE_NAMES.get(className);
    if (declaredClass == null) {
        try {
            declaredClass = conf.getClassByName(className);
        } catch (ClassNotFoundException e) {
            //SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class[className=" + className + "]", e);
        }
    }

    Object instance;

    if (declaredClass.isPrimitive()) { // primitive types

        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }

    } else if (declaredClass.isArray()) { // array
        //System.out.println("SANGCHUL] is array");
        int length = in.readInt();
        //System.out.println("SANGCHUL] array length : " + length);
        //System.out.println("Read:in.readInt():" + length);
        if (declaredClass.getComponentType() == Byte.TYPE) {
            byte[] bytes = new byte[length];
            in.readFully(bytes);
            instance = bytes;
        } else if (declaredClass.getComponentType() == ColumnValue.class) {
            instance = readColumnValue(in, conf, declaredClass, length);
        } else {
            Class componentType = declaredClass.getComponentType();

            // SANGCHUL
            //System.out.println("SANGCHUL] componentType : " + componentType.getName());

            instance = Array.newInstance(componentType, length);
            for (int i = 0; i < length; i++) {
                Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(),
                        componentType);
                Array.set(instance, i, arrayComponentInstance);
                //Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass == String.class) { // String
        instance = CUTF8.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in));
    } else if (declaredClass == ColumnValue.class) {
        //ColumnValue?  ?? ?? ?  ? ?.
        //? ?   ? ? ? ? . 
        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            if (typeDiff == TYPE_DIFF) {
                instanceClass = conf.getClassByName(CUTF8.readString(in));
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("readObject can't find class", e);
        }
        ColumnValue columnValue = new ColumnValue();
        columnValue.readFields(in);
        instance = columnValue;
    } else { // Writable

        Class instanceClass = null;
        try {
            short typeDiff = in.readShort();
            // SANGCHUL
            //System.out.println("SANGCHUL] typeDiff : " + typeDiff);
            //System.out.println("Read:in.readShort():" + typeDiff);
            if (typeDiff == TYPE_DIFF) {
                // SANGCHUL
                String classNameTemp = CUTF8.readString(in);
                //System.out.println("SANGCHUL] typeDiff : " + classNameTemp);
                instanceClass = conf.getClassByName(classNameTemp);
                //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass());
            } else {
                instanceClass = declaredClass;
            }
        } catch (ClassNotFoundException e) {

            // SANGCHUL
            e.printStackTrace();
            throw new RuntimeException("readObject can't find class", e);
        }

        CWritable writable = CWritableFactories.newInstance(instanceClass, conf);
        writable.readFields(in);
        //System.out.println("Read:writable.readFields(in)");
        instance = writable;

        if (instanceClass == NullInstance.class) { // null
            declaredClass = ((NullInstance) instance).declaredClass;
            instance = null;
        }
    }

    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }

    return instance;
}