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.navasoft.madcoin.backend.model.controller.impl.CategoryDataAccess.java

/**
 * Pre delete./* w  ww  . j a v a2s . c om*/
 * 
 * @param toDelete
 *            the to delete
 * @return the service categories
 * @throws NonexistentEntityException
 *             the nonexistent entity exception
 * @throws IllegalOrphanException
 *             the illegal orphan exception
 * @since 2/09/2014, 09:31:50 PM
 */
@Override
public ServiceCategories preDelete(Number toDelete) throws NonexistentEntityException, IllegalOrphanException {
    ServiceCategories serviceCategories;
    try {
        serviceCategories = entityManager.getReference(ServiceCategories.class, toDelete);
        serviceCategories.getIdServiceCategory();
    } catch (EntityNotFoundException enfe) {
        throw new NonexistentEntityException(
                "The serviceCategories with id " + toDelete.toString() + " no longer exists.", enfe);
    }
    List<String> illegalOrphanMessages = null;
    Collection<WorkRequests> workRequestsCollectionOrphanCheck = serviceCategories.getWorkRequestsCollection();
    for (WorkRequests workRequestsCollectionOrphanCheckWorkRequests : workRequestsCollectionOrphanCheck) {
        if (illegalOrphanMessages == null) {
            illegalOrphanMessages = new ArrayList<String>();
        }
        illegalOrphanMessages.add(
                "This ServiceCategories (" + serviceCategories + ") cannot be destroyed since the WorkRequests "
                        + workRequestsCollectionOrphanCheckWorkRequests
                        + " in its workRequestsCollection field has a non-nullable serviceCategories field.");
    }
    if (illegalOrphanMessages != null) {
        throw new IllegalOrphanException(illegalOrphanMessages);
    }
    BusinessLines parentLob = serviceCategories.getParentLob();
    if (parentLob != null) {
        parentLob.getServiceCategoriesCollection().remove(serviceCategories);
        parentLob = entityManager.merge(parentLob);
    }
    return serviceCategories;
}

From source file:com.aw.swing.mvp.validation.support.AWDefaultRulesSource.java

private void validateRangeNumber(Object propertyValidator) {
    Number df = (Number) ((PropertyValidator) propertyValidator).getMinValue();
    Number dt = (Number) ((PropertyValidator) propertyValidator).getMaxValue();
    BindingComponent inputComponent = ((PropertyValidator) propertyValidator).getBindingComponent();
    logger.info("validation " + inputComponent.getFieldName() + ": Range");
    Number valorCampo = (Number) inputComponent.getValue();
    if (valorCampo != null) {
        if (!(df.doubleValue() <= valorCampo.doubleValue() && dt.doubleValue() >= valorCampo.doubleValue())) {
            throw new AWValidationException("sw.error.validate.range",
                    new Object[] { df.toString(), dt.toString() },
                    Arrays.asList(new Object[] { inputComponent }));
        }/*from w  ww  .jav  a2 s  .c  o m*/
    }
}

From source file:org.hyperic.hq.plugin.zimbra.five.ZimbraCollector.java

public void collect() {
    if (log.isDebugEnabled()) {
        log.debug("collect() (" + getProperties() + ")");
    }/*  w w w .  ja  v  a 2  s .  c  o  m*/
    if (log.isTraceEnabled()) {
        log.trace("[collect] (" + getProperties().getProperty("statsfile") + ") myLastLine=" + lastLine);
    }
    try {
        if (lastLine == null) {
            return;
        }
        String[] metrics = lastLine.split(",");
        // start at column 1 to ignore the timestamp
        for (int i = 1; i < metrics.length; i++) {
            // remove some spaces
            metrics[i] = metrics[i].trim();
            String alias = null;
            if (null == metrics[i] || metrics[i].matches("^\\s*$")
                    || null == (alias = (String) myAliasMap.get(new Integer(i)))) {
                continue;
            }
            try {
                Number v = nf.parse(metrics[i]);
                if (percentage) {
                    v = new Double(v.doubleValue() / 100d);
                }
                if (acumulate != null) {
                    Number va = (Number) acumulate.get(alias);
                    if (va != null) {
                        Integer vf = new Integer(v.intValue() + va.intValue());
                        acumulate.put(alias, vf);
                        //if (log.isTraceEnabled())
                        //   log.trace("read(v)='" + v + "' - prev(va)='"+va+"' - final(vf)='"+vf+"'");
                        v = vf;
                    }
                }
                setValue(alias, v.toString());
                /*if (log.isTraceEnabled()) {
                log.trace(alias + "= '" + metrics[i] + "' --> '" + v.toString() + "'");
                }*/
            } catch (ParseException e) {
                if (log.isTraceEnabled()) {
                    log.trace(alias + "=" + metrics[i] + "-->" + e.getMessage());
                }
                setValue(alias, metrics[i]);
            }
        }
    } finally {
        lastLine = null;
    }
}

