List of usage examples for java.lang Number longValue
public abstract long longValue();
From source file:com.shenit.commons.utils.AvatarUtils.java
/** * Get Avataer url/*from w w w . j av a 2 s. c om*/ * * @param uid * @param width * @param height * @param prefix * @param type * @return */ public static String getAvatarURI(Number uid, Number width, Number height, String prefix, AvatarIdTypeEnum type) { if (ValidationUtils.all(ValidationUtils.NULL, uid, width, height, prefix)) return null; long uidl = uid.longValue(); String hash = null; String path, name; if (type == AvatarIdTypeEnum.YY) { hash = String.valueOf(hashUid(String.valueOf(uidl), false)); path = name = String.valueOf(uid); } else { String hashId = DigestUtils.md5Hex(String.valueOf(uidl)); hash = String.valueOf(hashUid(hashId, true)); path = hashId.substring(0, 2); name = hashId.substring(2); } return String.format(AVATAR_FORMAT, prefix, hash, path, name, width.intValue(), height.intValue()); }
From source file:org.openfaces.component.chart.impl.helpers.ChartInfoUtil.java
private static GridPointInfo getGridPointInfo(XYItemEntity en, Chart chart) { ChartModel model = chart.getModel(); if (model == null) return null; GridPointInfo info = new GridPointInfoImpl(); info.setSeries(new SeriesInfoImpl()); info.getSeries().setIndex(en.getSeriesIndex()); info.setIndex(en.getItem());/*from w w w . j av a2 s . co m*/ ModelInfo modelInfo = new ModelInfo(model); if (!modelInfo.isDataEmpty()) { if (modelInfo.getModelType() == ModelType.Date) { TimeSeriesCollection ds = ModelConverter.toTimeSeriesCollection(chart, modelInfo); Comparable seriesKey = ds.getSeriesKey(en.getSeriesIndex()); Number tupleKey = ds.getX(en.getSeriesIndex(), en.getItem()); if (tupleKey instanceof Long) { info.setKey(new Date(tupleKey.longValue())); } else { info.setKey(tupleKey); } Object tupleValue = ds.getY(en.getSeriesIndex(), en.getItem()); info.setValue(tupleValue); info.getSeries().setKey(seriesKey); } else { XYDataset ds = ModelConverter.toXYSeriesCollection(modelInfo); Comparable seriesKey = ds.getSeriesKey(en.getSeriesIndex()); Number tupleKey = ds.getX(en.getSeriesIndex(), en.getItem()); info.setKey(tupleKey); Object tupleValue = ds.getY(en.getSeriesIndex(), en.getItem()); info.setValue(tupleValue); info.getSeries().setKey(seriesKey); } } return info; }
From source file:gedi.util.MathUtils.java
/** * Throws an exception if n is either a real or to big to be represented by a byte. * @param n//from w ww. ja v a2 s . c o m * @return */ public static long longValueExact(Number n) { if (n instanceof Long || n instanceof Integer || n instanceof Short || n instanceof Byte) return n.longValue(); double d = n.doubleValue(); long l = n.longValue(); if (d == (double) l) { return l; } throw new NumberFormatException(); }
From source file:gedi.util.MathUtils.java
/** * Throws an exception if n is either a real or to big to be represented by a byte. * @param n//from ww w. j a v a2 s.co m * @return */ public static byte byteValueExact(Number n) { if (n instanceof Byte) return n.byteValue(); double d = n.doubleValue(); long l = n.longValue(); if (d == (double) l) { if (l >= Byte.MIN_VALUE && l <= Byte.MAX_VALUE) return (byte) l; } throw new NumberFormatException(); }
From source file:org.codice.ddf.configuration.migration.JsonUtils.java
/** * Retrieves a Json number as a long from the specified Json map given its key. * * @param map the map to retrieve an entry from * @param key the key for the entry to retrieve * @param required <code>true</code> if the entry must exist in the map otherwise an error is * generated; <code>false</code> to return <code>null</code> if it doesn't exist * @return the corresponding Json number as a long or <code>null</code> if it doesn't exist and * <code>required</code> is <code>false</code> * @throws MigrationException if the specified entry is not a Json number or if it doesn't exist * and <code>required</code> is true *///w w w.j ava2s . com public static Long getLongFrom(@Nullable Map<String, Object> map, @Nullable String key, boolean required) { final Number n = JsonUtils.getObjectFrom(Number.class, map, key, required); return (n != null) ? n.longValue() : null; }
From source file:com.alibaba.otter.manager.web.common.NumberFormatUtil.java
public static String formatDelay(Number data) { if (data == null) { return StringUtils.EMPTY; }//w w w . j ava 2s. com long t = data.longValue(); if (t < 0) { return String.valueOf(t); } int hour = 0; int minute = 0; while (t >= 60 * 60 * 1000) { hour++; t -= 60 * 60 * 1000; } while (t >= 60 * 1000) { minute++; t -= 60 * 1000; } List<String> result = new ArrayList<String>(); if (hour > 0) { result.add(hour + " h"); } if (minute > 0) { result.add(minute + " m"); } if (t > 0) { DecimalFormat format = new DecimalFormat(PATTERN); result.add(format.format((t * 1.0) / 1000) + " s"); } if (result.size() == 0) { return "0"; } return StringUtils.join(result, " "); }
From source file:com.redhat.rhn.domain.server.ServerGroupFactory.java
/** * Returns the servers of a given serverGroup. * @param sg the serverGroup to find the servers of * @return list of Server objects that are part of * the server group *//*from w ww . jav a 2s .c om*/ public static List<Server> listServers(ServerGroup sg) { Map<String, Object> params = new HashMap<String, Object>(); params.put("sgid", sg.getId()); params.put("org_id", sg.getOrg().getId()); List<Number> ids = SINGLETON.listObjectsByNamedQuery("ServerGroup.lookupServerIds", params); List<Long> serverIds = new ArrayList<Long>(); for (Number n : ids) { serverIds.add(new Long(n.longValue())); } return ServerFactory.lookupByIds(serverIds); }
From source file:gedi.util.MathUtils.java
/** * Throws an exception if n is either a real or to big to be represented by a byte. * @param n/*from ww w.j av a2s . c o m*/ * @return */ public static short shortValueExact(Number n) { if (n instanceof Short || n instanceof Byte) return n.shortValue(); double d = n.doubleValue(); long l = n.longValue(); if (d == (double) l) { if (l >= Short.MIN_VALUE && l <= Short.MAX_VALUE) return (short) l; } throw new NumberFormatException(); }
From source file:org.eclipse.jubula.client.core.persistence.TestResultPM.java
/** * @param session/*from w ww .ja va2 s. c o m*/ * The session in which to execute the Persistence (JPA / * EclipseLink) query. * @param summaryId * The database ID of the summary for which to compute the * corresponding Test Result nodes. * @return the Test Result nodes associated with the given Test Result * Summary, sorted by sequence (ascending). */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static boolean hasTestResultDetails(EntityManager session, Long summaryId) { boolean hasDetails = false; if (session == null) { return hasDetails; } CriteriaBuilder builder = session.getCriteriaBuilder(); CriteriaQuery query = builder.createQuery(); Root from = query.from(PoMaker.getTestResultClass()); query.select(builder.count(from)).where(builder.equal(from.get("internalTestResultSummaryID"), summaryId)); //$NON-NLS-1$ Number result = (Number) session.createQuery(query).getSingleResult(); if (result.longValue() > 0) { hasDetails = true; } return hasDetails; }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Comparable<?> convertTo(Class<?> clazz, Object obj) { if (obj == null) { return null; }//from w w w . j a v a 2s .co m if (clazz.isAssignableFrom(obj.getClass())) { return (Comparable<?>) obj; } if (clazz.isPrimitive()) { if (clazz.equals(Long.TYPE)) { clazz = Long.class; } else if (clazz.equals(Integer.TYPE)) { clazz = Integer.class; } else if (clazz.equals(Float.TYPE)) { clazz = Float.class; } else if (clazz.equals(Double.TYPE)) { clazz = Double.class; } else if (clazz.equals(Boolean.TYPE)) { clazz = Boolean.class; } } if (Number.class.isAssignableFrom(clazz)) { if (obj.getClass().equals(String.class)) { obj = new Double((String) obj); } if (!Number.class.isAssignableFrom(obj.getClass())) { throw new RuntimeException( "Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); } Number number = (Number) obj; if (clazz.equals(Long.class)) { return new Long(number.longValue()); } if (clazz.equals(Integer.class)) { return new Integer(number.intValue()); } if (clazz.equals(Float.class)) { return new Float(number.floatValue()); } if (clazz.equals(Double.class)) { return new Double(number.doubleValue()); } if (clazz.equals(BigDecimal.class)) { return new BigDecimal(number.doubleValue()); } } final String oStr = String.valueOf(obj); if (clazz.equals(String.class)) { return oStr; } if (clazz.equals(java.util.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(java.sql.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(Boolean.class)) { return new Boolean(oStr); } throw new RuntimeException("Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); }