Example usage for java.lang Number intValue

List of usage examples for java.lang Number intValue

Introduction

In this page you can find the example usage for java.lang Number intValue.

Prototype

public abstract int intValue();

Source Link

Document

Returns the value of the specified number as an int .

Usage

From source file:org.musicrecital.service.impl.PersistentPasswordTokenManagerImpl.java

protected boolean isRecoveryTokenPersisted(final User user, final String token) {
    Number count = jdbcTemplate.queryForObject(selectTokenSql, new Object[] { user.getUsername(), token },
            Integer.class);
    return count != null && count.intValue() == 1;
}

From source file:com.ruihu.easyshop.book.dao.BookDao.java

/**
 * //from ww  w  . j a va2s .c  o m
 * @param cid
 * @return
 * @throws SQLException 
 */
public int findCountByCategory(String cid) throws SQLException {
    String sql = "select count(1) from t_book where cid=?";
    Number cnt = (Number) qr.query(sql, new ScalarHandler(), cid);
    return cnt == null ? 0 : cnt.intValue();
}

From source file:cc.aileron.accessor.TypeConvertorImpl.java

/**
 * default constractor//from  w w w. ja v a  2 s  .c  o m
 */
@Inject
public TypeConvertorImpl() {
    map.put(Boolean.TYPE, new C() {
        @Override
        public Boolean convert(final java.lang.Number number) {
            return number.intValue() != 0;
        }
    });
    map.put(Byte.TYPE, new C() {

        @Override
        public Byte convert(final java.lang.Number number) {
            return number.byteValue();
        }
    });
    map.put(Short.TYPE, new C() {

        @Override
        public Short convert(final java.lang.Number number) {
            return number.shortValue();
        }
    });
    map.put(Integer.TYPE, new C() {
        @Override
        public Integer convert(final java.lang.Number number) {
            return number.intValue();
        }

    });
    map.put(Long.TYPE, new C() {

        @Override
        public Long convert(final java.lang.Number number) {
            return number.longValue();
        }
    });
    map.put(Float.TYPE, new C() {

        @Override
        public Float convert(final java.lang.Number number) {
            return number.floatValue();
        }
    });
    map.put(Double.TYPE, new C() {

        @Override
        public Double convert(final java.lang.Number number) {
            return number.doubleValue();
        }
    });
}

From source file:org.lightadmin.core.util.NumberUtils.java

@SuppressWarnings("unchecked")
public static <T extends Number> T convertNumberToTargetClass(Number number, Class<T> targetClass)
        throws IllegalArgumentException {
    Assert.notNull(number, "Number must not be null");
    Assert.notNull(targetClass, "Target class must not be null");

    if (targetClass.isInstance(number)) {
        return (T) number;
    } else if (targetClass.equals(byte.class)) {
        long value = number.longValue();
        if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }/*from  w w  w.  j  a va  2 s  .c o  m*/
        return (T) new Byte(number.byteValue());
    } else if (targetClass.equals(short.class)) {
        long value = number.longValue();
        if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return (T) new Short(number.shortValue());
    } else if (targetClass.equals(int.class)) {
        long value = number.longValue();
        if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return (T) new Integer(number.intValue());
    } else if (targetClass.equals(long.class)) {
        return (T) new Long(number.longValue());
    } else if (targetClass.equals(float.class)) {
        return (T) Float.valueOf(number.toString());
    } else if (targetClass.equals(double.class)) {
        return (T) Double.valueOf(number.toString());
    } else {
        return org.springframework.util.NumberUtils.convertNumberToTargetClass(number, targetClass);
    }
}

From source file:Ch9TableEditorComposite.java

private void attachLabelProvider(TableViewer viewer) {
    viewer.setLabelProvider(new ITableLabelProvider() {
        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }// w w w.  j a v  a  2s  . com

        public String getColumnText(Object element, int columnIndex) {
            switch (columnIndex) {
            case 0:
                return ((EditableTableItem) element).name;
            case 1:
                Number index = ((EditableTableItem) element).value;
                return VALUE_SET[index.intValue()];
            default:
                return "Invalid column: " + columnIndex;
            }
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void removeListener(ILabelProviderListener lpl) {
        }
    });
}

From source file:eu.dasish.annotation.backend.dao.impl.JdbcTargetDaoTest.java

/**
 * Test of getInternalIDFromURI method, public Number
 * getInternalIDFromURI(UUID externalID);
 *//*from   www.  j  a  va  2  s  . co m*/
@Test
public void testGetInternalIDFRomURI() throws NotInDataBaseException {
    System.out.println("test getInternalIDFromURI");
    jdbcTargetDao.setResourcePath("/api/targets/");
    String uri = "/api/targets/00000000-0000-0000-0000-000000000031";
    Number result = jdbcTargetDao.getInternalIDFromHref(uri);
    assertEquals(1, result.intValue());
}

From source file:acromusashi.stream.component.kestrel.spout.KestrelJsonSpout.java

/**
 * {@inheritDoc}/*from  w ww  .j  a  va 2s  .c o m*/
 */
@SuppressWarnings({ "rawtypes" })
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    super.open(conf, context, collector);

    Number timeout = (Number) conf.get(KESTREL_TIMEOUT);
    this.messageTimeoutMs = (int) TimeUnit.SECONDS.toMillis(timeout.intValue());

    this.restrictWatcher = new RestrictWatcher(this.restrictFilePath);

    // Spout????????Queue?Queue???
    int componentIndex = context.getThisTaskIndex();
    String baseQueueName = getQueueName();
    String queueName = baseQueueName + "_" + componentIndex;
    setQueueName(queueName);
}

From source file:eu.dasish.annotation.backend.dao.impl.JdbcPrincipalDaoTest.java

@Test
public void testAddPrincipal() throws NotInDataBaseException {
    System.out.println("test addPrincipal");
    jdbcPrincipalDao.setResourcePath("/api/principals/");
    String freshPrincipalName = "Guilherme";
    String freshPrincipalEmail = "guisil@mpi.nl";

    Principal freshPrincipal = new Principal();
    freshPrincipal.setDisplayName(freshPrincipalName);
    freshPrincipal.setEMail(freshPrincipalEmail);

    Number result = jdbcPrincipalDao.addPrincipal(freshPrincipal, "secret X");
    assertEquals(12, result.intValue());
    Principal addedPrincipal = jdbcPrincipalDao.getPrincipal(result);
    assertEquals(freshPrincipalName, addedPrincipal.getDisplayName());
    assertEquals(freshPrincipalEmail, addedPrincipal.getEMail());
    assertEquals(addedPrincipal.getHref(), "/api/principals/" + addedPrincipal.getId());

}

From source file:com.github.braully.graph.hn.UndirectedSparseGraphTO.java

public void setPairs(Collection pairs) {
    if (pairs != null) {
        Number n = 0;
        for (Object edge : pairs) {
            if (edge instanceof List) {
                List ed = (List) edge;
                this.addEdge(n, ed.get(0), ed.get(1));
                n = n.intValue() + 1;
            }//w  w  w  .j a  v a2 s .c o  m
        }
    }
}

From source file:com.qwazr.crawler.web.driver.PhantomJSBrowserDriver.java

@Override
public Integer getStatusCode() {
    if (endEntry == null)
        return null;
    Number statusCode = (Number) endEntry.get("status");
    return statusCode == null ? null : statusCode.intValue();
}