From source file:ddf.catalog.source.solr.SolrFilterDelegate.java

private SolrQuery getEqualToQuery(String propertyName, AttributeFormat format, Number literal) {
    String mappedPropertyName = getMappedPropertyName(propertyName, format, true);

    SolrQuery query = new SolrQuery();
    query.setQuery(" " + mappedPropertyName + ":" + literal.toString());

    return query;
}

From source file:ddf.catalog.source.solr.SolrFilterDelegate.java

private SolrQuery getGreaterThanOrEqualToQuery(String propertyName, AttributeFormat format, Number literal) {
    String mappedPropertyName = getMappedPropertyName(propertyName, format, true);

    SolrQuery query = new SolrQuery();
    query.setQuery(" " + mappedPropertyName + ":[ " + literal.toString() + TO + "* ] ");

    return query;
}

From source file:ddf.catalog.source.solr.SolrFilterDelegate.java

private SolrQuery getGreaterThanQuery(String propertyName, AttributeFormat format, Number literal) {
    String mappedPropertyName = getMappedPropertyName(propertyName, format, true);

    SolrQuery query = new SolrQuery();
    query.setQuery(" " + mappedPropertyName + ":{ " + literal.toString() + TO + "* ] ");

    return query;
}

From source file:ddf.catalog.source.solr.SolrFilterDelegate.java

private SolrQuery getLessThanOrEqualToQuery(String propertyName, AttributeFormat format, Number literal) {
    String mappedPropertyName = getMappedPropertyName(propertyName, format, true);

    SolrQuery query = new SolrQuery();
    query.setQuery(" " + mappedPropertyName + ":[ * TO " + literal.toString() + " ] ");

    return query;
}

From source file:ddf.catalog.source.solr.SolrFilterDelegate.java

private SolrQuery getLessThanQuery(String propertyName, AttributeFormat format, Number literal) {
    String mappedPropertyName = getMappedPropertyName(propertyName, format, true);

    SolrQuery query = new SolrQuery();
    query.setQuery(" " + mappedPropertyName + ":[ * TO " + literal.toString() + " } ");

    return query;
}

From source file:org.kuali.ext.mm.web.format.MMDecimalFormatter.java

/**
 * Returns a string representation of its argument formatted as a currency value. begin Kuali Foundation modification
 * //from   ww w.j a va 2s  .c om
 * @see org.kuali.rice.kns.web.format.Formatter#format(java.lang.Object) end Kuali Foundation modification
 */
// begin Kuali Foundation modification
@Override
// end Kuali Foundation modification
public Object format(Object obj) {
    // begin Kuali Foundation modification
    // major code rewrite, original code commented
    /*
     * if (obj == null) return null; NumberFormat formatter = NumberFormat.getCurrencyInstance(); String string = null; try {
     * BigDecimal number = (BigDecimal) obj; number = number.setScale(SCALE, BigDecimal.ROUND_HALF_UP); string =
     * formatter.format(number.doubleValue()); } catch (IllegalArgumentException e) { throw new FormatException(FORMAT_MSG +
     * obj, e); } catch (ClassCastException e) { throw new FormatException(FORMAT_MSG + obj, e); } return showSymbol() ? string :
     * removeSymbol(string);
     */
    LOG.debug("format '" + obj + "'");
    if (obj == null)
        return null;

    NumberFormat formatter = getCurrencyInstanceUsingParseBigDecimal();
    String string = null;

    try {
        Number number;

        if (obj instanceof KualiInteger) {
            formatter.setMaximumFractionDigits(0);
            number = (KualiInteger) obj;

            // Note that treating the number as a MMDecimal below is obsolete. But it doesn't do any harm either since
            // we already set maximumFractionDigits above.
        } else {
            number = (MMDecimal) obj;
            formatter.setMaximumFractionDigits(4);
        }

        // run the incoming MMDecimal's string representation through convertToObject, so that MMDecimal objects
        // containing ill-formatted incoming values will cause the same errors here that ill-formatted Strings do in
        // convertToObject
        MMDecimal convertedNumber = (MMDecimal) convertToObject(number.toString());

        string = formatter.format(convertedNumber.bigDecimalValue());
    } catch (IllegalArgumentException e) {
        throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
    } catch (ClassCastException e) {
        throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
    }

    return showSymbol() ? string : removeSymbol(string);
    // end Kuali Foundation modification
}

From source file:SignificantFigures.java

/**
 * Create a SignificantFigures object from a java number such as
 * a BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, or
 * Short.//from   www .  j  a v a2 s  . c  om
 *
 * @param number a number.
 *
 * @since ostermillerutils 1.00.00
 */
public SignificantFigures(Number number) {
    original = number.toString();
    try {
        parse(original);
    } catch (NumberFormatException nfe) {
        digits = null;
    }
}