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:fi.csc.kapaVirtaAS.MessageTransformer.java

public String createAuthenticationString(String message) {
    try {/*from   ww w.j a v  a  2  s .  c  o  m*/
        DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = dBuilder
                .parse(new InputSource(new ByteArrayInputStream(stripXmlDefinition(message).getBytes())));
        doc.setXmlVersion("1.0");
        doc.normalizeDocument();

        Optional<NodeList> headerNodes = getChildByKeyword(
                nodeListToStream(doc.getDocumentElement().getChildNodes()), "header");
        Optional<NodeList> clientHeaders = headerNodes
                .map(nodeList -> getChildByKeyword(nodeListToStream(nodeList), "client"))
                .orElse(Optional.empty());

        Number l = clientHeaders.get().getLength();
        l.toString();

        return clientHeaders
                .map(nodeList -> getNodeByKeyword(nodeListToStream(nodeList), "xRoadInstance")
                        .map(node -> node.getTextContent()))
                .orElse(Optional.empty()).orElse("")
                + ":"
                + clientHeaders.map(nodeList -> getNodeByKeyword(nodeListToStream(nodeList), "memberClass")
                        .map(node -> node.getTextContent())).orElse(Optional.empty()).orElse("")
                + ":"
                + clientHeaders.map(nodeList -> getNodeByKeyword(nodeListToStream(nodeList), "memberCode")
                        .map(node -> node.getTextContent())).orElse(Optional.empty()).orElse("")
                + ":"
                + clientHeaders.map(nodeList -> getNodeByKeyword(nodeListToStream(nodeList), "subsystemCode")
                        .map(node -> node.getTextContent())).orElse(Optional.empty()).orElse("");
    } catch (Exception e) {
        log.error("Error in parsing authenticationstring");
        log.error(e.toString());
        return "";
    }
}

From source file:org.opengroupware.logic.blobs.OGoRangeDirBlobStore.java

public File blobFileForId(Number _id, Number _containerId, String _ext) {
    if (_id == null)
        return null;

    File container = null;//from   ww  w.  java2  s  . co m

    /* container */

    if (_containerId != null) {
        container = new File(this.root, _containerId.toString());
        if (!container.exists()) {
            if (!container.mkdir()) {
                /* probably a permission setup issue */
                log.error("could not create BLOB directory for container '" + _containerId + "': " + container
                        + " (check filesystem permissions!)");
                return null;
            }
        }
    } else
        container = this.root;

    /* folder ranges */

    if (UseFoldersForIDRanges) {
        long rangeId = _id.longValue();
        rangeId = rangeId - (rangeId % this.rangeSize);

        container = new File(container, Long.toString(rangeId));
        if (!container.exists()) {
            if (!container.mkdir()) {
                /* probably a permission setup issue */
                log.error("could not create BLOB directory for id-range '" + rangeId + "': " + container
                        + " (check filesystem permissions!)");
                return null;
            }
        }
    }

    /* filename */

    final StringBuilder sb = new StringBuilder(128);
    sb.append(_id);
    if (_ext != null && _ext.length() > 0) {
        sb.append('.');
        sb.append(_ext);
    }

    return new File(container, sb.toString());
}

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

/**
 * {@link java.lang.Double#isInfinite()}.
 *
 * @param o the object, number or string.
 * @param signum return {@code n == -Infinity} if {@code signum < 0}. if {@code signum > 0}, return {@code n == Infinity}.
 * @return {@code == Infinity}./*from  www .  j  a v a2s  . c om*/
 */
public static boolean isInfinite(final Object o, final int signum) {
    Number n = valueOf(o);
    if (n == null)
        return false;
    if (!ObjectUtils.isAny(n, double.class, Double.class, float.class, Float.class))
        return false;
    if (n.toString().equalsIgnoreCase(signum < 0 ? "-Infinity" : "Infinity"))
        return true;
    if (signum > 0 && Double.POSITIVE_INFINITY == Double.valueOf(n.toString()))
        return true;
    if (signum < 0 && Double.NEGATIVE_INFINITY == Double.valueOf(n.toString()))
        return true;
    if (signum == 0 && Double.valueOf(n.toString()).isInfinite())
        return true;

    return false;
}

From source file:com.xpn.xwiki.objects.classes.NumberClass.java

