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:op.tools.SYSTools.java

public static BigDecimal parseCurrency(String test) {
    NumberFormat nf = DecimalFormat.getCurrencyInstance();
    test = assimilateDecimalSeparators(test);
    Number num;
    try {/*from w w  w  . j  a  v  a2s.c  o  m*/
        num = nf.parse(test);
    } catch (ParseException ex) {
        try {
            String test1 = test + " " + SYSConst.eurosymbol;
            num = nf.parse(test1);
        } catch (ParseException ex1) {
            num = null;
        }
    }

    BigDecimal betrag = null;
    if (num != null) {
        if (num instanceof Long) {
            betrag = new BigDecimal(num.longValue());
        } else if (num instanceof Double) {
            betrag = new BigDecimal(num.doubleValue());
        } else if (num instanceof BigDecimal) {
            betrag = (BigDecimal) num;
        } else {
            betrag = null;
        }
    }

    return betrag;
}

From source file:moe.encode.airblock.commands.arguments.types.PrimitiveParser.java

@Override
public Object convert(Executor executor, ArgumentConverter parser, Type type, String value) {
    Class<?> cls = ReflectionUtils.toClass(type);
    if (ClassUtils.isPrimitiveWrapper(cls))
        cls = ClassUtils.wrapperToPrimitive(cls);

    if (cls.equals(boolean.class))
        return this.isTrue(executor, value);
    else if (cls.equals(char.class)) {
        if (value.length() > 0)
            throw new NumberFormatException("Character arguments cannot be longer than one characters");
        return value.charAt(0);
    }/*w w w . ja  va2s. co  m*/

    // Get the locale of the user and get a number-format according to it.
    LocaleResolver resolver = TranslationManager.getResolver(executor);
    Locale locale;
    if (resolver != null)
        locale = resolver.getLocale();
    else
        locale = Locale.ENGLISH;

    NumberFormat nf = NumberFormat.getNumberInstance(locale);
    nf.setGroupingUsed(true);

    // Parse the value.
    Number result;
    try {
        result = nf.parse(value);
    } catch (ParseException e) {
        NumberFormatException nfe = new NumberFormatException("Invalid number");
        nfe.initCause(e);
        throw nfe;
    }

    // Returns the value in the correct type.
    if (cls.equals(int.class))
        return result.intValue();
    else if (cls.equals(float.class))
        return result.floatValue();
    else if (cls.equals(double.class))
        return result.doubleValue();
    else if (cls.equals(byte.class))
        return result.byteValue();
    else if (cls.equals(short.class))
        return result.shortValue();
    else if (cls.equals(long.class))
        return result.longValue();

    throw new NumberFormatException("Unknown primitive type.");
}

From source file:org.opengroupware.logic.blobs.OGoRangeDirBlobStore.java

public File blobFileForId(Number _id, Number _containerId, String _ext) {
    if (_id == null)
        return null;

    File container = null;// www . j a  va 2s. com

    /* container */

    if (_containerId != null) {
        container = new File(this.root, _containerId.toString());
        if (!container.exists()) {
            if (!container.mkdir()) {
                /* probably a permission setup issue */
                log.error("could not create BLOB directory for container '" + _containerId + "': " + container
                        + " (check filesystem permissions!)");
                return null;
            }
        }
    } else
        container = this.root;

    /* folder ranges */

    if (UseFoldersForIDRanges) {
        long rangeId = _id.longValue();
        rangeId = rangeId - (rangeId % this.rangeSize);

        container = new File(container, Long.toString(rangeId));
        if (!container.exists()) {
            if (!container.mkdir()) {
                /* probably a permission setup issue */
                log.error("could not create BLOB directory for id-range '" + rangeId + "': " + container
                        + " (check filesystem permissions!)");
                return null;
            }
        }
    }

    /* filename */

    final StringBuilder sb = new StringBuilder(128);
    sb.append(_id);
    if (_ext != null && _ext.length() > 0) {
        sb.append('.');
        sb.append(_ext);
    }

    return new File(container, sb.toString());
}

From source file:vteaexploration.plottools.panels.XYChartPanel.java

private double getMaximumOfData(ArrayList alVolumes, int x) {

    ListIterator litr = alVolumes.listIterator();

    //ArrayList<Number> al = new ArrayList<Number>();
    Number high = 0;

    while (litr.hasNext()) {
        try {//from ww w  .j  a  v a2 s  .co  m
            MicroObjectModel volume = (MicroObjectModel) litr.next();
            Number Corrected = processPosition(x, volume);
            if (Corrected.floatValue() > high.floatValue()) {
                high = Corrected;
            }
        } catch (NullPointerException e) {
        }
    }
    return high.longValue();

}

