Example usage for java.lang Long parseLong

List of usage examples for java.lang Long parseLong

Introduction

In this page you can find the example usage for java.lang Long parseLong.

Prototype

public static long parseLong(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal long .

Usage

From source file:org.shredzone.cilla.web.converter.StringToPage.java

@Override
public Page convert(String string) {
    try {//from  w ww  . j  av  a2 s  .  c  o m
        return pageDao.fetch(Long.parseLong(string));
    } catch (NumberFormatException ex) {
        return pageDao.fetchByName(string);
    }
}

From source file:org.shredzone.cilla.web.converter.StringToUser.java

@Override
public User convert(String string) {
    try {/*from w ww  .  jav a 2s. c  o m*/
        return userDao.fetch(Long.parseLong(string));
    } catch (NumberFormatException ex) {
        return null;
    }
}

From source file:org.jspringbot.keyword.ssh.ExecuteWhileOutputIsNot.java

@Override
public Object execute(Object[] params) {
    try {/* w ww .j a va  2 s .  c  om*/
        helper.executeWhileOutputIsNot(String.valueOf(params[0]), String.valueOf(params[1]),
                Long.parseLong(String.valueOf(params[2])), Long.parseLong((String) params[3]));
    } catch (InterruptedException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }

    return null;
}

From source file:fr.mycellar.interfaces.web.services.FilterCouple.java

/**
 * Default constructor.//ww w. j  a va 2 s .co  m
 * 
 * @param couple
 */
public FilterCouple(String couple) {
    property = couple.substring(0, couple.indexOf(","));
    String value = couple.substring(couple.indexOf(",") + 1);
    Object result = null;
    try {
        result = Long.parseLong(value);
    } catch (Exception e) {
    }
    if (result == null) {
        try {
            result = Double.parseDouble(value);
        } catch (Exception e) {
        }
    }
    if (result == null) {
        try {
            result = LocalDateTime.parse(value);
        } catch (Exception e) {
        }
    }
    if (result == null) {
        result = value;
    }
    filter = result;
}

From source file:com.inkubator.hrm.web.converter.CityConverter.java

@Override
public Object getAsObject(FacesContext contet, UIComponent component, String value) {
    CityService cityService = (CityService) ServiceWebUtil.getService("cityService");
    if (!StringUtils.isNumeric(value)) {
        return null;
    }//  w  w w .  ja va  2  s  .  c  o m
    Object object = null;
    try {
        Long id = Long.parseLong(value);
        object = cityService.getEntiyByPK(id);
        //            City city = cityService.getEntiyByPK(id);
        return object;
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Input tidak valid", ""));
    }
}

From source file:com.lightboxtechnologies.nsrl.HashRecordProcessor.java

public HashData process(String[] col) throws BadDataException {
    if (col.length < 8) {
        throw new BadDataException("too few columns");
    } else if (col.length > 8) {
        throw new BadDataException("too many columns");
    }/*from  www .j a  va 2  s.c  om*/

    long size = 0;
    try {
        size = Long.parseLong(col[4]);
    } catch (NumberFormatException e) {
        throw new BadDataException(e);
    }

    if (size < 0) {
        throw new BadDataException("size < 0");
    }

    int prod_code = 0;
    try {
        prod_code = Integer.parseInt(col[5]);
    } catch (NumberFormatException e) {
        throw new BadDataException(e);
    }

    if (prod_code < 0) {
        throw new BadDataException("prod_code < 0");
    }

    byte[] sha1, md5, crc32;
    try {
        sha1 = (byte[]) hex.decode(col[0]);
        md5 = (byte[]) hex.decode(col[1]);
        crc32 = (byte[]) hex.decode(col[2]);
    } catch (DecoderException e) {
        throw new BadDataException(e);
    }

    return new HashData(sha1, md5, crc32, col[3], size, prod_code, col[6], col[7]);
}

From source file:com.mobilewallet.services.UserProfileService.java

@GET
@Produces(MediaType.APPLICATION_JSON)/* w  w  w.  java2 s.co  m*/
public Object profile(@QueryParam("id") String eid) {

    String decryptedUserId = MobileWalletID.getDecryptedUserId(eid);
    String userId = null;

    if (decryptedUserId != null) {
        try {
            userId = decryptedUserId.replace(Config.USER_ENCRYPTED_EXTENSION, "");
        } catch (Exception ex) {

        }
    }
    log.info("UserId : " + userId);
    if (userId != null) {

        return UserBO.userProfile(Long.parseLong(userId));
    }

    return new LoginBean();
}

From source file:IPAddressUtil.java

public static byte[] textToNumericFormatV4(String src) {
    if (src.length() == 0) {
        return null;
    }//from   w ww .  j av a  2s.c  o m

    byte[] res = new byte[INADDR4SZ];
    String[] s = src.split("\\.", -1);
    long val;
    try {
        switch (s.length) {
        case 1:
            /*
             * When only one part is given, the value is stored directly in
             * the network address without any byte rearrangement.
             */

            val = Long.parseLong(s[0]);
            if (val < 0 || val > 0xffffffffL)
                return null;
            res[0] = (byte) ((val >> 24) & 0xff);
            res[1] = (byte) (((val & 0xffffff) >> 16) & 0xff);
            res[2] = (byte) (((val & 0xffff) >> 8) & 0xff);
            res[3] = (byte) (val & 0xff);
            break;
        case 2:
            /*
             * When a two part address is supplied, the last part is
             * interpreted as a 24-bit quantity and placed in the right
             * most three bytes of the network address. This makes the
             * two part address format convenient for specifying Class A
             * network addresses as net.host.
             */

            val = Integer.parseInt(s[0]);
            if (val < 0 || val > 0xff)
                return null;
            res[0] = (byte) (val & 0xff);
            val = Integer.parseInt(s[1]);
            if (val < 0 || val > 0xffffff)
                return null;
            res[1] = (byte) ((val >> 16) & 0xff);
            res[2] = (byte) (((val & 0xffff) >> 8) & 0xff);
            res[3] = (byte) (val & 0xff);
            break;
        case 3:
            /*
             * When a three part address is specified, the last part is
             * interpreted as a 16-bit quantity and placed in the right
             * most two bytes of the network address. This makes the
             * three part address format convenient for specifying
             * Class B net- work addresses as 128.net.host.
             */
            for (int i = 0; i < 2; i++) {
                val = Integer.parseInt(s[i]);
                if (val < 0 || val > 0xff)
                    return null;
                res[i] = (byte) (val & 0xff);
            }
            val = Integer.parseInt(s[2]);
            if (val < 0 || val > 0xffff)
                return null;
            res[2] = (byte) ((val >> 8) & 0xff);
            res[3] = (byte) (val & 0xff);
            break;
        case 4:
            /*
             * When four parts are specified, each is interpreted as a
             * byte of data and assigned, from left to right, to the
             * four bytes of an IPv4 address.
             */
            for (int i = 0; i < 4; i++) {
                val = Integer.parseInt(s[i]);
                if (val < 0 || val > 0xff)
                    return null;
                res[i] = (byte) (val & 0xff);
            }
            break;
        default:
            return null;
        }
    } catch (NumberFormatException e) {
        return null;
    }
    return res;
}

From source file:com.taobao.adfs.database.tdhsocket.client.util.ConvertUtil.java

public static byte getByteFromString(String stringVal) throws SQLException {

    if (StringUtils.isBlank(stringVal)) {
        return (byte) 0;
    }//  w  w w . j  a  v a  2 s.  com
    stringVal = stringVal.trim();

    try {
        int decimalIndex = stringVal.indexOf(".");

        if (decimalIndex != -1) {
            double valueAsDouble = Double.parseDouble(stringVal);
            return (byte) valueAsDouble;
        }

        long valueAsLong = Long.parseLong(stringVal);

        return (byte) valueAsLong;
    } catch (NumberFormatException NFE) {
        throw new SQLException("Parse byte value error:" + stringVal);
    }
}

From source file:info.archinnov.achilles.json.CounterDeserializer.java

@Override
public Counter deserialize(JsonParser parser, DeserializationContext context) throws IOException {

    Counter counter = null;// w ww  .ja  va2  s.c om
    String value = parser.getText();
    if (value != null && !"".equals(value.trim())) {
        try {
            counter = CounterBuilder.incr(Long.parseLong(value));
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Cannot deserialize '" + value + "' as Long for Counter ");
        }
    }
    return counter;
}