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:de.tuberlin.uebb.jbop.optimizer.controlflow.ConstantIfInliner.java

private Number calculateOparator(final AbstractInsnNode node1, final Number op1, final Number op2) {
    Number newNumber = op1;//from  w ww . j a  v  a  2  s  .  c  o  m
    if (isCompare(node1)) {
        switch (node1.getOpcode()) {
        case Opcodes.DCMPG:
        case Opcodes.DCMPL:
            newNumber = Double.valueOf(op2.doubleValue() - op1.doubleValue());
            break;
        case Opcodes.FCMPG:
        case Opcodes.FCMPL:
            newNumber = Float.valueOf(op2.floatValue() - op1.floatValue());
            break;
        case Opcodes.LCMP:
            newNumber = Long.valueOf(op2.longValue() - op1.longValue());
            break;
        default:
            newNumber = op1;
        }
    }
    return newNumber;
}

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

@Override
public Long getClientSessionMetricsRowCount() {

    String query = "SELECT MAX(id) from CLIENT_SESSION_METRICS";
    Transaction transaction = null;/*w w w. jav 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 Client Session Metrics Count");
        transaction.rollback();
        throw new HibernateException("Cannot get client session metrics. ", e);
    }
    /*
    Session s = ServiceFactory.getAnalyticsHibernateSession();
    Transaction t = s.beginTransaction();
    Number count = (Number)s.createCriteria(ClientSessionMetrics.class).    
    setProjection(Projections.rowCount()).uniqueResult();
    t.commit();
    log.info("available row count for Client Session Metrics is = " + (count!=null?count.intValue():count));
    return count != null ? count.intValue() : 0;
     */
}

From source file:ui.Analyze.java

private void generateLaba(LocalDate ld1, LocalDate ld2) throws SQLException {
    org.jfree.data.category.DefaultCategoryDataset data = new org.jfree.data.category.DefaultCategoryDataset();
    javax.swing.table.DefaultTableModel m = (javax.swing.table.DefaultTableModel) ketTbl.getModel();
    ketTbl.removeAll();//from ww w. ja  v  a  2  s .  c o  m
    LocalDate awal, akhir, loop;
    boolean min;
    if (ld2.isBefore(ld1)) {
        awal = ld2;
        akhir = ld1;
        min = false;
    } else {
        akhir = ld2;
        awal = ld1;
        min = true;
    }
    for (loop = awal; min ? !loop.isAfter(akhir) : !loop.isBefore(akhir);) {
        Number u = getUntung(loop), r = getRugi(loop);
        data.addValue(u.longValue() - r.longValue(), "Laba", loop);
        m.addRow(new Object[] { loop, u.longValue() - r.longValue() });
        if (min)
            loop = loop.plusDays(1);
        else
            loop = loop.minusDays(1);
    }
    org.jfree.chart.ChartPanel cp = new org.jfree.chart.ChartPanel(ChartFactory.createLineChart("Laba",
            "Tanggal", "Laba", data, PlotOrientation.VERTICAL, true, true, false));
    cp.setSize(pnlLaba.getSize());
    if (0 < pnlLaba.getComponentCount())
        pnlLaba.removeAll();
    pnlLaba.add(cp);
}

From source file:org.richfaces.renderkit.AbstractProgressBarRenderer.java

/**
 * Converts value attr to number value/*from w  w  w  .j a va  2s .  c  om*/
 * 
 * @param v -
 *            value attr
 * @return result
 */
public Number getNumber(Object v) {
    Number result = null;
    if (v != null) {
        try {
            if (v instanceof String) {
                result = Double.parseDouble((String) v);
            } else {
                Number n = (Number) v;
                if (n instanceof BigDecimal || n instanceof Double || n instanceof Float) {
                    result = n.floatValue();
                } else if (n instanceof Integer || n instanceof Long) {
                    result = n.longValue();
                }
            }
        } catch (Exception e) {
            // no action
        }
        return result;
    }
    return new Integer(0);
}

From source file:com.hortonworks.streamline.streams.actions.storm.topology.StormTopologyActionsImpl.java

@Override
public void init(Map<String, Object> conf) {
    this.conf = conf;
    if (conf != null) {
        if (conf.containsKey(StormTopologyLayoutConstants.STORM_ARTIFACTS_LOCATION_KEY)) {
            stormArtifactsLocation = (String) conf
                    .get(StormTopologyLayoutConstants.STORM_ARTIFACTS_LOCATION_KEY);
        }//from ww  w.j a  v  a  2s. c o  m
        if (conf.containsKey(StormTopologyLayoutConstants.STORM_HOME_DIR)) {
            String stormHomeDir = (String) conf.get(StormTopologyLayoutConstants.STORM_HOME_DIR);
            if (!stormHomeDir.endsWith(File.separator)) {
                stormHomeDir += File.separator;
            }
            stormCliPath = stormHomeDir + "bin" + File.separator + "storm";
        }
        this.stormJarLocation = (String) conf.get(StormTopologyLayoutConstants.STORM_JAR_LOCATION_KEY);

        catalogRootUrl = (String) conf.get(StormTopologyLayoutConstants.YAML_KEY_CATALOG_ROOT_URL);

        Map<String, String> env = System.getenv();
        String javaHomeStr = env.get("JAVA_HOME");
        if (StringUtils.isNotEmpty(javaHomeStr)) {
            if (!javaHomeStr.endsWith(File.separator)) {
                javaHomeStr += File.separator;
            }
            javaJarCommand = javaHomeStr + "bin" + File.separator + "jar";
        } else {
            javaJarCommand = "jar";
        }

        String stormApiRootUrl = (String) conf.get(TopologyLayoutConstants.STORM_API_ROOT_URL_KEY);
        Subject subject = (Subject) conf.get(TopologyLayoutConstants.SUBJECT_OBJECT);
        Client restClient = ClientBuilder.newClient(new ClientConfig());

        this.client = new StormRestAPIClient(restClient, stormApiRootUrl, subject);
        nimbusSeeds = (String) conf.get(NIMBUS_SEEDS);
        nimbusPort = Integer.valueOf((String) conf.get(NIMBUS_PORT));

        if (conf.containsKey(TopologyLayoutConstants.NIMBUS_THRIFT_MAX_BUFFER_SIZE)) {
            nimbusThriftMaxBufferSize = (Long) conf.get(TopologyLayoutConstants.NIMBUS_THRIFT_MAX_BUFFER_SIZE);
        } else {
            nimbusThriftMaxBufferSize = DEFAULT_NIMBUS_THRIFT_MAX_BUFFER_SIZE;
        }

        setupSecuredStormCluster(conf);

        EnvironmentService environmentService = (EnvironmentService) conf
                .get(TopologyLayoutConstants.ENVIRONMENT_SERVICE_OBJECT);
        Number namespaceId = (Number) conf.get(TopologyLayoutConstants.NAMESPACE_ID);
        this.serviceConfigurationReader = new AutoCredsServiceConfigurationReader(environmentService,
                namespaceId.longValue());
    }
    File f = new File(stormArtifactsLocation);
    f.mkdirs();
}

