Example usage for java.lang Byte parseByte

List of usage examples for java.lang Byte parseByte

Introduction

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

Prototype

public static byte parseByte(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal byte .

Usage

From source file:org.wikidata.wdtk.datamodel.json.jackson.datavalues.JacksonInnerTime.java

/**
 * Helper method to decompose the time string into its parts.
 *//*from  ww w.  j  a v  a2s  .com*/
private void decomposeTimeString() {
    // decompose the time string into its parts
    String[] substrings = time.split("(?<!\\A)[\\-\\:TZ]");

    // get the components of the date
    this.year = Long.parseLong(substrings[0]);
    this.month = Byte.parseByte(substrings[1]);
    this.day = Byte.parseByte(substrings[2]);
    this.hour = Byte.parseByte(substrings[3]);
    this.minute = Byte.parseByte(substrings[4]);
    this.second = Byte.parseByte(substrings[5]);
}

From source file:org.hachreak.projects.networkcodingsip2peer.utils.EncapsulatedEncodedFragment.java

public static byte[] decodeJSONArray2byte(JSONArray buffer) throws JSONException {
    byte[] output = new byte[buffer.length()];
    for (int i = 0; i < output.length; i++) {
        output[i] = Byte.parseByte(buffer.getString(i));
    }//from  w  w w.ja v a 2  s  . c  om
    return output;
}

From source file:org.romaframework.core.schema.SchemaClassElement.java

@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object convertValue(Object iFieldValue, SchemaClassDefinition expectedType) {
    if (expectedType == null || expectedType.getSchemaClass().isArray())
        return iFieldValue;

    SchemaClass typeClass = expectedType.getSchemaClass();
    if (typeClass.equals(Roma.schema().getSchemaClass(iFieldValue)))
        return iFieldValue;

    String textValue = null;/*from w w w .  j a  v  a2 s  .  c om*/
    if (iFieldValue instanceof String) {
        textValue = (String) iFieldValue;
    } else if (iFieldValue != null) {
        textValue = iFieldValue.toString();
    }

    Object value = null;

    if (textValue != null) {
        // TRY A SOFT CONVERSION
        if (typeClass.isOfType(Integer.class) || typeClass.isOfType(Integer.TYPE)) {
            try {
                value = textValue.equals("") ? null : Integer.parseInt(textValue);
            } catch (Exception e) {
                value = textValue.equals("") ? null : Double.valueOf(textValue).intValue();
            }
        } else if (typeClass.isOfType(Long.class) || typeClass.isOfType(Long.TYPE)) {
            value = textValue.equals("") ? null : Long.parseLong(textValue);
        } else if (typeClass.isOfType(Short.class) || typeClass.isOfType(Short.TYPE)) {
            value = textValue.equals("") ? null : Short.parseShort(textValue);
        } else if (typeClass.isOfType(Byte.class) || typeClass.isOfType(Byte.TYPE)) {
            value = textValue.equals("") ? null : Byte.parseByte(textValue);
        } else if (typeClass.isOfType(Character.class) || typeClass.isOfType(Character.TYPE)) {
            if (textValue.length() > 0) {
                value = new Character(textValue.charAt(0));
            }
        } else if (typeClass.isOfType(Float.class) || typeClass.isOfType(Float.TYPE)) {
            value = textValue.equals("") ? null : Float.parseFloat(textValue);
        } else if (typeClass.isOfType(Double.class) || typeClass.isOfType(Double.TYPE)) {
            value = textValue.equals("") ? null : Double.parseDouble(textValue);
        } else if (typeClass.isOfType(BigDecimal.class)) {
            value = textValue.equals("") ? null : new BigDecimal(textValue);
        } else if (iFieldValue != null && !typeClass.isArray() && iFieldValue.getClass().isArray()) {
            // DESTINATION VALUE IS NOT AN ARRAY: ASSIGN THE FIRST ONE ELEMENT
            value = ((Object[]) iFieldValue)[0];
        } else if (typeClass.isEnum()) {
            value = Enum.valueOf((Class) typeClass.getLanguageType(), textValue.toUpperCase());
        } else {
            value = iFieldValue;
        }
    }

    if (value != null) {
        // TODO is this the right place to do this...?
        Class<?> valueClass = value.getClass();
        // SUCH A MONSTER!!! MOVE THIS LOGIC IN SchemaClass.isAssignableFrom...
        if (value instanceof VirtualObject
                && !(typeClass.getLanguageType() instanceof Class<?>
                        && ((Class<?>) typeClass.getLanguageType()).isAssignableFrom(VirtualObject.class))
                && ((VirtualObject) value).getSuperClassObject() != null) {
            if (ComposedEntity.class
                    .isAssignableFrom(((VirtualObject) value).getSuperClassObject().getClass())) {
                value = ((VirtualObject) value).getSuperClassObject();
                valueClass = value.getClass();
            }
        }

        if (value instanceof ComposedEntity<?> && !typeClass.isAssignableFrom(valueClass)) {
            value = ((ComposedEntity<?>) value).getEntity();
        }
    }

    if (value == null && typeClass.isPrimitive()) {
        log.warn("Cannot set the field value to null for primitive types! Field: " + getEntity() + "." + name
                + " of class " + expectedType.getName() + ". Setting value to 0.");
        // SET THE VALUE TO 0
        value = SchemaHelper.assignDefaultValueToLiteral(typeClass);
    }
    return value;
}

From source file:com.bossletsplays.frost.utils.config.Configuration.java

public byte getByte(String option) {
    ObjectNode node = (ObjectNode) map.get(option);
    return Byte.parseByte(node.asText());
}

From source file:routines.system.BigDataParserUtils.java

public static Byte parseTo_Byte(String s, boolean isDecode) {
    if (isBlank(s)) {
        return null;
    }//from  w w  w  .  jav  a  2s  .  co  m
    if (isDecode) {
        return Byte.decode(s).byteValue();
    } else {
        return Byte.parseByte(s);
    }
}

From source file:com.ocdsoft.bacta.soe.json.schema.SoeDefaultRule.java

private JExpression getDefaultValue(JType fieldType, JsonNode node) {

    fieldType = fieldType.unboxify();/* w w w.  j  a v  a 2  s  . c om*/

    if (fieldType.fullName().equals(String.class.getName())) {
        return JExpr.lit(node.asText());

    } else if (fieldType.fullName().equals(int.class.getName())) {
        return JExpr.lit(Integer.parseInt(node.asText()));

    } else if (fieldType.fullName().equals(short.class.getName())) {
        return JExpr.lit(Short.parseShort(node.asText()));

    } else if (fieldType.fullName().equals(byte.class.getName())) {
        return JExpr.lit(Byte.parseByte(node.asText()));

    } else if (fieldType.fullName().equals(double.class.getName())) {
        return JExpr.lit(Double.parseDouble(node.asText()));

    } else if (fieldType.fullName().equals(boolean.class.getName())) {
        return JExpr.lit(Boolean.parseBoolean(node.asText()));

    } else if (fieldType.fullName().equals(getDateType().getName())) {
        long millisecs = parseDateToMillisecs(node.asText());

        JInvocation newDate = JExpr._new(fieldType);
        newDate.arg(JExpr.lit(millisecs));

        return newDate;

    } else if (fieldType.fullName().equals(long.class.getName())) {
        return JExpr.lit(Long.parseLong(node.asText()));

    } else if (fieldType.fullName().equals(float.class.getName())) {
        return JExpr.lit(Float.parseFloat(node.asText()));

    } else if (fieldType instanceof JDefinedClass
            && ((JDefinedClass) fieldType).getClassType().equals(ClassType.ENUM)) {

        return getDefaultEnum(fieldType, node);

    } else {
        return JExpr._null();

    }

}

From source file:savant.data.types.VCFVariantRecord.java

/**
 * Constructor not be be called directly, but rather through TabixIntervalRecord.valueOf.
 *//* w ww.j  a va  2 s.com*/
protected VCFVariantRecord(String line, ColumnMapping mapping) {
    super(line, mapping);

    // Storing all the string information is grossly inefficient, so we just parse what we
    // need and set the values to null.
    reference = super.getReference().intern();
    name = values[NAME_COLUMN].equals(".") ? null : values[NAME_COLUMN]; // VCF uses "." for missing value
    refBases = values[REF_COLUMN].intern();

    String altValue = values[ALT_COLUMN];
    if (altValue.startsWith("<")) {
        altBases = new String[] { altValue.intern() };
    } else {
        altBases = altValue.split(",");
        for (int i = 0; i < altBases.length; i++) {
            altBases[i] = altBases[i].intern();
        }
    }

    if (values.length > FIRST_PARTICIPANT_COLUMN) {
        participants0 = new byte[values.length - FIRST_PARTICIPANT_COLUMN];
        participants1 = new byte[values.length - FIRST_PARTICIPANT_COLUMN];
        for (int i = 0; i < participants0.length; i++) {
            String info = values[FIRST_PARTICIPANT_COLUMN + i];
            participants0[i] = MISSING;
            participants1[i] = MISSING;
            if (!info.equals(".")) {
                int colonPos = info.indexOf(':');
                if (colonPos >= 0) {
                    info = info.substring(0, colonPos);
                }

                phased &= info.indexOf('/') < 0;
                String[] alleleIndices = info.split("[|/]");
                if (!alleleIndices[0].equals(".")) {
                    participants0[i] = Byte.parseByte(alleleIndices[0]);
                }
                if (alleleIndices.length > 1 && !alleleIndices[1].equals(".")) {
                    participants1[i] = Byte.parseByte(alleleIndices[1]);
                }
            }
        }
    } else {
        // A defective VCF with no participants.
        participants0 = new byte[0];
        participants1 = new byte[0];
    }

    values = null;
}

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

/**    
 * {@inheritDoc}
 */
@Override
public Field setValueFromString(TimeZone timeZone, String s) {
    return setByte(Byte.parseByte(s));
}

From source file:com.pinterest.pinlater.client.PinLaterQueryIssuer.java

public PinLaterQueryIssuer(CommandLine cmdLine) {
    this.cmdLine = Preconditions.checkNotNull(cmdLine);
    this.mode = cmdLine.getOptionValue("mode");
    this.queueName = cmdLine.getOptionValue("queue", null);
    this.concurrency = Integer.parseInt(cmdLine.getOptionValue("concurrency", "1"));
    this.batchSize = Integer.parseInt(cmdLine.getOptionValue("batch_size", "1"));
    this.numQueries = Integer.parseInt(cmdLine.getOptionValue("num_queries", "1"));
    this.dequeueSuccessPercent = Integer.parseInt(cmdLine.getOptionValue("dequeue_success_percent", "100"));
    this.jobDescriptor = cmdLine.getOptionValue("job_descriptor", "");
    this.priority = Byte.parseByte(cmdLine.getOptionValue("priority", "1"));
    this.jobState = Integer.parseInt(cmdLine.getOptionValue("job_state", "0"));
    this.countFutureJobs = Boolean.parseBoolean(cmdLine.getOptionValue("count_future_jobs", "false"));
}

From source file:org.codehaus.groovy.grails.web.util.AbstractTypeConvertingMap.java

/**
 * Helper method for obtaining integer value from parameter
 * @param name The name of the parameter
 * @return The integer value or null if there isn't one
 *//*  ww  w .j a  v a  2s  .c o m*/
public Byte getByte(String name) {
    Object o = get(name);
    if (o instanceof Number) {
        return ((Number) o).byteValue();
    }

    if (o != null) {
        try {
            String string = o.toString();
            if (string != null && string.length() > 0) {
                return Byte.parseByte(string);
            }
        } catch (NumberFormatException e) {
        }
    }
    return null;
}