List of usage examples for java.lang Number floatValue
public abstract float floatValue();
From source file:com.tibbo.linkserver.plugin.device.file.item.NumericItem.java
private int toInt(Number value) { if (value instanceof Double) { return (new BigDecimal(value.doubleValue())).setScale(0, RoundingMode.HALF_UP).intValue(); }/*from w w w. j ava 2 s. c o m*/ if (value instanceof Float) { return (new BigDecimal(value.floatValue())).setScale(0, RoundingMode.HALF_UP).intValue(); } if (value instanceof BigDecimal) { return ((BigDecimal) value).setScale(0, RoundingMode.HALF_UP).intValue(); } else { return value.intValue(); } }
From source file:org.red5.io.AbstractIOTest.java
@Test public void testNumberFloat() { log.debug("\ntestNumberFloat"); for (Number n : new Number[] { Float.MIN_VALUE, Float.MIN_NORMAL, Float.MAX_VALUE, rnd.nextFloat(), 666.6666f }) {//from w ww . j a v a2s. c om Serializer.serialize(out, n); dumpOutput(); Number rn = Deserializer.deserialize(in, Number.class); assertEquals("Deserialized Float should be the same", (Float) n, (Float) rn.floatValue()); resetOutput(); } }
From source file:com.scit.sling.test.MockValueMap.java
@SuppressWarnings("unchecked") private <T> T convertType(Object o, Class<T> type) { if (o == null) { return null; }/*from w w w .j a va2 s . c om*/ if (o.getClass().isArray() && type.isArray()) { if (type.getComponentType().isAssignableFrom(o.getClass().getComponentType())) { return (T) o; } else { // we need to convert the elements in the array Object array = Array.newInstance(type.getComponentType(), Array.getLength(o)); for (int i = 0; i < Array.getLength(o); i++) { Array.set(array, i, convertType(Array.get(o, i), type.getComponentType())); } return (T) array; } } if (o.getClass().isAssignableFrom(type)) { return (T) o; } if (String.class.isAssignableFrom(type)) { // Format dates if (o instanceof Calendar) { return (T) formatDate((Calendar) o); } else if (o instanceof Date) { return (T) formatDate((Date) o); } else if (o instanceof DateTime) { return (T) formatDate((DateTime) o); } return (T) String.valueOf(o); } else if (o instanceof DateTime) { DateTime dt = (DateTime) o; if (Calendar.class.isAssignableFrom(type)) { return (T) dt.toCalendar(Locale.getDefault()); } else if (Date.class.isAssignableFrom(type)) { return (T) dt.toDate(); } else if (Number.class.isAssignableFrom(type)) { return convertType(dt.getMillis(), type); } } else if (o instanceof Number && Number.class.isAssignableFrom(type)) { if (Byte.class.isAssignableFrom(type)) { return (T) (Byte) ((Number) o).byteValue(); } else if (Double.class.isAssignableFrom(type)) { return (T) (Double) ((Number) o).doubleValue(); } else if (Float.class.isAssignableFrom(type)) { return (T) (Float) ((Number) o).floatValue(); } else if (Integer.class.isAssignableFrom(type)) { return (T) (Integer) ((Number) o).intValue(); } else if (Long.class.isAssignableFrom(type)) { return (T) (Long) ((Number) o).longValue(); } else if (Short.class.isAssignableFrom(type)) { return (T) (Short) ((Number) o).shortValue(); } else if (BigDecimal.class.isAssignableFrom(type)) { return (T) new BigDecimal(o.toString()); } } else if (o instanceof Number && type.isPrimitive()) { final Number num = (Number) o; if (type == byte.class) { return (T) new Byte(num.byteValue()); } else if (type == double.class) { return (T) new Double(num.doubleValue()); } else if (type == float.class) { return (T) new Float(num.floatValue()); } else if (type == int.class) { return (T) new Integer(num.intValue()); } else if (type == long.class) { return (T) new Long(num.longValue()); } else if (type == short.class) { return (T) new Short(num.shortValue()); } } else if (o instanceof String && Number.class.isAssignableFrom(type)) { if (Byte.class.isAssignableFrom(type)) { return (T) new Byte((String) o); } else if (Double.class.isAssignableFrom(type)) { return (T) new Double((String) o); } else if (Float.class.isAssignableFrom(type)) { return (T) new Float((String) o); } else if (Integer.class.isAssignableFrom(type)) { return (T) new Integer((String) o); } else if (Long.class.isAssignableFrom(type)) { return (T) new Long((String) o); } else if (Short.class.isAssignableFrom(type)) { return (T) new Short((String) o); } else if (BigDecimal.class.isAssignableFrom(type)) { return (T) new BigDecimal((String) o); } } throw new NotImplementedException( "Can't handle conversion from " + o.getClass().getName() + " to " + type.getName()); }
From source file:org.richfaces.component.UIProgressBar.java
/** * Converts value attr to number value//from w w w . j av a 2 s . c o m * * @param v - * value attr * @return result */ public Number getNumber(Object v) { Number result = null; if (v != null) { try { if (v instanceof String) { // String result = Double.parseDouble((String) v); } else { Number n = (Number) v; if ((n instanceof BigDecimal) || (n instanceof Double) // Double // or // BigDecimal || (n instanceof Float)) { result = n.floatValue(); } else if (n instanceof Integer || n instanceof Long) { // Integer result = n.longValue(); } } } catch (Exception e) { e.getMessage(); } return result; } return new Integer(0); }
From source file:org.apache.fontbox.cff.CharStringRenderer.java
private void pointSb(Number x, Number y) { sidebearingPoint = new Point2D.Float(x.floatValue(), y.floatValue()); }
From source file:com.weibo.api.motan.rpc.URL.java
public Float getFloatParameter(String name, float defaultValue) { Number n = getNumbers().get(name); if (n != null) { return n.floatValue(); }//from w ww.j a v a 2 s . c o m String value = parameters.get(name); if (value == null || value.length() == 0) { return defaultValue; } float f = Float.parseFloat(value); getNumbers().put(name, f); return f; }
From source file:com.weibo.api.motan.rpc.URL.java
public Float getMethodParameter(String methodName, String paramDesc, String name, float defaultValue) { String key = methodName + "(" + paramDesc + ")." + name; Number n = getNumbers().get(key); if (n != null) { return n.floatValue(); }//from w w w . j a v a 2 s .c om String value = getMethodParameter(methodName, paramDesc, name); if (value == null || value.length() == 0) { return defaultValue; } float f = Float.parseFloat(value); getNumbers().put(key, f); return f; }
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 {/*w w w . j a v a2 s .c om*/ 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: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;/*ww w . ja v a 2s . c o m*/ while (litr.hasNext()) { try { 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:org.apache.pdfbox.pdmodel.font.PDType1CFont.java
/** * {@inheritDoc}/*ww w .j a va 2 s . c o m*/ */ public PDMatrix getFontMatrix() { if (fontMatrix == null) { List<Number> numbers = (List<Number>) this.cffFont.getProperty("FontMatrix"); if (numbers != null && numbers.size() == 6) { COSArray array = new COSArray(); for (Number number : numbers) { array.add(new COSFloat(number.floatValue())); } fontMatrix = new PDMatrix(array); } else { super.getFontMatrix(); } } return fontMatrix; }