From source file:org.jasper.collectionspace.smk.datasource.JsonCSDataSource.java

protected Object convertNumber(Number number, Class<?> valueClass) throws JRException {
    Number value = null;/*  ww w .  j  a v a  2  s.c  om*/
    if (valueClass.equals(Byte.class)) {
        value = new Byte(number.byteValue());
    } else if (valueClass.equals(Short.class)) {
        value = new Short(number.shortValue());
    } else if (valueClass.equals(Integer.class)) {
        value = Integer.valueOf(number.intValue());
    } else if (valueClass.equals(Long.class)) {
        value = new Long(number.longValue());
    } else if (valueClass.equals(Float.class)) {
        value = new Float(number.floatValue());
    } else if (valueClass.equals(Double.class)) {
        value = new Double(number.doubleValue());
    } else if (valueClass.equals(BigInteger.class)) {
        value = BigInteger.valueOf(number.longValue());
    } else if (valueClass.equals(BigDecimal.class)) {
        value = new BigDecimal(Double.toString(number.doubleValue()));
    } else {
        throw new JRException("Unknown number class " + valueClass.getName());
    }
    return value;
}

From source file:org.polymap.rhei.field.NumberValidator.java

public M transform2Model(String fieldValue) throws Exception {
    if (fieldValue == null) {
        return null;
    } else if (fieldValue instanceof String) {
        ParsePosition pp = new ParsePosition(0);
        Number result = nf.parse((String) fieldValue, pp);

        if (pp.getErrorIndex() > -1 || pp.getIndex() < ((String) fieldValue).length()) {
            throw new ParseException("field value: " + fieldValue, pp.getErrorIndex());
        }/*from  w w w.  j ava2  s .c  o  m*/

        log.debug("value: " + fieldValue + " -> " + result.doubleValue());

        // XXX check max digits

        if (Float.class.isAssignableFrom(targetClass)) {
            return (M) Float.valueOf(result.floatValue());
        } else if (Double.class.isAssignableFrom(targetClass)) {
            return (M) Double.valueOf(result.floatValue());
        } else if (Integer.class.isAssignableFrom(targetClass)) {
            return (M) Integer.valueOf(result.intValue());
        } else if (Long.class.isAssignableFrom(targetClass)) {
            return (M) Long.valueOf(result.longValue());
        } else {
            throw new RuntimeException("Unsupported target type: " + targetClass);
        }
    } else {
        throw new RuntimeException("Unhandled field value type: " + fieldValue);
    }
}

From source file:IntRange.java

/**
 * <p>Tests whether the specified <code>Number</code> occurs within
 * this range using <code>long</code> comparison..</p>
 * //from  w ww .  ja v a  2 s . co m
 * <p><code>null</code> is handled and returns <code>false</code>.</p>
 * 
 * <p>This implementation forwards to the {@link #containsLong(long)} method.</p>
 *
 * @param value  the long to test, may be <code>null</code>
 * @return <code>true</code> if the specified number occurs within this
 *  range by <code>long</code> comparison
 */
public boolean containsLong(Number value) {
    if (value == null) {
        return false;
    }
    return containsLong(value.longValue());
}

From source file:org.cinchapi.concourse.util.ConvertTest.java

@Test
public void testConvertLinkFromLongValue() {
    // A int/long that is wrapped between two at (@) symbols must always
    // convert to a Link
    Number number = Random.getLong();
    String value = MessageFormat.format("{0}{1}{0}", "@", number.toString()); // must use
                                                                              // number.toString()
                                                                              // so comma
                                                                              // separators are
                                                                              // not added to
                                                                              // the output
    Link link = (Link) Convert.stringToJava(value);
    Assert.assertEquals(number.longValue(), link.longValue());
}

From source file:LongRange.java

/**
 * <p>Tests whether the specified <code>number</code> occurs within
 * this range using <code>long</code> comparison.</p>
 * /*from   w  ww  . ja v a2  s  .c o m*/
 * <p><code>null</code> is handled and returns <code>false</code>.</p>
 *
 * @param number  the number to test, may be <code>null</code>
 * @return <code>true</code> if the specified number occurs within this range
 */
public boolean containsNumber(Number number) {
    if (number == null) {
        return false;
    }
    return containsLong(number.longValue());
}