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:Main.java

/**
 * Returns the current hour of the day as set on the device.
 * @return// ww w  . ja v a 2  s  . co m
 */
public static int getHourOfDay() {
    SimpleDateFormat format = new SimpleDateFormat("H");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    return Byte.parseByte(format.format(new Date()));
}

From source file:Main.java

/**
 * Returns the current hour of the day as set on the device.
 * @return/*  w ww  . jav a  2s  . c  om*/
 */
public static int getMinuteOfDay() {
    SimpleDateFormat format = new SimpleDateFormat("m");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    return Byte.parseByte(format.format(new Date()));
}

From source file:Main.java

/**
 * //from w w w.  jav a  2 s .c  o  m
 * @param object
 * @return
 */
protected static Byte toByte(Object object) {
    String str = toString(object);
    if ("".equals(str))
        return 0;
    else
        return Byte.parseByte(str);
}

From source file:Main.java

/**
 * parse value to byte/*from   ww w .j  a va2 s.  c  o m*/
 */
public static byte toByte(String value) {
    return TextUtils.isEmpty(value) ? 0 : Byte.parseByte(value);
}

From source file:Main.java

/**
 * This method parses the given value into the specified primitive or wrapper class.
 * @param clazz - primitive or wrapper class used to parse
 * @param value - string to be parsed/*from w  w  w . j av  a2s.  com*/
 * @return object of type clazz parsed from the string
 * @author Trisan Bepler
 */
public static Object toObject(Class<?> clazz, String value) {
    if (Boolean.TYPE == clazz)
        return Boolean.parseBoolean(value);
    if (Byte.TYPE == clazz)
        return Byte.parseByte(value);
    if (Short.TYPE == clazz)
        return Short.parseShort(value);
    if (Integer.TYPE == clazz)
        return Integer.parseInt(value);
    if (Long.TYPE == clazz)
        return Long.parseLong(value);
    if (Float.TYPE == clazz)
        return Float.parseFloat(value);
    if (Double.TYPE == clazz)
        return Double.parseDouble(value);
    if (Boolean.class == clazz)
        return Boolean.parseBoolean(value);
    if (Byte.class == clazz)
        return Byte.parseByte(value);
    if (Short.class == clazz)
        return Short.parseShort(value);
    if (Integer.class == clazz)
        return Integer.parseInt(value);
    if (Long.class == clazz)
        return Long.parseLong(value);
    if (Float.class == clazz)
        return Float.parseFloat(value);
    if (Double.class == clazz)
        return Double.parseDouble(value);
    if (Character.class == clazz)
        return value.charAt(0);
    if (Character.TYPE == clazz)
        return value.charAt(0);
    return value;
}

From source file:Main.java

public static byte toByte(String value, byte defaultValue) {
    try {//from  w  w  w  . j a v  a  2s  . c  o  m
        return Byte.parseByte(value);
    } catch (Exception e) {
        return defaultValue;
    }
}

From source file:Main.java

/**
 * Parses the supplied xsd:byte string and returns its value.
 * //from  www .  j av  a  2s .com
 * @param s
 *        A string representation of an xsd:byte value.
 * @return The <tt>byte</tt> value represented by the supplied string argument.
 * @throws NumberFormatException
 *         If the supplied string is not a valid xsd:byte value.
 */
public static byte parseByte(String s) {
    s = trimPlusSign(s);
    return Byte.parseByte(s);
}

From source file:Main.java

/**
 * Converts the string representation of a hash to a byte array.
 *///from  w  ww  . j a v  a 2  s.  com
public static byte[] stringToHash(String hashString) {
    if (hashString.length() % 2 != 0) {
        throw new IllegalArgumentException("Hash must have even length");
    }
    int j = 0;
    byte[] hash = new byte[hashString.length() / 2];
    for (int i = 0; i < hashString.length(); i += 2) {
        hash[j++] = Byte.parseByte(hashString.substring(i, i + 2));
    }
    return hash;
}

From source file:Main.java

/**
 * Parses a netmask. This can either be in ip format (xxx.xxx.xxx.xxx)
 * or an int when using CIDR notation/*w  ww .j  av  a 2 s.c  o m*/
 * @param netmask
 * @return
 */
public static byte parseNetmaskToCidr(String netmask) {
    if (netmask.indexOf('.') == -1) { // CIDR notation
        try {
            byte val = Byte.parseByte(netmask);
            if (val >= 0) {
                return val;
            }
            throw new IllegalArgumentException("Invalid netmask: " + netmask);
        } catch (NumberFormatException exp) {
            throw new IllegalArgumentException("Invalid netmask: " + netmask);
        }
    } else {// simple ip notation
        return calculateCidr(parseDottedIpToInt(netmask));
    }
}

From source file:NetworkUtils.java

/**
 * check if IP address match pattern//from w  w  w  .ja  v a  2 s .  c o m
 * 
 * @param pattern
 *            *.*.*.* , 192.168.1.0-255 , *
 * @param address
 *            - 192.168.1.1<BR>
 *            <code>address = 10.2.88.12  pattern = *.*.*.*   result: true<BR>
 *                address = 10.2.88.12  pattern = *   result: true<BR>
 *                address = 10.2.88.12  pattern = 10.2.88.12-13   result: true<BR>
 *                address = 10.2.88.12  pattern = 10.2.88.13-125   result: false<BR></code>
 * @return true if address match pattern
 */
public static boolean checkIPMatching(String pattern, String address) {
    if (pattern.equals("*.*.*.*") || pattern.equals("*"))
        return true;

    String[] mask = pattern.split("\\.");
    String[] ip_address = address.split("\\.");
    for (int i = 0; i < mask.length; i++) {
        if (mask[i].equals("*") || mask[i].equals(ip_address[i]))
            continue;
        else if (mask[i].contains("-")) {
            byte min = Byte.parseByte(mask[i].split("-")[0]);
            byte max = Byte.parseByte(mask[i].split("-")[1]);
            byte ip = Byte.parseByte(ip_address[i]);
            if (ip < min || ip > max)
                return false;
        } else
            return false;
    }
    return true;
}