Example usage for java.lang Number longValue

List of usage examples for java.lang Number longValue

Introduction

In this page you can find the example usage for java.lang Number longValue.

Prototype

public abstract long longValue();

Source Link

Document

Returns the value of the specified number as a long .

Usage

From source file:org.codehaus.griffon.runtime.quartz.CustomTriggerFactoryBean.java

public void afterPropertiesSet() throws ParseException {
    customTrigger = BeanUtils.instantiateClass(triggerClass);

    if (triggerAttributes.containsKey(QuartzConstants.START_DELAY)) {
        Number startDelay = (Number) triggerAttributes.remove(QuartzConstants.START_DELAY);
        customTrigger.setStartTime(new Date(System.currentTimeMillis() + startDelay.longValue()));
    }//from w w w .  j ava  2 s  . c  om

    if (jobDetail != null) {
        customTrigger.setJobName(jobDetail.getName());
        customTrigger.setJobGroup(jobDetail.getGroup());
    }

    BeanWrapper customTriggerWrapper = PropertyAccessorFactory.forBeanPropertyAccess(customTrigger);
    customTriggerWrapper.registerCustomEditor(String.class, new StringEditor());
    customTriggerWrapper.setPropertyValues(triggerAttributes);
}

From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCPhotographerDAO.java

@Override
public Photographer create(Photographer photographer) throws DAOException, ValidationException {
    logger.debug("Creating photographer {}", photographer);

    PhotographerValidator.validate(photographer);

    try {/*from  w w w  .  j  ava  2s  .c o  m*/
        Map<String, Object> parameters = new HashMap<>(1);
        parameters.put("name", photographer.getName());
        Number newId = insertPhotographer.executeAndReturnKey(parameters);
        photographer.setId((int) newId.longValue());

        addedCallbacks.forEach(cb -> cb.accept(photographer));

        return photographer;
    } catch (DataAccessException ex) {
        logger.error("Failed to create photographer", ex);
        throw new DAOException("Failed to create photographer", ex);
    }
}

From source file:com.redhat.lightblue.crud.validator.MinMaxChecker.java

private int cmp(JsonNode node, Number value) {
    if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
        return cmp(node.asLong(), value.longValue());
    } else if (value instanceof Float || value instanceof Double) {
        return cmp(node.asDouble(), value.doubleValue());
    } else if (value instanceof BigInteger) {
        return cmp(node.bigIntegerValue(), (BigInteger) value);
    } else {//from  www  . j  a v a2 s.  com
        return cmp(node.decimalValue(), (BigDecimal) value);
    }
}

From source file:com.glaf.core.util.GetterUtils.java

public static long get(Object value, long defaultValue) {
    if (value == null) {
        return defaultValue;
    }/* w w w .j a v  a  2s. c o m*/

    if (value instanceof String) {
        return get((String) value, defaultValue);
    }

    Class<?> clazz = value.getClass();

    if (Long.class.isAssignableFrom(clazz)) {
        return (Long) value;
    }

    if (value instanceof Number) {
        Number number = (Number) value;

        return number.longValue();
    }

    return defaultValue;
}

From source file:com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype.java

protected void checkIntegerRange(String value, Number result) throws ParseException {
    if ((result instanceof Long || result instanceof Double)
            && (result.longValue() > Integer.MAX_VALUE || result.longValue() < Integer.MIN_VALUE))
        throw new ParseException(String.format("Integer range exceeded: \"%s\"", value), 0);
}

From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCSlideshowDAO.java

@Override
public Slideshow create(Slideshow slideshow) throws DAOException, ValidationException {
    logger.debug("Creating slideshow {}", slideshow);

    SlideshowValidator.validate(slideshow);

    try {//ww w .  jav  a  2s  .com
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("name", slideshow.getName());
        parameters.put("durationbetweenphotos", slideshow.getDurationBetweenPhotos());
        Number newId = insertSlideshow.executeAndReturnKey(parameters);
        slideshow.setId((int) newId.longValue());

        logger.debug("Created slideshow {}", slideshow);
        return slideshow;
    } catch (DataAccessException ex) {
        logger.error("Failed to create slideshow", ex);
        throw new DAOException("Failed to create slideshow", ex);
    }
}

