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.openvpms.web.echo.style.StylePropertyEvaluator.java

/**
 * Rounds a numeric value to a long.//  w  ww.  j av a  2s .  c o m
 *
 * @param value the value to round
 * @return the rounded value
 */
private long round(Number value) {
    if (value instanceof Integer || value instanceof Long) {
        return value.longValue();
    }
    BigDecimal result = (value instanceof BigDecimal) ? (BigDecimal) value
            : new BigDecimal(value.doubleValue());
    return result.setScale(0, RoundingMode.HALF_EVEN).longValue();
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJInt16Editor.java

public Short getInt16Value() {
    final String S_ProcName = "getInt16Value";
    Short retval;/*  w  w w.j  a  v  a  2 s  .c  o  m*/
    String text = getText();
    if ((text == null) || (text.length() <= 0)) {
        retval = null;
    } else {
        if (!isEditValid()) {
            throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName,
                    "Field is not valid");
        }
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = null;
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            short v = s.shortValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = (Short) s;
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            int v = i.intValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Short(i.shortValue());
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            long v = l.longValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Short(l.shortValue());
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            long v = n.longValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Short(n.shortValue());
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, or Number");
        }
    }
    return (retval);
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJInt32Editor.java

public Integer getInt32Value() {
    final String S_ProcName = "getInt32Value";
    Integer retval;/*from w  w w .  ja  v a 2 s .  co  m*/
    String text = getText();
    if ((text == null) || (text.length() <= 0)) {
        retval = null;
    } else {
        if (!isEditValid()) {
            throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName,
                    "Field is not valid");
        }
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = null;
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            short v = s.shortValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Integer((int) v);
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            int v = i.intValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = i;
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            long v = l.longValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Integer(l.intValue());
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            long v = n.longValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Integer(n.intValue());
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, or Number");
        }
    }
    return (retval);
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJInt64Editor.java

public Long getInt64Value() {
    final String S_ProcName = "getInt64Value";
    Long retval;/*w  ww . j  a v a 2  s.co  m*/
    String text = getText();
    if ((text == null) || (text.length() <= 0)) {
        retval = null;
    } else {
        if (!isEditValid()) {
            throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName,
                    "Field is not valid");
        }
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = null;
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            short v = s.shortValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Long((long) v);
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            int v = i.intValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Long((long) v);
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            long v = l.longValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = l;
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            long v = n.longValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Long(n.longValue());
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, or Number");
        }
    }
    return (retval);
}

From source file:cz.cvut.kbss.jsonld.jackson.serialization.JacksonJsonWriter.java

@Override
public void writeNumber(Number number) throws IOException {
    if (number instanceof Integer) {
        jsonGenerator.writeNumber(number.intValue());
    } else if (number instanceof Long) {
        jsonGenerator.writeNumber(number.longValue());
    } else if (number instanceof Float) {
        jsonGenerator.writeNumber(number.floatValue());
    } else if (number instanceof Double) {
        jsonGenerator.writeNumber(number.doubleValue());
    } else if (number instanceof BigInteger) {
        jsonGenerator.writeNumber((BigInteger) number);
    } else if (number instanceof BigDecimal) {
        jsonGenerator.writeNumber((BigDecimal) number);
    } else if (number instanceof Short) {
        jsonGenerator.writeNumber(number.shortValue());
    } else if (number instanceof Byte) {
        jsonGenerator.writeNumber(number.byteValue());
    } else {/*from   w w  w. j  a va2  s  . c  om*/
        throw new IllegalArgumentException(
                "Unable to write number " + number + " of type " + number.getClass());
    }
}

From source file:com.jagornet.dhcp.db.JdbcDhcpOptionDAO.java