From source file:de.instantouch.model.io.SnakeJSONReader.java

public void read(SnakeType type, Object value) throws SnakeModelException, IOException, InstantiationException,
        IllegalAccessException, ClassNotFoundException {

    if (type.hasReference()) {
        SnakeReference ref = type.getReference();
        if (ref == null) {
            throw new SnakeNotInitializedException("reference is not initialized");
        }/*from  www. j a  v a  2s  .  com*/

        SnakeType key = ref.getKey();
        if (key == null) {
            throw new SnakeNotInitializedException("no reference key container os given");
        }

        read(key, value);
    } else {
        if (type instanceof SnakeEntity) {
            readEntity((SnakeEntity) type, value);
        } else if (type instanceof SnakeList) {
            readList((SnakeList) type, value);
        } else if (type instanceof SnakeMap) {
            readMap((SnakeMap) type, value);
        } else if (value == null) {
            type.setNull();
        } else if (value instanceof String) {
            type.set(value.toString());
        } else if (value instanceof Boolean) {
            type.set(value.toString());
        } else if (value instanceof Number) {
            Number number = (Number) value;

            if (value instanceof Double) {
                type.set(number.doubleValue());
            } else if (value instanceof Float) {
                type.set(number.floatValue());
            } else if (value instanceof Byte) {
                type.set(number.byteValue());
            } else if (value instanceof Short) {
                type.set(number.shortValue());
            } else if (value instanceof Integer) {
                type.set(number.intValue());
            } else if (value instanceof Long) {
                type.set(number.longValue());
            }
        }
    }

}

From source file:vteaexploration.plottools.panels.XYChartPanel.java

private double getMinimumOfData(ArrayList alVolumes, int x) {

    ListIterator litr = alVolumes.listIterator();

    //ArrayList<Number> al = new ArrayList<Number>();
    Number low = getMaximumOfData(alVolumes, x);

    while (litr.hasNext()) {
        try {/*from  w w w.j  av a 2  s  . com*/
            MicroObjectModel volume = (MicroObjectModel) litr.next();
            Number Corrected = processPosition(x, volume);
            if (Corrected.floatValue() < low.floatValue()) {
                low = Corrected;
            }
        } catch (NullPointerException e) {
        }
    }
    return low.longValue();
}

From source file:org.lwes.db.EventTemplateDB.java

private void checkRange(String eventName, String attributeName, Object value, long min, long max)
        throws EventSystemException {
    final Number number = (Number) value;
    if (min <= number.longValue() && number.longValue() <= max) {
        return;//w  w w .ja va 2  s . c o  m
    }
    throw new EventSystemException(String.format("Field %s.%s value %d outside allowed range [%d,%d]",
            eventName, attributeName, value, min, max));
}

From source file:org.osgp.adapter.protocol.dlms.domain.commands.DlmsHelperService.java

public Long readLong(final DataObject resultData, final String description) throws ProtocolAdapterException {
    final Number number = this.readNumber(resultData, description);
    if (number == null) {
        return null;
    }/*ww  w  .ja  v  a  2 s.  c  om*/
    return number.longValue();
}

From source file:org.apache.usergrid.apm.service.SessionDBServiceImpl.java

@Override
public Long getCompactSessionMetricsRowCount() {
    String query = "SELECT MAX(id) from COMPACT_SESSION_METRICS";
    Transaction transaction = null;/*from  w w  w. ja  v  a 2  s.c om*/
    Session session = null;
    try {
        session = ServiceFactory.getAnalyticsHibernateSession();
        transaction = session.beginTransaction();
        SQLQuery sqlquery = session.createSQLQuery(query);

        Number number = (Number) sqlquery.uniqueResult();
        transaction.commit();
        if (number != null)
            return number.longValue();
        else
            return 0L;
    } catch (HibernateException e) {
        e.printStackTrace();
        log.error("Problem getting Compact Session Metrics Count");
        throw new HibernateException("Cannot get compact session metrics. ", e);
    }

}

From source file:ui.Analyze.java

private Component labane(LocalDate l) throws SQLException {
    org.jfree.data.category.DefaultCategoryDataset data = new org.jfree.data.category.DefaultCategoryDataset();
    for (LocalDate l2 = l; l2.isBefore(l.plusWeeks(1)); l2 = l2.plusDays(1)) {
        Number u = getUntung(l2), r = getRugi(l2);
        data.addValue(u.longValue() - r.longValue(), "Laba", l2);
    }//from ww w .  ja v  a2s.  c om
    return new org.jfree.chart.ChartPanel(ChartFactory.createLineChart("Laba Bersih", "Periode", "Nilai", data,
            PlotOrientation.VERTICAL, true, true, false));
}