From source file:org.beangle.struts2.view.component.Select.java

public boolean isSelected(Object obj) {
    if (null == value)
        return false;
    else//  w w w . j  av  a 2s .c o m
        try {
            if (value instanceof Number) {
                Number v = (Number) value;
                return v.longValue() == new Long(PropertyUtils.getSimpleProperty(obj, keyName).toString());
            } else if (value instanceof Collection) {
                @SuppressWarnings("rawtypes")
                Collection c = (Collection) value;
                for (Object o : c) {
                    if (o.equals(obj)) {
                        return true;
                    }
                }
                return false;
            } else {
                try {
                    if (obj instanceof Map) {
                        return value.equals(((Map) obj).get(keyName));
                    } else {
                        return value.equals(obj) || value.equals(PropertyUtils.getSimpleProperty(obj, keyName));
                    }
                } catch (Exception e) {
                    return false;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
}

From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCPlaceDAO.java

@Override
public Place create(Place place) throws DAOException, ValidationException {
    logger.debug("Creating Place", place);

    PlaceValidator.validate(place);/*from w w w  .j av  a  2  s . c  o  m*/

    for (Place element : readAll()) {
        if (element.getCity().equals(place.getCity()) && element.getCountry().equals(place.getCountry()))
            return element;
    }

    Map<String, Object> parameters = new HashMap<String, Object>(1);
    parameters.put("city", place.getCity());
    parameters.put("country", place.getCountry());
    parameters.put("latitude", place.getLatitude());
    parameters.put("longitude", place.getLongitude());

    try {
        Number newId = insertPlace.executeAndReturnKey(parameters);
        place.setId((int) newId.longValue());

        addedCallbacks.forEach(cb -> cb.accept(place));

        return place;
    } catch (DataAccessException ex) {
        logger.error("Failed to create place", ex);
        throw new DAOException("Failed to create place", ex);
    }
}

From source file:org.qi4j.runtime.types.NumberType.java

public Object fromJSON(Object json, Module module) {
    if (json == JSONObject.NULL) {
        return null;
    }/*from  ww  w  . j  a  v  a  2s .c o  m*/
    if (type.isClass(BigDecimal.class)) {
        return new BigDecimal("" + json);
    } else if (type.isClass(BigInteger.class)) {
        return new BigInteger("" + json);
    }
    Number number = (Number) json;

    if (type.isClass(Integer.class)) {
        return number.intValue();
    } else if (type.isClass(Long.class)) {
        return number.longValue();
    } else if (type.isClass(Double.class)) {
        return number.doubleValue();
    } else if (type.isClass(Float.class)) {
        return number.floatValue();
    } else if (type.isClass(Short.class)) {
        return number.shortValue();
    } else if (type.isClass(Byte.class)) {
        return number.byteValue();
    }

    throw new IllegalStateException("Unknown number type:" + type);
}

From source file:grails.plugins.quartz.CustomTriggerFactoryBean.java

public void afterPropertiesSet() throws ParseException {
    // Create a trigger by the class name
    customTrigger = BeanUtils.instantiateClass(triggerClass);

    // If trigger is a standard trigger, set standard properties
    if (customTrigger instanceof AbstractTrigger) {
        AbstractTrigger<?> at = (AbstractTrigger<?>) customTrigger;

        if (jobDetail != null) {
            at.setJobKey(jobDetail.getKey());
        }/* www  .  j  a  va 2 s .co  m*/

        if (triggerAttributes.containsKey(GrailsJobClassConstants.START_DELAY)) {
            Number startDelay = (Number) triggerAttributes.remove(GrailsJobClassConstants.START_DELAY);
            at.setStartTime(new Date(System.currentTimeMillis() + startDelay.longValue()));
        }
    }

    // Set non standard properties.
    BeanWrapper customTriggerWrapper = PropertyAccessorFactory.forBeanPropertyAccess(customTrigger);
    customTriggerWrapper.registerCustomEditor(String.class, new StringEditor());
    customTriggerWrapper.setPropertyValues(triggerAttributes);
}