Example usage for java.lang Number toString

List of usage examples for java.lang Number toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJFloatEditor.java

public boolean isEditValid() {
    final String S_ProcName = "isEditValid";
    if (!hasValue()) {
        setValue(null);/*from  w w  w.  j av a2  s  . c  o  m*/
        return (true);
    }

    boolean retval = super.isEditValid();
    if (retval) {
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = false;
        } else if (obj instanceof Float) {
            Float v = (Float) obj;
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Double) {
            Double v = (Double) obj;
            Double min = getMinValue().doubleValue();
            Double max = getMaxValue().doubleValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            Float v = new Float(s.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            Float v = new Float(i.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            Float v = new Float(l.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof BigDecimal) {
            BigDecimal b = (BigDecimal) obj;
            Float v = new Float(b.toString());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            Float v = new Float(n.toString());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, BigDecimal, Float, Double or Number");
        }
    }
    return (retval);
}

From source file:org.richfaces.component.UIProgressBar.java

/**
 * Returns context for macrosubstitution
 * /* w  w  w .j  a v  a2  s  .  com*/
 * @param renderer
 * @param percent
 * @return
 */
private JSLiteral getContext(AbstractProgressBarRenderer renderer, Number percent) {
    StringBuffer buffer = new StringBuffer("{");
    buffer.append("value:");
    buffer.append(ScriptUtils.toScript(percent.toString())).append(",");
    buffer.append("minValue:");
    buffer.append(ScriptUtils.toScript(this.getAttributes().get(_minValue).toString())).append(",");
    buffer.append("maxValue:");
    buffer.append(ScriptUtils.toScript(this.getAttributes().get(_maxValue).toString()));

    String parameters = renderer.getParameters(this);
    if (parameters != null) {
        buffer.append(",");
        buffer.append(parameters);
    }
    buffer.append("}");
    return new JSLiteral(buffer.toString());
}

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

@Test
public void testConvertLinkFromIntValue() {
    // A int/long that is wrapped between two at (@) symbols must always
    // convert to a Link
    Number number = Random.getInt();
    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.intValue(), link.intValue());
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJFloatEditor.java

public Float getFloatValue() {
    final String S_ProcName = "getFloatValue";
    Float retval;/*from  w ww  .ja  va  2  s  .co m*/
    String text = getText();
    if ((text == null) || (text.length() <= 0)) {
        retval = null;
    } else {
        if (!isEditValid()) {
            throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName,
                    "Field is not valid");
        }
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = null;
        } else if (obj instanceof Float) {
            Float v = (Float) obj;
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else if (obj instanceof Double) {
            Double v = (Double) obj;
            Double min = getMinValue().doubleValue();
            Double max = getMaxValue().doubleValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = new Float(v.floatValue());
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            Float v = new Float(s.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            Float v = new Float(i.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            Float v = new Float(l.floatValue());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else if (obj instanceof BigDecimal) {
            BigDecimal b = (BigDecimal) obj;
            Float v = new Float(b.toString());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            Float v = new Float(n.toString());
            Float min = getMinValue();
            Float max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0,
                        "EditedValue", v, min, max);
            }
            retval = v;
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number");
        }
    }
    return (retval);
}

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:org.loklak.data.DAO.java

public static void announceNewUserId(Number id) {
    JsonFactory mapcapsule = DAO.user_dump.get("id_str", id.toString());
    JSONObject map = null;/*  www  .  j  av a 2s .  c o m*/
    try {
        map = mapcapsule == null ? null : mapcapsule.getJSON();
    } catch (IOException e) {
    }
    if (map == null)
        newUserIds.add(id);
}

From source file:org.springframework.integration.redis.outbound.RedisCollectionPopulatingMessageHandler.java

private double determineScore(Message<?> message) {
    Object scoreHeader = message.getHeaders().get(RedisHeaders.ZSET_SCORE);
    if (scoreHeader == null) {
        return Double.valueOf(1);
    } else {// w ww .j  av a  2 s .c  o m
        Assert.isInstanceOf(Number.class, scoreHeader,
                "Header " + RedisHeaders.ZSET_SCORE + " must be a Number");
        Number score = (Number) scoreHeader;
        return Double.valueOf(score.toString());
    }
}

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  av a  2s . c om*/
        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:com.streamsets.datacollector.bundles.content.SdcInfoContentGenerator.java

private void writeObject(JsonGenerator jg, Object value) throws IOException {
    if (value == null) {
        jg.writeNull();//from   w w  w . j a v  a2s.  co  m
    } else {
        Class<?> c = value.getClass();
        if (c.isArray()) {
            jg.writeStartArray();
            int len = Array.getLength(value);
            for (int j = 0; j < len; j++) {
                Object item = Array.get(value, j);
                writeObject(jg, item);
            }
            jg.writeEndArray();
        } else if (value instanceof Number) {
            Number n = (Number) value;
            if (value instanceof Double && (((Double) value).isInfinite() || ((Double) value).isNaN())) {
                jg.writeString(n.toString());
            } else {
                jg.writeNumber(n.toString());
            }
        } else if (value instanceof Boolean) {
            Boolean b = (Boolean) value;
            jg.writeBoolean(b);
        } else if (value instanceof CompositeData) {
            CompositeData cds = (CompositeData) value;
            CompositeType comp = cds.getCompositeType();
            Set<String> keys = comp.keySet();
            jg.writeStartObject();
            for (String key : keys) {
                writeAttribute(jg, key, cds.get(key));
            }
            jg.writeEndObject();
        } else if (value instanceof TabularData) {
            TabularData tds = (TabularData) value;
            jg.writeStartArray();
            for (Object entry : tds.values()) {
                writeObject(jg, entry);
            }
            jg.writeEndArray();
        } else if (value instanceof GaugeValue) {
            ((GaugeValue) value).serialize(jg);
        } else {
            jg.writeString(value.toString());
        }
    }
}

From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJNumberEditor.java

public boolean isEditValid() {
    final String S_ProcName = "isEditValid";
    if (!hasValue()) {
        setValue(null);//from www.j  ava 2  s  .c o m
        return (true);
    }

    boolean retval = super.isEditValid();
    if (retval) {
        try {
            commitEdit();
        } catch (ParseException e) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Field is not valid - " + e.getMessage(), e);

        }
        Object obj = getValue();
        if (obj == null) {
            retval = false;
        } else if (obj instanceof Short) {
            Short s = (Short) obj;
            BigDecimal v;
            if (precis > 0) {
                v = new BigDecimal(s.toString() + "." + S_Zeroes.substring(0, precis));
            } else {
                v = new BigDecimal(s.toString());
            }
            BigDecimal min = getMinValue();
            BigDecimal max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Integer) {
            Integer i = (Integer) obj;
            BigDecimal v;
            if (precis > 0) {
                v = new BigDecimal(i.toString() + "." + S_Zeroes.substring(0, precis));
            } else {
                v = new BigDecimal(i.toString());
            }
            BigDecimal min = getMinValue();
            BigDecimal max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Long) {
            Long l = (Long) obj;
            BigDecimal v;
            if (precis > 0) {
                v = new BigDecimal(l.toString() + "." + S_Zeroes.substring(0, precis));
            } else {
                v = new BigDecimal(l.toString());
            }
            BigDecimal min = getMinValue();
            BigDecimal max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof BigDecimal) {
            BigDecimal v = (BigDecimal) obj;
            BigDecimal min = getMinValue();
            BigDecimal max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else if (obj instanceof Number) {
            Number n = (Number) obj;
            BigDecimal v = new BigDecimal(n.toString());
            BigDecimal min = getMinValue();
            BigDecimal max = getMaxValue();
            if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) {
                retval = false;
            }
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                    "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number");
        }
    }
    return (retval);
}