@Override
public void displaySearch(StringBuffer buffer, String name, String prefix, XWikiCriteria criteria,
        XWikiContext context) {/*from   w w  w .  ja  v  a 2s  .  c  o  m*/
    input input1 = new input();
    input1.setType("text");
    input1.setName(prefix + name + "_morethan");
    input1.setID(prefix + name);
    input1.setSize(getSize());
    String fieldFullName = getFieldFullName();
    Number value = (Number) criteria.getParameter(fieldFullName + "_morethan");
    if (value != null) {
        input1.setValue(value.toString());
    }

    input input2 = new input();

    input2.setType("text");
    input2.setName(prefix + name + "_lessthan");
    input2.setID(prefix + name);
    input2.setSize(getSize());
    value = (Number) criteria.getParameter(fieldFullName + "_lessthan");
    if (value != null) {
        input2.setValue(value.toString());
    }

    XWikiMessageTool msg = context.getMessageTool();
    buffer.append((msg == null) ? "from" : msg.get("from"));
    buffer.append(input1.toString());
    buffer.append((msg == null) ? "from" : msg.get("to"));
    buffer.append(input2.toString());
}

From source file:org.getobjects.foundation.NSPropertyListGenerator.java

public boolean appendNumber(Number _s, StringBuilder _sb, int _indent) {
    _sb.append(_s.toString());
    return true;/*from  w w w.  j  ava2 s  .  c om*/
}

From source file:org.dbrain.data.jackson.serializers.JsonLongSerializer.java

@Override
public void serialize(Number value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    if (value != null) {
        long longValue = value.longValue();
        if (longValue >= MIN_VALUE && longValue <= MAX_VALUE) {
            jgen.writeNumber(longValue);
        } else {// www.j  a  v a  2s .  c  o m
            jgen.writeString(value.toString());
        }
    } else {
        jgen.writeNull();
    }
}

From source file:com.xpn.xwiki.objects.classes.NumberClass.java

@Override
public void makeQuery(Map<String, Object> map, String prefix, XWikiCriteria query, List<String> criteriaList) {
    Number value = (Number) map.get(prefix);
    if ((value != null) && (!value.equals(""))) {
        criteriaList.add(getFullQueryPropertyName() + "=" + value.toString());
        return;/*from w w w .  j  a va  2  s .  com*/
    }

    value = (Number) map.get(prefix + "lessthan");
    if ((value != null) && (!value.equals(""))) {
        criteriaList.add(getFullQueryPropertyName() + "<=" + value.toString());
        return;
    }

    value = (Number) map.get(prefix + "morethan");
    if ((value != null) && (!value.equals(""))) {
        criteriaList.add(getFullQueryPropertyName() + ">=" + value.toString());
        return;
    }
}

From source file:org.kuali.rice.core.web.format.CurrencyFormatter.java

/**
 * begin Kuali Foundation modification/*from w  w w  .jav  a 2  s . c  o  m*/
 * Unformats its argument and returns a KualiDecimal instance initialized with the resulting string value
 *
 * @see org.kuali.rice.core.web.format.Formatter#convertToObject(java.lang.String)
 * end Kuali Foundation modification
 */
@Override
protected Object convertToObject(String target) {
    // begin Kuali Foundation modification
    KualiDecimal value = null;

    LOG.debug("convertToObject '" + target + "'");

    if (target != null) {
        target = target.trim();

        String rawString = target;

        // parseable values are $1.23 and ($1.23), not (1.23)
        if (target.startsWith("(")) {
            if (!target.startsWith("($")) {
                target = "($" + StringUtils.substringAfter(target, "(");
            }
        }

        // Insert currency symbol if absent
        if (!(target.startsWith("(") || target.startsWith(getSymbol()))) {
            target = interpolateSymbol(target);
        }

        // preemptively detect non-numeric-related symbols, since NumberFormat.parse seems to be silently deleting them
        // (i.e. 9aaaaaaaaaaaaaaa is silently converted into 9)
        if (!CURRENCY_PATTERN.matcher(target).matches()) {
            throw new FormatException("parsing", RiceKeyConstants.ERROR_CURRENCY, rawString);
        }

        // preemptively detect String with excessive digits after the decimal, to prevent them from being silently rounded
        if (rawString.contains(".") && !TRAILING_DECIMAL_PATTERN
                .matcher(target.substring(target.indexOf("."), target.length())).matches()) {
            throw new FormatException("parsing", RiceKeyConstants.ERROR_CURRENCY_DECIMAL, rawString);
        }

        // actually reformat the numeric value
        NumberFormat formatter = getCurrencyInstanceUsingParseBigDecimal();
        try {
            Number parsedNumber = formatter.parse(target);
            value = new KualiDecimal(parsedNumber.toString());
        } catch (NumberFormatException e) {
            throw new FormatException("parsing", RiceKeyConstants.ERROR_CURRENCY, rawString, e);
        } catch (ParseException e) {
            throw new FormatException("parsing", RiceKeyConstants.ERROR_CURRENCY, rawString, e);
        }
    }

    return value;
    // end Kuali Foundation modification
}

