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.sipfoundry.sipxconfig.components.MillisDurationFormat.java

public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
    // only works for numbers - class exception otherwise
    Number millisNumber = (Number) obj;
    long millis = millisNumber.longValue();

    if (m_formats == null) {
        initLocale(null);/*w ww. j a  va2s  .  c  o m*/
    }

    if (millis < DateUtils.MILLIS_PER_SECOND && !m_showZero) {
        return toAppendTo;
    }

    boolean added = false;
    long[] result = calculate(millis);
    for (int i = 0; i < result.length; i++) {
        long l = result[i];
        if (l >= 0 || added || i == result.length - 1) {
            if (added) {
                toAppendTo.append(m_separator);
            }
            Object params = new Object[] { l };
            m_formats[i].format(params, toAppendTo, pos);
            added = true;
        }
    }
    return toAppendTo;
}

From source file:MutableLong.java

/**    Compares this number to another number.
 *
 *   @param   number   The other number.
 *///from  w w  w  .j a  v  a2  s  . c  o  m

public int compareTo(Number number) {
    return doCompare(mutableLong, number.longValue());
}

From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java

/**
 * Transforms a Number into a valid javascript number.<br>
 * Float gets promoted to Double.<br>
 * Byte and Short get promoted to Integer.<br>
 * Long gets downgraded to Integer if possible.<br>
 *//*from  ww  w  .j  a  v a 2s.c o m*/
public static Number transformNumber(Number input) {
    if (input instanceof Float) {
        return new Double(input.toString());
    } else if (input instanceof Short) {
        return new Integer(input.intValue());
    } else if (input instanceof Byte) {
        return new Integer(input.intValue());
    } else if (input instanceof Long) {
        Long max = new Long(Integer.MAX_VALUE);
        if (input.longValue() <= max.longValue() && input.longValue() >= Integer.MIN_VALUE) {
            return new Integer(input.intValue());
        }
    }

    return input;
}

From source file:MutableLong.java

public MutableLong(Number value) {
    super();
    this._value = value.longValue();
}

From source file:jgnash.ui.commodity.SecurityItemLabelGenerator.java

/**
 * Generates a tooltip text item for a particular item within a series.
 *
 * @param dataset  the dataset./*from w  w w .  j a  v a 2 s .co m*/
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return The tooltip text.
 */
@Override
public String generateToolTip(final XYDataset dataset, final int series, final int item) {

    String result = null;

    if (dataset instanceof OHLCDataset) {
        OHLCDataset d = (OHLCDataset) dataset;

        Number close = d.getClose(series, item);

        Number x = d.getX(series, item);

        if (x != null) {
            Date date = new Date(x.longValue());
            result = dateLabel + " " + dateFormatter.format(date);

            if (close != null) {
                result = result + " " + closeLabel + "  " + numberFormatter.format(close.doubleValue());
            }
        }
    }

    return result;
}

From source file:org.bbreak.excella.reports.util.ReportsUtil.java

/**
 * ???/* www . j a va 2 s.  c o m*/
 * 
 * @param info 
 * @param propertyName ?
 * @param parsers ?
 * @return ?
 */
public static BigDecimal getSumValue(ParamInfo info, String propertyName, List<ReportsTagParser<?>> parsers) {
    List<?> values = ReportsUtil.getParamValues(info, propertyName, parsers);

    BigDecimal sumValue = BigDecimal.ZERO;

    for (Object value : values) {
        if (value instanceof Number) {

            Number num = (Number) value;
            BigDecimal decimal = null;
            if (value instanceof Byte) {
                decimal = new BigDecimal(num.intValue());
            } else if (value instanceof Short) {
                decimal = new BigDecimal(num.intValue());
            } else if (value instanceof Integer) {
                decimal = new BigDecimal(num.intValue());
            } else if (value instanceof Long) {
                decimal = new BigDecimal(num.longValue());
            } else if (value instanceof Float) {
                Float floatValue = (Float) value;
                decimal = new BigDecimal(String.valueOf(floatValue));
            } else if (value instanceof Double) {
                decimal = BigDecimal.valueOf(num.doubleValue());
            } else if (value instanceof BigInteger) {
                decimal = new BigDecimal((BigInteger) value);
            } else if (value instanceof BigDecimal) {
                decimal = (BigDecimal) value;
            }

            if (decimal != null) {
                sumValue = sumValue.add(decimal);
            }
        }
    }
    return sumValue;
}

From source file:org.apache.james.mailbox.elasticsearch.search.ElasticSearchSearcher.java

private Optional<Pair<MailboxId, Long>> extractContentFromHit(SearchHit hit) {
    SearchHitField mailboxId = hit.field(JsonMessageConstants.MAILBOX_ID);
    SearchHitField uid = hit.field(JsonMessageConstants.ID);
    if (mailboxId != null && uid != null) {
        Number uidAsNumber = uid.getValue();
        return Optional.of(Pair.of(mailboxIdFactory.fromString(mailboxId.getValue()), uidAsNumber.longValue()));
    } else {//from w  ww.j a  va 2s  .  c  o m
        LOGGER.warn("Can not extract UID and/or MailboxId for search result " + hit.getId());
        return Optional.empty();
    }
}

From source file:com.example.dfa.demo.service.DfaDemoServiceImpl.java

@Override
public Long addNewProspect(EmployeeProspectDTO employeeProspect) {
    SqlParameterSource inParams = new BeanPropertySqlParameterSource(employeeProspect);
    Number insertedRow = insertEmployeeInsertStatement.executeAndReturnKey(inParams);
    employeeProspect.setEmployeeId(insertedRow.longValue());
    Map<String, ?> result = startWorkflowSpaCall.execute(inParams);
    Long dfaWorkflowId = converter.convert(result.get("dfaWorkflowId"), Long.class);
    employeeProspect.setDfaWorkflowId(dfaWorkflowId);
    return dfaWorkflowId;
}

From source file:de.tuberlin.uebb.jbop.optimizer.utils.NodeHelper.java

private static AbstractInsnNode getLongInsnNode(final Number newNumber) {
    if (newNumber.longValue() == 0) {
        return new InsnNode(Opcodes.LCONST_0);
    } else if (newNumber.longValue() == 1) {
        return new InsnNode(Opcodes.LCONST_1);
    } else {//  w  w  w . j av  a2  s  . c o m
        return new LdcInsnNode(newNumber);
    }
}

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

public boolean isSelected(Object obj) {
    if (null == value)
        return false;
    else//from  w w w . j  av  a 2 s . com
        try {
            if (value instanceof Number) {
                Number v = (Number) value;
                return v.longValue() == new Long(PropertyUtils.getSimpleProperty(obj, keyName).toString());
            } else {
                try {
                    return value.equals(obj) || value.equals(PropertyUtils.getSimpleProperty(obj, keyName));
                } catch (Exception e) {
                    return false;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
}