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:api.Client.java

public Request<OrderSearchResult> getOrdersOrderApiService(Number storeId, String token, Number limit,
        Number offset, String couponCode, Number orderNumber, Number totalFrom, Number totalTo, String customer,
        String createdFrom, String createdTo, String paymentMethod, String vendorNumber, String shippingMethod,
        String keywords, String fulfillmentStatus, String paymentStatus, String updatedFrom, String updatedTo) {
    try {//from w w  w. j av  a 2s. c  o  m
        URIBuilder builder = new URIBuilder(url + "/" + storeId + "/orders");
        if (token != null)
            builder.setParameter("token", token.toString());
        if (limit != null)
            builder.setParameter("limit", limit.toString());
        if (offset != null)
            builder.setParameter("offset", offset.toString());
        if (couponCode != null)
            builder.setParameter("couponCode", couponCode.toString());
        if (orderNumber != null)
            builder.setParameter("orderNumber", orderNumber.toString());
        if (totalFrom != null)
            builder.setParameter("totalFrom", totalFrom.toString());
        if (totalTo != null)
            builder.setParameter("totalTo", totalTo.toString());
        if (customer != null)
            builder.setParameter("customer", customer.toString());
        if (createdFrom != null)
            builder.setParameter("createdFrom", createdFrom.toString());
        if (createdTo != null)
            builder.setParameter("createdTo", createdTo.toString());
        if (paymentMethod != null)
            builder.setParameter("paymentMethod", paymentMethod.toString());
        if (vendorNumber != null)
            builder.setParameter("vendorNumber", vendorNumber.toString());
        if (shippingMethod != null)
            builder.setParameter("shippingMethod", shippingMethod.toString());
        if (keywords != null)
            builder.setParameter("keywords", keywords.toString());
        if (fulfillmentStatus != null)
            builder.setParameter("fulfillmentStatus", fulfillmentStatus.toString());
        if (paymentStatus != null)
            builder.setParameter("paymentStatus", paymentStatus.toString());
        if (updatedFrom != null)
            builder.setParameter("updatedFrom", updatedFrom.toString());
        if (updatedTo != null)
            builder.setParameter("updatedTo", updatedTo.toString());

        if (storeId == null)
            throw new IllegalArgumentException("No parameter storeId is set");

        return new Request<OrderSearchResult>(getRequestExecutor(), builder.build()) {
            @Override
            public OrderSearchResult execute(RequestExecutor executor) throws IOException, JSONException {
                HttpGet method = new HttpGet(uri);
                try {
                    HttpResponse response = executor.execute(method);
                    if (response.getStatusLine().getStatusCode() >= 400) {
                        throw new IOException("Unexpected HTTP status: " + response.getStatusLine());
                    }
                    HttpEntity entity = response.getEntity();
                    if (entity == null)
                        throw new JSONException("No response. Expected JSON object.");
                    return new OrderSearchResult(new JSONObject(EntityUtils.toString(entity)));

                } finally {
                    method.releaseConnection();
                }
            }
        };
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:javadz.beanutils.converters.NumberConverter.java

/**
 * Convert any Number object to the specified type for this
 * <i>Converter</i>.//ww w. jav a  2s . co  m
 * <p>
 * This method handles conversion to the following types:
 * <ul>
 *     <li><code>java.lang.Byte</code></li>
 *     <li><code>java.lang.Short</code></li>
 *     <li><code>java.lang.Integer</code></li>
 *     <li><code>java.lang.Long</code></li>
 *     <li><code>java.lang.Float</code></li>
 *     <li><code>java.lang.Double</code></li>
 *     <li><code>java.math.BigDecimal</code></li>
 *     <li><code>java.math.BigInteger</code></li>
 * </ul>
 * @param sourceType The type being converted from
 * @param targetType The Number type to convert to
 * @param value The Number to convert.
 *
 * @return The converted value.
 */
private Number toNumber(Class sourceType, Class targetType, Number value) {

    // Correct Number type already
    if (targetType.equals(value.getClass())) {
        return value;
    }

    // Byte
    if (targetType.equals(Byte.class)) {
        long longValue = value.longValue();
        if (longValue > Byte.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Byte.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Byte(value.byteValue());
    }

    // Short
    if (targetType.equals(Short.class)) {
        long longValue = value.longValue();
        if (longValue > Short.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Short.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Short(value.shortValue());
    }

    // Integer
    if (targetType.equals(Integer.class)) {
        long longValue = value.longValue();
        if (longValue > Integer.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        if (longValue < Integer.MIN_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too small " + toString(targetType));
        }
        return new Integer(value.intValue());
    }

    // Long
    if (targetType.equals(Long.class)) {
        return new Long(value.longValue());
    }

    // Float
    if (targetType.equals(Float.class)) {
        if (value.doubleValue() > Float.MAX_VALUE) {
            throw new ConversionException(
                    toString(sourceType) + " value '" + value + "' is too large for " + toString(targetType));
        }
        return new Float(value.floatValue());
    }

    // Double
    if (targetType.equals(Double.class)) {
        return new Double(value.doubleValue());
    }

    // BigDecimal
    if (targetType.equals(BigDecimal.class)) {
        if (value instanceof Float || value instanceof Double) {
            return new BigDecimal(value.toString());
        } else if (value instanceof BigInteger) {
            return new BigDecimal((BigInteger) value);
        } else {
            return BigDecimal.valueOf(value.longValue());
        }
    }

    // BigInteger
    if (targetType.equals(BigInteger.class)) {
        if (value instanceof BigDecimal) {
            return ((BigDecimal) value).toBigInteger();
        } else {
            return BigInteger.valueOf(value.longValue());
        }
    }

    String msg = toString(getClass()) + " cannot handle conversion to '" + toString(targetType) + "'";
    if (log().isWarnEnabled()) {
        log().warn("    " + msg);
    }
    throw new ConversionException(msg);

}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

/**
 * @return a count of the digits in the specified number
 *//*from   w  w  w. j a  v  a  2 s.c om*/
protected int countDigits(Number number) {
    int numDigits = 0;

    if (number != null) {
        // Remove everything that's not a digit (e.g., decimal points or signs)
        String digitsOnly = number.toString().replaceAll("\\D", EMPTY_PATH);
        numDigits = digitsOnly.length();
    }

    return numDigits;
}

From source file:net.storyspace.StorySpace.java

/**
 * Use twitlonger.com to post a lengthy speakup. See twitlonger.com for more
 * details on their service.//from  w  w w  . ja va 2  s  . c om
 * <p>
 * Note: You need to have called {@link #setupTwitlonger(String, String)}
 * before calling this.
 * 
 * @param message
 * @param inReplyToStatusId Can be null if this isn't a reply
 * @return A StorySpace status using a truncated message with a link to
 *         twitlonger.com
 * @see #setupTwitlonger(String, String)
 */
public Status updateLongStatus(String message, Number inReplyToStatusId) {
    if (twitlongerApiKey == null || twitlongerAppName == null) {
        throw new IllegalStateException(
                "Twitlonger api details have not been set! Call #setupTwitlonger() first.");
    }
    if (message.length() < 141) {
        throw new IllegalArgumentException(
                "Message too short (" + inReplyToStatusId + " chars). Just post a normal StorySpace status. ");
    }
    String url = "http://www.twitlonger.com/api_post";
    Map<String, String> vars = asMap("application", twitlongerAppName, "api_key", twitlongerApiKey, "username",
            name, "message", message);
    if (inReplyToStatusId != null) {
        assert inReplyToStatusId.doubleValue() != 0 && inReplyToStatusId.doubleValue() != -1; // FIXME remove
        vars.put("in_reply", inReplyToStatusId.toString());
    }
    // ?? set direct_message 0/1 as appropriate if allowing long DMs
    String response = http.post(url, vars, false);
    Matcher m = contentTag.matcher(response);
    boolean ok = m.find();
    if (!ok) {
        throw new StorySpaceException.TwitLongerException("TwitLonger call failed", response);
    }
    String shortMsg = m.group(1).trim();

    // Post to StorySpace
    Status s = updateStatus(shortMsg, inReplyToStatusId);

    m = idTag.matcher(response);
    ok = m.find();
    if (!ok) {
        // weird - but oh well
        return s;
    }
    String id = m.group(1);

    // Once a message has been successfully posted to Twitlonger and
    // StorySpace, it would be really useful to send back the StorySpace ID for
    // the message. This will allow users to manage their Twitlonger posts
    // and delete not only the Twitlonger post, but also the StorySpace post
    // associated with it. It will also makes replies much more effective.
    try {
        url = "http://www.twitlonger.com/api_set_id";
        vars.remove("message");
        vars.remove("in_reply");
        vars.remove("username");
        vars.put("message_id", "" + id);
        vars.put("StorySpace_id", "" + s.getId());
        http.post(url, vars, false);
    } catch (Exception e) {
        // oh well
    }

    // done
    return s;
}

From source file:net.storyspace.StorySpace.java

/**
 * Updates the authenticating user's status and marks it as a reply to the
 * speakup with the given ID./*  w  ww  .  j a  v a2  s .  c  o m*/
 * 
 * @param statusText
 *            The text of your status update. Must not be more than 160
 *            characters and should not be more than 140 characters to
 *            ensure optimal display.
 * 
 * 
 * @param inReplyToStatusId
 *            The ID of the speakup that this speakup is in response to. The
 *            statusText must contain the username (with an "@" prefix) of
 *            the owner of the speakup being replied to for for StorySpace to
 *            agree to mark the speakup as a reply. <i>null</i> to leave this
 *            unset.
 * 
 * @return The posted status when successful.
 *         <p>
 *         Warning: the microformat for direct messages is supported. BUT:
 *         the return value from this method will be null, and not the
 *         direct message. Other microformats (such as follow) may result in
 *         an exception being thrown.
 * 
 * @throws StorySpaceException
 *             if something goes wrong. There is a rare (but not rare
 *             enough) bug whereby StorySpace occasionally returns a success
 *             code but the wrong speakup. If this happens, the update may or
 *             may not have worked - wait a bit & check.
 */
public Status updateStatus(String statusText, Number inReplyToStatusId) throws StorySpaceException {
    // should we trim statusText??
    if (statusText.length() > 160) {
        throw new IllegalArgumentException(
                "Status text must be 160 characters or less: " + statusText.length() + " " + statusText);
    }
    Map<String, String> vars = asMap("status", statusText);

    // add in long/lat if set
    if (myLatLong != null) {
        vars.put("lat", Double.toString(myLatLong[0]));
        vars.put("long", Double.toString(myLatLong[1]));
    }

    if (sourceApp != null)
        vars.put("source", sourceApp);
    if (inReplyToStatusId != null) {
        // TODO remove this legacy check
        double v = inReplyToStatusId.doubleValue();
        assert v != 0 && v != -1;
        vars.put("in_reply_to_status_id", inReplyToStatusId.toString());
    }
    String result;
    try {
        result = http.post(StorySpace_URL + "/statuses/update.json", vars, true);
    } catch (E403 e) {
        // test for repetition (which gets a 403)
        Status s = getStatus();
        if (s != null && s.getText().equals(statusText)) {
            throw new StorySpaceException.Repetition(s.getText());
        }
        throw e;
    }
    try {
        Status s = new Status(new JSONObject(result), null);
        // sanity check
        String targetText = statusText.trim();
        String returnedStatusText = s.text.trim();
        if (returnedStatusText.equals(targetText))
            return s;
        // weird bug: StorySpace occasionally rejects speakups?
        String st = statusText.toLowerCase();
        // is it a direct message? - which doesn't return the true status
        if (st.startsWith("dm") || st.startsWith("d")) {
            return null;
        }
        // try waiting and rechecking - maybe it did work after all
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            // igore the interruption & just report the weirdness
            throw new StorySpaceException.Unexplained("Unexplained failure for speakup: expected \""
                    + statusText + "\" but got " + returnedStatusText);
        }
        Status s2 = getStatus();
        if (s2 != null && targetText.equals(s2.text)) {
            // Log.report("Weird transitory bug in StorySpace update status with "+targetText);
            return s2;
        }
        throw new StorySpaceException.Unexplained(
                "Unexplained failure for speakup: expected \"" + statusText + "\" but got " + s2);
    } catch (JSONException e) {
        throw new StorySpaceException.Parsing(result, e);
    }
}

From source file:pcgen.core.Equipment.java

/**
 * Calculate the parts of the cost for the equipment's head that are 
 * affected by size./*from  w w w .  j a v  a 2s . c o  m*/
 *  
 * @param aPC The character who owns the equipment.
 * @param primaryHead Are we calculating for the primary or alternate head.
 * @return The cost of the head
 */
private BigDecimal getPreSizingCostForHead(final PlayerCharacter aPC, boolean primaryHead) {
    BigDecimal c = BigDecimal.ZERO;
    EquipmentHead head = getEquipmentHeadReference(primaryHead ? 1 : 2);
    if (head != null) {
        bonusPrimary = primaryHead;
        for (EquipmentModifier eqMod : head.getSafeListFor(ListKey.EQMOD)) {
            int iCount = getSelectCorrectedAssociationCount(eqMod);

            if (iCount < 1) {
                iCount = 1;
            }

            Formula baseCost = eqMod.getSafe(FormulaKey.BASECOST);
            Number bc = baseCost.resolve(this, primaryHead, aPC, "");
            final BigDecimal eqModCost = new BigDecimal(bc.toString());
            c = c.add(eqModCost
                    .multiply(new BigDecimal(Integer.toString(getSafe(IntegerKey.BASE_QUANTITY) * iCount))));
            c = c.add(EqModCost.addItemCosts(eqMod, aPC, "ITEMCOST", getSafe(IntegerKey.BASE_QUANTITY) * iCount,
                    this));
        }
    }
    return c;
}

From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java

/**
 * Set the given value as a parameter to the statement.
 *//* w  w  w  .j  a  va  2 s.c o  m*/
public void setNumber(PreparedStatement stmnt, int idx, Number num, Column col) throws SQLException {
    // check for known floating point types to give driver a chance to
    // handle special numbers like NaN and infinity; bug #1053
    if (num instanceof Double)
        setDouble(stmnt, idx, ((Double) num).doubleValue(), col);
    else if (num instanceof Float)
        setFloat(stmnt, idx, ((Float) num).floatValue(), col);
    else
        setBigDecimal(stmnt, idx, new BigDecimal(num.toString()), col);
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils.NumberObject}
 *//*from ww  w . j  av  a2  s  . c  o  m*/
@SuppressWarnings("unchecked")
@Test
public void NumberObjectTest() {
    try {
        Class<?> numberObject = ClassLoader.getSystemClassLoader()
                .loadClass(NumberUtils.class.getName() + "$NumberObject");

        Constructor<?> c = numberObject.getDeclaredConstructor(Class.class);
        c.setAccessible(true);

        Method ofType = numberObject.getMethod("of", Class.class);
        ofType.setAccessible(true);

        Method ofN = numberObject.getMethod("of", Number.class);
        ofN.setAccessible(true);

        Method parsable = numberObject.getDeclaredMethod("parsable", Number.class);
        parsable.setAccessible(true);

        Method contains = numberObject.getDeclaredMethod("contains", Number.class);
        contains.setAccessible(true);

        Method valueOf = numberObject.getDeclaredMethod("valueOf", Number.class);
        valueOf.setAccessible(true);

        for (Class<?> type : NUMBERS) {
            Object o = c.newInstance(type);
            Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type);
            Object numob = ofType.invoke(null, type);
            assertEquals("ofType: " + type.getSimpleName(), o, numob);
            Number n = null;
            if (!type.isPrimitive()) {
                if (ClassUtils.isPrimitiveWrapper(type)) {
                    n = (Number) ClassUtils.primitiveToWrapper(type).getMethod("valueOf", String.class)
                            .invoke(null, "1");
                } else {
                    n = (Number) type.getField("ONE").get(null);
                }
                if (type.equals(byte.class))
                    assertEquals("ofN: 1: " + type.getSimpleName(), o, ofN.invoke(null, n));
            }
            assertEquals("parsable: -1: " + type.getSimpleName(), true, parsable.invoke(numob, -1));
            assertEquals("parsable: 0: " + type.getSimpleName(), true, parsable.invoke(numob, 0));
            assertEquals("parsable: 1: " + type.getSimpleName(), true, parsable.invoke(numob, 1));

            assertEquals("parsable: null: " + type.getSimpleName(), !type.isPrimitive(),
                    parsable.invoke(numob, (Number) null));

            Object expected = ObjectUtils.isAny(wrapper, Float.class, Double.class, BigDecimal.class,
                    BigInteger.class);
            assertEquals("parsable: Infinity: Double: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Double.POSITIVE_INFINITY));
            assertEquals("parsable: Infinity: Double: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE));
            assertEquals("parsable: Infinity: Double: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE.toBigInteger()));
            assertEquals("parsable: Infinity: Float: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Float.POSITIVE_INFINITY));
            assertEquals("parsable: Infinity: Float: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT));
            assertEquals("parsable: Infinity: Float: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT.toBigInteger()));
            assertEquals("parsable: -Infinity: Double: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Double.NEGATIVE_INFINITY));
            assertEquals("parsable: -Infinity: Double: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE.negate()));
            assertEquals("parsable: -Infinity: Double: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_DOUBLE.negate().toBigInteger()));
            assertEquals("parsable: -Infinity: Float: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Float.NEGATIVE_INFINITY));
            assertEquals("parsable: -Infinity: Float: BigDecimal: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT.negate()));
            assertEquals("parsable: -Infinity: Float: BigInteger: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, INFINITY_FLOAT.negate().toBigInteger()));

            expected = ObjectUtils.isAny(wrapper, Float.class, Double.class);
            assertEquals("parsable: NaN: Float: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Float.NaN));
            assertEquals("parsable: NaN: Double: " + type.getSimpleName(), expected,
                    parsable.invoke(numob, Double.NaN));

            if (Byte.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getByte(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getByte(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Short.MIN_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Short.MAX_VALUE));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123.456f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getByte(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getByte(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, Short.MIN_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Short.MAX_VALUE));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123.456f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 1234.56f));
            }
            if (Short.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getShort(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getShort(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Integer.MIN_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Integer.MAX_VALUE));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123.456f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getShort(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getShort(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, Integer.MIN_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Integer.MAX_VALUE));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 12345.6f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 123456.789f));
            }
            if (Integer.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getInt(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getInt(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Long.MIN_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Long.MAX_VALUE));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123456.789f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getInt(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getInt(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, Long.MIN_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Long.MAX_VALUE));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123456.789f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 12345678912345678912.3456d));
            }
            if (Long.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MIN_VALUE").getLong(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getLong(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), false,
                        parsable.invoke(numob, BigInteger.valueOf(Long.MIN_VALUE).pow(2)));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, BigInteger.valueOf(Long.MAX_VALUE).pow(2)));
                assertEquals("parsable: fraction: " + type.getSimpleName(), false,
                        parsable.invoke(numob, 123.456f));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MIN_VALUE").getLong(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getLong(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, BigInteger.valueOf(Long.MIN_VALUE).pow(2)));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, BigInteger.valueOf(Long.MAX_VALUE).pow(2)));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123456.789f));
                assertEquals("contains: overflow: fraction: " + type.getSimpleName(), false,
                        contains.invoke(numob, 12345678912345678912.3456f));
            }
            if (Float.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, -wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, -Double.MAX_VALUE));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), false,
                        parsable.invoke(numob, Double.MAX_VALUE));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, -wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getFloat(null)));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, -Double.MAX_VALUE));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, Double.MAX_VALUE));
            }
            if (Double.class.equals(wrapper)) {
                assertEquals("parsable: contains: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, -wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("parsable: contains: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("parsable: overflow: min: " + type.getSimpleName(), true,
                        parsable.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN).negate()));
                assertEquals("parsable: overflow: max: " + type.getSimpleName(), true,
                        parsable.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN)));

                assertEquals("contains: min: " + type.getSimpleName(), true,
                        contains.invoke(numob, -wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("contains: max: " + type.getSimpleName(), true,
                        contains.invoke(numob, wrapper.getField("MAX_VALUE").getDouble(null)));
                assertEquals("contains: overflow: min: " + type.getSimpleName(), false,
                        contains.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN).negate()));
                assertEquals("contains: overflow: max: " + type.getSimpleName(), false,
                        contains.invoke(numob, INFINITY_DOUBLE.multiply(BigDecimal.TEN)));
            }
            if (!ClassUtils.isPrimitiveWrapper(wrapper)) {
                assertEquals("parsable: fraction: " + type.getSimpleName(), BigDecimal.class.equals(type),
                        parsable.invoke(numob, 123.456f));
                assertEquals("contains: fraction: " + type.getSimpleName(), true,
                        contains.invoke(numob, 123.456f));
            }

            if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, "123");
            } else {
                expected = new BigDecimal("123");
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            for (Class<?> valueType : OBJECTS) {
                if (ClassUtils.isPrimitiveWrapper(valueType)) {
                    n = (Number) valueType.getMethod("valueOf", String.class).invoke(null, "123");
                } else {
                    n = new BigDecimal("123");
                    if (BigInteger.class.equals(valueType))
                        n = ((BigDecimal) n).toBigInteger();
                }
                assertEquals(
                        "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): " + type.getSimpleName(),
                        expected, valueOf.invoke(numob, n));
                assertEquals(
                        "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): class: "
                                + type.getSimpleName(),
                        expected.getClass(), valueOf.invoke(numob, n).getClass());
            }

            n = 123.456f;
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, n.toString());
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null,
                        Integer.toString(((Float) n).intValue()));
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: " + n + " (" + n.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    expected, valueOf.invoke(numob, n));
            assertEquals(
                    "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): class: " + type.getSimpleName(),
                    expected.getClass(), valueOf.invoke(numob, n).getClass());

            n = 1.23456789E-6d;
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null, n.toString());
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getMethod("valueOf", String.class).invoke(null,
                        Integer.toString(((Double) n).intValue()));
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: " + n + " (" + n.getClass().getSimpleName() + "): " + type.getSimpleName(),
                    expected, valueOf.invoke(numob, n));
            assertEquals(
                    "valueOf: " + n + " (" + n.getClass().getSimpleName() + "): class: " + type.getSimpleName(),
                    expected.getClass(), valueOf.invoke(numob, n).getClass());

            n = INFINITY_DOUBLE.pow(2);
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getField("POSITIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MAX_VALUE").get(null);
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: Huge: " + type.getSimpleName(), expected, valueOf.invoke(numob, n));
            assertEquals("valueOf: Huge: class: " + type.getSimpleName(), expected.getClass(),
                    valueOf.invoke(numob, n).getClass());

            n = INFINITY_DOUBLE.pow(2).negate();
            if (ObjectUtils.isAny(wrapper, Float.class, Double.class)) {
                expected = wrapper.getField("NEGATIVE_INFINITY").get(null);
            } else if (ClassUtils.isPrimitiveWrapper(wrapper)) {
                expected = wrapper.getField("MIN_VALUE").get(null);
            } else {
                expected = new BigDecimal(n.toString());
                if (BigInteger.class.equals(wrapper))
                    expected = ((BigDecimal) expected).toBigInteger();
            }
            assertEquals("valueOf: Huge: negative: " + type.getSimpleName(), expected,
                    valueOf.invoke(numob, n));
            assertEquals("valueOf: Huge: negative: class: " + type.getSimpleName(), expected.getClass(),
                    valueOf.invoke(numob, n).getClass());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
    }
}