From source file:net.myrrix.online.eval.ParameterOptimizer.java

/**
 * @return a {@link Map} between the values of the given {@link System} properties and the best value found
 *  during search//from  w w w .  j  a  v  a2 s.c  o  m
 * @throws ExecutionException if an error occurs while calling {@code evaluator}; the cause is the
 *  underlying exception
 */
public Map<String, Number> findGoodParameterValues() throws ExecutionException {

    int numProperties = parameterRanges.size();
    String[] propertyNames = new String[numProperties];
    Number[][] parameterValuesToTry = new Number[numProperties][];
    int index = 0;
    for (Map.Entry<String, ParameterRange> entry : parameterRanges.entrySet()) {
        propertyNames[index] = entry.getKey();
        parameterValuesToTry[index] = entry.getValue().buildSteps(numSteps);
        index++;
    }

    int numTests = 1;
    for (Number[] toTry : parameterValuesToTry) {
        numTests *= toTry.length;
    }

    List<Pair<Double, String>> testResultLinesByValue = Lists.newArrayListWithCapacity(numTests);

    Map<String, Number> bestParameterValues = Maps.newHashMap();
    double bestValue = minimize ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;

    for (int test = 0; test < numTests; test++) {

        StringBuilder testResultLine = new StringBuilder();
        for (int prop = 0; prop < numProperties; prop++) {
            String property = propertyNames[prop];
            Number parameterValue = getParameterValueToTry(parameterValuesToTry, test, prop);
            String propertyString = parameterValue.toString();
            log.info("Setting {}={}", property, propertyString);
            System.setProperty(property, propertyString);
            testResultLine.append('[').append(property).append('=').append(propertyString).append("] ");
        }

        Number evaluatorResult;
        try {
            evaluatorResult = evaluator.call();
        } catch (Exception e) {
            throw new ExecutionException(e);
        }
        if (evaluatorResult == null) {
            continue;
        }
        double testValue = evaluatorResult.doubleValue();
        testResultLine.append("= ").append(testValue);
        testResultLinesByValue.add(new Pair<Double, String>(testValue, testResultLine.toString()));
        log.info("{}", testResultLine);

        if (minimize ? testValue < bestValue : testValue > bestValue) {
            log.info("New best value {}", testValue);
            bestValue = testValue;
            for (int prop = 0; prop < numProperties; prop++) {
                String property = propertyNames[prop];
                Number parameterValue = getParameterValueToTry(parameterValuesToTry, test, prop);
                bestParameterValues.put(property, parameterValue);
            }
        }

        Collections.sort(testResultLinesByValue, new Comparator<Pair<Double, String>>() {
            @Override
            public int compare(Pair<Double, String> a, Pair<Double, String> b) {
                if (a.getFirst() > b.getFirst()) {
                    return -1;
                }
                if (a.getFirst() < b.getFirst()) {
                    return 1;
                }
                return 0;
            }
        });

        for (Pair<Double, String> result : testResultLinesByValue) {
            log.info("{}", result.getSecond());
        }
        log.info("Best parameter values so far are {}", bestParameterValues);
    }

    log.info("Final best parameter values are {}", bestParameterValues);
    return bestParameterValues;
}

From source file:at.pagu.soldockr.core.query.CriteriaTest.java

@Test
public void testRegisterAlternateConverter() {
    Criteria criteria = new Criteria("field_1").is(100);
    criteria.registerConverter(new Converter<Number, String>() {

        @Override// w  w  w . j  a  v a 2 s .c om
        public String convert(Number arg0) {
            return StringUtils.reverse(arg0.toString());
        }

    });
    Assert.assertEquals("field_1:001", criteria.createQueryString());
}