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:com.boundary.sdk.event.script.SnmpToMeasureTest.java

@Test
public void testTimeTickVariable() throws InterruptedException {
    String expectedOid = "1.3.6.1.2.1.1.3.0";
    Number expectedValue = 2929358;
    String expectedSource = "www.myweb.com";
    String expectedMetricId = "MY_FAVORITE_METRIC";

    VariableBinding vb = new VariableBinding();
    TimeTicks v = new TimeTicks();
    v.setValue(expectedValue.longValue());

    vb.setOid(new OID(expectedOid));
    vb.setVariable(v);/*w  w w.  j av a 2s .c  om*/

    SnmpPollerConfiguration config = getSnmpPollerConfiguration(expectedSource, expectedMetricId, expectedOid);
    out.expectedMessageCount(1);
    in.sendBodyAndHeaders(vb, setScriptHeaders(SNMP_TO_MEASURE_SCRIPT, config));
    out.assertIsSatisfied();

    Measurement m = getMeasurement(out);
    assertNotNull("check event for null", m);
    assertEquals("check source", expectedSource, m.getSource());
    assertEquals("check metric", expectedMetricId, m.getMetric());
    assertEquals("check measure", v.getValue(), m.getMeasure().intValue());
}

From source file:com.boundary.sdk.event.script.SnmpToMeasureTest.java

@Test
public void testCounter32Variable() throws InterruptedException {
    String expectedOid = "1.3.6.1.2.1.4.3.0";
    Number expectedValue = 1588007;
    String expectedSource = "www.myweb.com";
    String expectedMetricId = "MY_FAVORITE_METRIC";

    VariableBinding vb = new VariableBinding();
    Counter32 v = new Counter32();
    v.setValue(expectedValue.longValue());

    vb.setOid(new OID(expectedOid));
    vb.setVariable(v);/*  ww w.  j a  va 2 s.  c  o  m*/

    SnmpPollerConfiguration config = getSnmpPollerConfiguration(expectedSource, expectedMetricId, expectedOid);
    out.expectedMessageCount(1);
    in.sendBodyAndHeaders(vb, setScriptHeaders(SNMP_TO_MEASURE_SCRIPT, config));
    out.assertIsSatisfied();

    Measurement m = getMeasurement(out);
    assertNotNull("check event for null", m);
    assertEquals("check source", expectedSource, m.getSource());
    assertEquals("check metric", expectedMetricId, m.getMetric());
    assertEquals("check measure", v.getValue(), m.getMeasure().intValue());
}

From source file:com.bdb.weather.display.summary.HighLowPanel.java

@Override
public void chartMouseClicked(ChartMouseEventFX event) {
    ChartEntity entity = event.getEntity();
    ///*from w  ww.  j  a v  a 2s  .c  o  m*/
    // Was a point on the plot selected?
    //
    if (entity instanceof XYItemEntity) {
        XYItemEntity itemEntity = (XYItemEntity) entity;
        XYDataset dataset = itemEntity.getDataset();
        Number x = dataset.getXValue(itemEntity.getSeriesIndex(), itemEntity.getItem());
        LocalDate date = LocalDate.from(Instant.ofEpochMilli(x.longValue()));
        boolean doubleClick = event.getTrigger().getClickCount() == 2;
        if (doubleClick) {
            supporter.launchView(launcher, date);
        }
    }
}

From source file:de.unioninvestment.eai.portal.portlet.crud.scripting.domain.container.rest.ValueConverter.java

private Object convertNumberToNumber(Class<?> targetClass, Number number) {
    if (targetClass.isAssignableFrom(number.getClass())) {
        return number;
    } else if (targetClass == Integer.class) {
        return number.intValue();
    } else if (targetClass == Long.class) {
        return number.longValue();
    } else if (targetClass == Double.class) {
        return number.doubleValue();
    } else if (targetClass == BigDecimal.class) {
        return new BigDecimal(number.toString());
    }//from w ww  .ja  v a2  s  .  c om
    throw new IllegalArgumentException("Cannot convert to " + targetClass.getSimpleName() + ": " + number
            + " of type " + number.getClass().getName());
}

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