public void create(DhcpOption option) {
    SimpleJdbcInsert insertOption = new SimpleJdbcInsert(getDataSource()).withTableName("dhcpoption")
            .usingGeneratedKeyColumns("id");

    Long iaId = option.getIdentityAssocId();
    Long iaAddrId = option.getIaAddressId();
    Long iaPrefixId = option.getIaPrefixId();

    if ((iaId == null) && (iaAddrId == null) && (iaPrefixId == null)) {
        throw new IllegalStateException("DhcpOption must reference either an IdentityAssoc, an IaAddress");
    }/* w  w w .ja  v a2  s  .  com*/
    if ((iaId != null) && (iaAddrId != null)) {
        throw new IllegalStateException("DhcpOption cannot reference both an IdentityAssoc and an IaAddress");
    }
    if ((iaId != null) && (iaPrefixId != null)) {
        throw new IllegalStateException("DhcpOption cannot reference both an IdentityAssoc and an IaPrefix");
    }
    if ((iaAddrId != null) && (iaPrefixId != null)) {
        throw new IllegalStateException("DhcpOption cannot reference both an IaAddress and an IaPrefix");
    }

    Map<String, Object> parameters = new HashMap<String, Object>(3);
    parameters.put("code", option.getCode());
    parameters.put("value", option.getValue());
    // TODO: verify that the option has only one foreign key
    if (iaId != null) {
        parameters.put("identityassoc_id", iaId);
        insertOption.usingColumns("code", "value", "identityassoc_id");
    } else if (iaAddrId != null) {
        parameters.put("iaaddress_id", iaAddrId);
        insertOption.usingColumns("code", "value", "iaaddress_id");
    } else if (iaPrefixId != null) {
        parameters.put("iaprefix_id", iaAddrId);
        insertOption.usingColumns("code", "value", "iaprefix_id");
    }
    /**
     * Note: see https://issues.apache.org/jira/browse/DERBY-3609
     * "Formally, Derby does not support getGeneratedKeys since 
     * DatabaseMetaData.supportsGetGeneratedKeys() returns false. 
     * However, Statement.getGeneratedKeys() is partially implemented,
     * ... since it will only return a meaningful result when an single 
     * row insert is done with INSERT...VALUES"
     * 
     * Spring has thus provided a workaround as described here:
     * http://jira.springframework.org/browse/SPR-5306
     */
    Number newId = insertOption.executeAndReturnKey(parameters);
    if (newId != null) {
        option.setId(newId.longValue());
    }
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJUInt16Editor.java

public Integer getUInt16Value() {
    final String S_ProcName = "getUInt16Value";
    Integer retval;//  w  ww .java2s  .c  o m
    String text = getText();
    if ((text == null) || (text.length() <= 0)) {
        retval = null;
    } else {
        if (!isEditValid()) {
            throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName,
                    "Field is not valid");
        }
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = null;
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            short v = s.shortValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Integer((int) v);
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            int v = i.intValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = i;
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            long v = l.longValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Integer(l.intValue());
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            long v = n.longValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Integer(n.intValue());
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, or Number");
        }
    }
    return (retval);
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJUInt32Editor.java

public Long getUInt32Value() {
    final String S_ProcName = "getUInt32Value";
    Long retval;//from   ww w.  ja va2  s .c o  m
    String text = getText();
    if ((text == null) || (text.length() <= 0)) {
        retval = null;
    } else {
        if (!isEditValid()) {
            throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName,
                    "Field is not valid");
        }
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = null;
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            short v = s.shortValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Long((long) v);
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            int v = i.intValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Long((long) v);
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            long v = l.longValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = l;
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            long v = n.longValue();
            if ((v < getMinValue()) || (v > getMaxValue())) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, getMinValue(), getMaxValue());
            }
            retval = new Long(n.longValue());
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, or Number");
        }
    }
    return (retval);
}

From source file:org.kalypso.zml.ui.chart.layer.themes.LineLayerModelVisitor.java

private Date getTo() {
    if (Objects.isNotNull(m_to))
        return m_to;

    final Number max = m_domainIntervall.getMax();
    if (Objects.isNull(max))
        return null;

    m_to = new Date(max.longValue());
    return m_to;//from w ww .j  a v  a 2  s.c o m
}

From source file:org.kalypso.zml.ui.chart.layer.themes.LineLayerModelVisitor.java

private Date getFrom() {
    if (Objects.isNotNull(m_from))
        return m_from;

    final Number min = m_domainIntervall.getMin();
    if (Objects.isNull(min))
        return null;

    m_from = new Date(min.longValue());
    return m_from;
}