Example usage for java.lang Long valueOf

List of usage examples for java.lang Long valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Long valueOf(long l) 

Source Link

Document

Returns a Long instance representing the specified long value.

Usage

From source file:com.multimedia.service.locale.CmsLocaleServiceImpl.java

@Override
public Locale getInsertBean(Locale obj) {
    if (obj == null)
        obj = new Locale();
    Long sort = (Long) service.getSinglePropertyU("max(sort)");
    if (sort == null)
        sort = Long.valueOf(0);
    else//from  w  ww.  j a va 2  s  . c o  m
        sort++;
    obj.setSort(sort);
    obj.setActive(Boolean.TRUE);
    return obj;
}

From source file:me.repository.menu.MenuDao.java

public List<Menu> findNodes(String id) {

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Menu.class);
    detachedCriteria.add(Restrictions.eq("parentId", Long.valueOf(id))).addOrder(Order.asc("sort"));
    return find(detachedCriteria);
}

From source file:com.scvngr.levelup.core.model.util.JsonUtilsTest.java

/**
 * Tests {@link JsonUtils#optLongNullable}.
 *///  w  ww  .  j  a  v  a2s.com
@SmallTest
public void testOptLongNullable() throws JSONException {
    final JSONObject object = new JSONObject();
    object.put("test_literal", 1L);
    object.put("test_object", Long.valueOf(1L));
    object.put("test_null", null);

    final Long literal = JsonUtils.optLongNullable(object, "test_literal");
    assertNotNull(literal);
    assertEquals(1L, literal.longValue());

    assertEquals(Long.valueOf(1L), JsonUtils.optLongNullable(object, "test_object"));
    assertNull(JsonUtils.optLongNullable(object, "test_null"));
    assertNull(JsonUtils.optLongNullable(object, "test_key_not_found"));
}

From source file:com.hp.alm.ali.idea.model.type.FileSizeType.java

@Override
public String translate(String value, ValueCallback callback) {
    return FileUtils.byteCountToDisplaySize(Long.valueOf(value));
}

From source file:com.jaspersoft.jasperserver.war.cascade.handlers.converters.LongDataConverter.java

@Override
public Long stringToValue(String rawData) throws JSValidationException {
    return StringUtils.isNotEmpty(rawData) ? Long.valueOf(rawData) : null;
}

From source file:csns.web.editor.CoursePropertyEditor.java

@Override
public void setAsText(String text) throws IllegalArgumentException {
    if (StringUtils.hasText(text))
        setValue(courseDao.getCourse(Long.valueOf(text)));
}

From source file:com.snapdeal.scm.fh.service.impl.ConvertorService.java

@SuppressWarnings("unchecked")
@Override/*from w w w  .ja  v  a  2  s.c o  m*/
public <T> T convertToObject(Class<T> clazz, String value) throws ParseException {
    if (StringUtils.isEmpty(value) || StringUtils.NULL.equalsIgnoreCase(value)) {
        return null;
    }
    if (clazz.equals(Integer.class)) {
        return (T) Integer.valueOf(value);
    }
    if (clazz.equals(Date.class)) {
        try {
            return (T) new Date(Long.valueOf(value));
        } catch (NumberFormatException ne) {
            return (T) DateUtils.parseDate(value, ALLOWED_DATE_FORMATS);
        }
    }
    if (clazz.equals(String.class)) {
        return (T) value;
    }
    if (clazz.equals(Float.class)) {
        return (T) Float.valueOf(value);
    }
    if (clazz.equals(Double.class)) {
        return (T) Double.valueOf(value);
    }
    if (clazz.equals(Boolean.class)) {
        if (value.equals("1") || value.equalsIgnoreCase("true")) {
            return (T) Boolean.TRUE;
        } else if (value.equals("0") || value.equalsIgnoreCase("false")) {
            return (T) Boolean.FALSE;
        }
    }
    throw new ParseException("unable to parse string [" + value + "] to class " + clazz, 0);
}

From source file:com.redhat.rhn.common.security.acl.KickstartAclHandler.java