private Slide createBase(Slide slide) throws DAOException, ValidationException {
    logger.debug("Creating slide {}", slide);

    SlideValidator.validate(slide);// w  ww  . j ava 2  s.c  o  m

    try {
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("id", slide.getId());
        parameters.put("slideshow_id", slide.getSlideshowId());
        parameters.put("orderposition", slide.getOrder());
        parameters.put("caption", slide.getCaption());
        Number newId = insertSlide.executeAndReturnKey(parameters);
        slide.setId((int) newId.longValue());

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

From source file:com.github.nlloyd.hornofmongo.adaptor.NumberLong.java

@JSConstructor
public NumberLong(final Object obj) {
    super();//from   w w  w  . jav a2s .  c om
    if (obj instanceof Number) {
        realLong = ((Number) obj).longValue();
    } else if (!(obj instanceof Undefined)) {
        String str = Context.toString(obj);
        Number num = NumberUtils.createNumber(str);
        if ((num instanceof BigInteger) || (num instanceof BigDecimal))
            throw new NumberFormatException(
                    String.format("Error: could not convert %s to NumberLong, too big.", str));
        realLong = num.longValue();
    }
    put("floatApprox", this, realLong);
}

From source file:com.arpnetworking.metrics.impl.ApacheHttpSinkTest.java

private static void assertSample(final List<ClientV2.MetricEntry> samples, final String name,
        final Number value, @Nullable final ClientV2.CompoundUnit compoundUnit) {

    final ClientV2.Quantity.Builder protobufSample = ClientV2.Quantity.newBuilder();
    if (value instanceof Double || value instanceof Float) {
        protobufSample.setDoubleValue(value.doubleValue());
    } else {/*from   w  w w  .  ja v  a2 s . c  o  m*/
        protobufSample.setLongValue(value.longValue());
    }
    if (compoundUnit != null) {
        protobufSample.setUnit(compoundUnit);
    } else {
        protobufSample.setUnit(ClientV2.CompoundUnit.newBuilder().build());
    }

    Assert.assertTrue(
            String.format("Missing sample: name=%s, value=%s (%s)", name, value, value.getClass().getName()),
            samples.contains(ClientV2.MetricEntry.newBuilder().setName(name)
                    .addSamples(0, protobufSample.build()).build()));
}

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

public void create(final IaAddress iaAddr) {
    /**//from  w ww.j  a va  2s. c  o m
     * 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
     */
    GeneratedKeyHolder newKey = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        @Override
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(
                    "insert into iaaddress" + " (ipaddress, starttime, preferredendtime, validendtime,"
                            + " state, identityassoc_id)" + " values (?, ?, ?, ?, ?, ?)",
                    PreparedStatement.RETURN_GENERATED_KEYS);
            ps.setBytes(1, iaAddr.getIpAddress().getAddress());
            java.sql.Timestamp sts = new java.sql.Timestamp(iaAddr.getStartTime().getTime());
            ps.setTimestamp(2, sts, Util.GMT_CALENDAR);
            java.sql.Timestamp pts = new java.sql.Timestamp(iaAddr.getPreferredEndTime().getTime());
            ps.setTimestamp(3, pts, Util.GMT_CALENDAR);
            java.sql.Timestamp vts = new java.sql.Timestamp(iaAddr.getValidEndTime().getTime());
            ps.setTimestamp(4, vts, Util.GMT_CALENDAR);
            ps.setByte(5, iaAddr.getState());
            ps.setLong(6, iaAddr.getIdentityAssocId());
            return ps;
        }
    }, newKey);
    Number newId = newKey.getKey();
    if (newId != null) {
        iaAddr.setId(newId.longValue());
    }
}

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

public void create(final IaPrefix iaPrefix) {
    /**/*from  ww  w  .java  2  s  . com*/
     * 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
     */
    GeneratedKeyHolder newKey = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        @Override
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(
                    "insert into iaprefix" + " (prefixaddress, prefixlength, starttime, preferredendtime,"
                            + " validendtime, state, identityassoc_id)" + " values (?, ?, ?, ?, ?, ?, ?)",
                    PreparedStatement.RETURN_GENERATED_KEYS);
            ps.setBytes(1, iaPrefix.getIpAddress().getAddress());
            ps.setInt(2, iaPrefix.getPrefixLength());
            java.sql.Timestamp sts = new java.sql.Timestamp(iaPrefix.getStartTime().getTime());
            ps.setTimestamp(3, sts, Util.GMT_CALENDAR);
            java.sql.Timestamp pts = new java.sql.Timestamp(iaPrefix.getPreferredEndTime().getTime());
            ps.setTimestamp(4, pts, Util.GMT_CALENDAR);
            java.sql.Timestamp vts = new java.sql.Timestamp(iaPrefix.getValidEndTime().getTime());
            ps.setTimestamp(5, vts, Util.GMT_CALENDAR);
            ps.setByte(6, iaPrefix.getState());
            ps.setLong(7, iaPrefix.getIdentityAssocId());
            return ps;
        }
    }, newKey);
    Number newId = newKey.getKey();
    if (newId != null) {
        iaPrefix.setId(newId.longValue());
    }
}

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

@Override
public Photo create(Photo photo) throws DAOException {
    if (photo == null)
        throw new IllegalArgumentException();
    logger.debug("Creating photo {}", photo);

    Map<String, Object> parameters = new HashMap<String, Object>(1);
    parameters.put("path", photo.getPath());
    parameters.put("rating", photo.getData().getRating().ordinal());
    parameters.put("datetime", Timestamp.valueOf(photo.getData().getDatetime()));
    parameters.put("latitude", photo.getData().getLatitude());
    parameters.put("longitude", photo.getData().getLongitude());

    Place place = photo.getData().getPlace();
    parameters.put("place_id", null);
    if (place != null) {
        parameters.put("place_id", place.getId());
    }//from w  ww .  ja  va 2 s.  c om

    Journey journey = photo.getData().getJourney();
    parameters.put("journey_id", null);
    if (journey != null) {
        parameters.put("journey_id", journey.getId());
    }

    Photographer photographer = photo.getData().getPhotographer();
    parameters.put("photographer_id", null);
    if (photographer != null) {
        parameters.put("photographer_id", photographer.getId());
    }

    try {
        Number newId = insertPhoto.executeAndReturnKey(parameters);
        photo.setId((int) newId.longValue());
        return photo;
    } catch (DataAccessException ex) {
        logger.error("Failed to create photo", ex);
        throw new DAOException("Failed to create photo", ex);
    }
}