private KickstartData getKickstart(User usr, String[] params) {
    String ksStr = params[0];//from  w w  w. j  av a 2  s  .  co  m
    Long id = null;
    try {
        id = Long.valueOf(ksStr);
    } catch (NumberFormatException nfe) {
        return null;
    }

    if (id != null) {
        KickstartData ks = KickstartFactory.lookupKickstartDataByIdAndOrg(usr.getOrg(), id);
        return ks;
    }
    return null;
}

From source file:cn.sixlab.sixutil.StrUtil.java

/**
 * ?// w  w  w. ja v a 2s .c  o  m
 *
 * @param str ?
 * @return {@code str}true {@code str}?false
 */
public static Boolean isNaturalNumber(String str) {
    try {
        long value = Long.valueOf(str);
        if (value >= 0) {
            return true;
        }
        return false;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

/**
 * parse a string to an Object of given data type. <br>
 * @param strValue the string value/*w  w  w . j  a  v  a2 s.  c o  m*/
 * @param valueType the full java class name which could be <br>
 * java.util.Date   (default format is yyyy-MM-dd) <br>
 * java.sql.Date   (default format is yyyy-MM-dd) <br>
 * java.sql.Timestamp   (default format is yyyy-MM-dd HH:mm:ss) <br>
 * java.sql.Time   (default format is HH:mm:ss) <br>
 * java.lang.String   <br>
 * java.lang.Boolean   <br>
 * java.lang.Double   <br>
 * java.lang.Long   <br>
 * java.lang.Short   <br>
 * java.lang.Integer   <br>
 * java.lang.Byte   <br>
 * java.lang.Float   <br>
 * java.math.BigInteger   <br>
 * java.math.BigDecimal   <br>
 * 
 * @param format SimpleDateFormat allowed standard formats.
 * @return Object
 * @throws Exception
 */
public static Object parseStringToObject(String strValue, String valueType, String format) throws Exception {
    if ("java.util.Date".equals(valueType)) {
        // default format yyyy-MM-dd
        SimpleDateFormat fmt = new SimpleDateFormat(format != null ? format : "yyyy-MM-dd");
        return (fmt.parse(strValue));
    } else if ("java.sql.Date".equals(valueType)) {
        // default format yyyy-MM-dd
        SimpleDateFormat fmt = new SimpleDateFormat(format != null ? format : "yyyy-MM-dd");
        return (new java.sql.Date(fmt.parse(strValue).getTime()));
    } else if ("java.sql.Timestamp".equals(valueType)) {
        // default format yyyy-MM-dd HH:mm:ss
        SimpleDateFormat fmt = new SimpleDateFormat(format != null ? format : "yyyy-MM-dd HH:mm:ss");
        return (new java.sql.Timestamp(fmt.parse(strValue).getTime()));
    } else if ("java.sql.Time".equals(valueType)) {
        // default format HH:mm:ss
        SimpleDateFormat fmt = new SimpleDateFormat(format != null ? format : "HH:mm:ss");
        return (new java.sql.Time(fmt.parse(strValue).getTime()));
    } else if ("java.lang.Boolean".equals(valueType)) {
        return (Boolean.valueOf(strValue));
    } else if ("java.lang.Double".equals(valueType)) {
        return (Double.valueOf(strValue));
    } else if ("java.lang.Long".equals(valueType)) {
        return (Long.valueOf(strValue));
    } else if ("java.lang.Short".equals(valueType)) {
        return (Short.valueOf(strValue));
    } else if ("java.lang.Integer".equals(valueType)) {
        return (Integer.valueOf(strValue));
    } else if ("java.lang.Byte".equals(valueType)) {
        return (Byte.valueOf(strValue));
    } else if ("java.lang.Float".equals(valueType)) {
        return (Float.valueOf(strValue));
    } else if ("java.math.BigInteger".equals(valueType)) {
        return (new java.math.BigInteger(strValue));
    } else if ("java.math.BigDecimal".equals(valueType)) {
        return (new java.math.BigDecimal(strValue));
    } else {
        return (strValue);
    }
}