List of usage examples for java.lang Number toString
public String toString()
From source file:org.mifos.clientportfolio.loan.ui.LoanAccountFormBean.java
private void validateAdministrativeAndAdditionalFees(Errors errors) { Set<Integer> feeSet = new HashSet<Integer>(); if (this.selectedFeeId != null) { boolean noDuplicateExists = true; for (Number feeId : this.selectedFeeId) { if (feeId != null) { noDuplicateExists = feeSet.add(feeId.intValue()); if (!noDuplicateExists) { errors.rejectValue("selectedFeeId", "loanAccountFormBean.additionalfees.invalid", "Multiple instances of the same fee are not allowed."); break; }/*from w w w . j ava 2 s .c o m*/ } } } int defaultFeeIndex = 0; if (this.defaultFeeId != null) { for (Number feeId : this.defaultFeeId) { if (feeId != null) { Boolean feeSelectedForRemoval = this.defaultFeeSelected[defaultFeeIndex]; if (feeSelectedForRemoval == null || !feeSelectedForRemoval) { Number amountOrRate = this.defaultFeeAmountOrRate[defaultFeeIndex]; if (amountOrRate == null) { errors.rejectValue("defaultFeeId", "loanAccountFormBean.defaultfees.amountOrRate.invalid", "Please specify fee amount for administrative fee " + Integer.valueOf(defaultFeeIndex + 1).toString()); } else { FeeDto selectedFee = findDefaultFee(feeId.intValue()); if (selectedFee.isRateBasedFee()) { // maybe check based on 'interest rate' decimals? } else { BigDecimal feeAmountAsDecimal = new BigDecimal(amountOrRate.toString()) .stripTrailingZeros(); int places = feeAmountAsDecimal.scale(); if (places > this.digitsAfterDecimalForMonetaryAmounts) { errors.rejectValue("selectedFeeId", "loanAccountFormBean.defaultfees.amountOrRate.digits.after.decimal.invalid", new Object[] { Integer.valueOf(defaultFeeIndex + 1), this.digitsAfterDecimalForMonetaryAmounts }, "Please specify fee amount for additional fee " + Integer.valueOf(defaultFeeIndex + 1).toString()); } int digitsBefore = feeAmountAsDecimal.toBigInteger().toString().length(); if (digitsBefore > this.digitsBeforeDecimalForMonetaryAmounts) { errors.rejectValue("selectedFeeId", "loanAccountFormBean.defaultfees.amountOrRate.digits.before.decimal.invalid", new Object[] { Integer.valueOf(defaultFeeIndex + 1), this.digitsAfterDecimalForMonetaryAmounts }, "Please specify fee amount for additional fee " + Integer.valueOf(defaultFeeIndex + 1).toString()); } } } } } defaultFeeIndex++; } } int additionalFeeIndex = 0; if (this.selectedFeeId != null) { for (Number feeId : this.selectedFeeId) { if (feeId != null) { Number amountOrRate = this.selectedFeeAmount[additionalFeeIndex]; if (amountOrRate == null) { errors.rejectValue("selectedFeeId", "loanAccountFormBean.additionalfees.amountOrRate.invalid", "Please specify fee amount for additional fee " + Integer.valueOf(additionalFeeIndex + 1).toString()); } else { int digitsAllowedBefore, digitsAllowedAfter; if (findAdditionalFee(feeId.intValue()).isRateBasedFee()) { digitsAllowedBefore = this.digitsBeforeDecimalForInterest; digitsAllowedAfter = this.digitsAfterDecimalForInterest; } else { digitsAllowedBefore = this.digitsBeforeDecimalForMonetaryAmounts; digitsAllowedAfter = this.digitsAfterDecimalForMonetaryAmounts; } BigDecimal feeAmountAsDecimal = new BigDecimal(amountOrRate.toString()) .stripTrailingZeros(); int places = feeAmountAsDecimal.scale(); if (places > digitsAllowedAfter) { errors.rejectValue("selectedFeeId", "loanAccountFormBean.additionalfees.amountOrRate.digits.after.decimal.invalid", new Object[] { Integer.valueOf(additionalFeeIndex + 1), digitsAllowedAfter }, "Please specify fee amount for additional fee " + Integer.valueOf(additionalFeeIndex + 1).toString()); } int digitsBefore = feeAmountAsDecimal.toBigInteger().toString().length(); if (digitsBefore > digitsAllowedBefore) { errors.rejectValue("selectedFeeId", "loanAccountFormBean.additionalfees.amountOrRate.digits.before.decimal.invalid", new Object[] { Integer.valueOf(additionalFeeIndex + 1), digitsAllowedBefore }, "Please specify fee amount for additional fee " + Integer.valueOf(additionalFeeIndex + 1).toString()); } } } additionalFeeIndex++; } } }
From source file:org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.java
/** * @return a count of the digits in the specified number *//*w w w. j av a2 s . co m*/ private static 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:com.flexive.core.storage.genericSQL.GenericTreeStorage.java
/** * Get all node ids between the left and right boundaries * * @param con an open and valid connection * @param mode tree mode/*from w w w . j a v a 2 s . c om*/ * @param left left boundary * @param right right boundary * @param includeRoot if the root node (of the subtree) itself should be included * @return node id's between the boundaries * @throws SQLException on errors */ protected List<Long> selectAllChildNodeIds(Connection con, FxTreeMode mode, Number left, Number right, boolean includeRoot) throws SQLException { PreparedStatement stmt = null; try { final String rangeIncl = includeRoot ? "=" : ""; stmt = con.prepareStatement("SELECT id FROM " + getTable(mode) + " WHERE lft >" + rangeIncl + " ? AND rgt <" + rangeIncl + " ?"); setNodeBounds(stmt, 1, new BigInteger(left.toString())); setNodeBounds(stmt, 2, new BigInteger(right.toString())); return collectNodeIds(stmt); } finally { Database.closeObjects(GenericTreeStorage.class, null, stmt); } }
From source file:com.xyphos.vmtgen.GUI.java
private void writeSpinner(PrintWriter out, JSpinner spinner, Number defaultValue, String key, int padding) { Number value = ((SpinnerNumberModel) spinner.getModel()).getNumber(); writeKeyValue(!defaultValue.equals(value), out, key, value.toString(), padding); }
From source file:org.tolven.assembler.webxml.WebXMLAssembler.java
protected void addSessionConfig(Number sessionTimeout, XMLStreamWriter xmlStreamWriter) throws XMLStreamException { xmlStreamWriter.writeStartElement("xsl:if"); xmlStreamWriter.writeAttribute("test", "count(tp:session-config[tp:session-timeout = '" + sessionTimeout + "']) = 0"); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("session-config"); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeStartElement("session-timeout"); xmlStreamWriter.writeCharacters(sessionTimeout.toString()); xmlStreamWriter.writeEndElement();//from w w w .java 2 s.co m xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); }
From source file:org.apache.cocoon.template.instruction.FormatNumber.java
private String format(ExpressionContext expressionContext) throws Exception { // Determine formatting locale String var = this.var == null ? null : this.var.getStringValue(expressionContext); Number input = this.value.getNumberValue(expressionContext); String type = this.type == null ? null : this.type.getStringValue(expressionContext); String pattern = this.pattern == null ? null : this.pattern.getStringValue(expressionContext); String currencyCode = this.currencyCode == null ? null : this.currencyCode.getStringValue(expressionContext); String currencySymbol = this.currencySymbol == null ? null : this.currencySymbol.getStringValue(expressionContext); Boolean isGroupingUsed = this.isGroupingUsed == null ? null : this.isGroupingUsed.getBooleanValue(expressionContext); Number maxIntegerDigits = this.maxIntegerDigits == null ? null : this.maxIntegerDigits.getNumberValue(expressionContext); Number minIntegerDigits = this.minIntegerDigits == null ? null : this.minIntegerDigits.getNumberValue(expressionContext); Number maxFractionDigits = this.maxFractionDigits == null ? null : this.maxFractionDigits.getNumberValue(expressionContext); Number minFractionDigits = this.minFractionDigits == null ? null : this.minFractionDigits.getNumberValue(expressionContext); Locale loc = getLocale(expressionContext); String formatted;/*from w w w .ja v a 2 s. c o m*/ if (loc != null) { // Create formatter NumberFormat formatter = null; if (StringUtils.isNotEmpty(pattern)) { // if 'pattern' is specified, 'type' is ignored DecimalFormatSymbols symbols = new DecimalFormatSymbols(loc); formatter = new DecimalFormat(pattern, symbols); } else { formatter = createFormatter(loc, type); } if (StringUtils.isNotEmpty(pattern) || CURRENCY.equalsIgnoreCase(type)) { setCurrency(formatter, currencyCode, currencySymbol); } configureFormatter(formatter, isGroupingUsed, maxIntegerDigits, minIntegerDigits, maxFractionDigits, minFractionDigits); formatted = formatter.format(input); } else { // no formatting locale available, use toString() formatted = input.toString(); } if (var != null) { expressionContext.put(var, formatted); return null; } return formatted; }
From source file:org.getobjects.eoaccess.EOSQLExpression.java
/** * Returns the SQL representation of a Number. For INTs this is just the * Java value, for float/doubles/bigdecs it might be database specific. * The current implementation just calls the numbers toString() method. * // w ww. j av a2 s . c o m * @param _value - some Number object * @return the SQL representation of the given Number (or NULL for null) */ public String sqlStringForNumber(final Number _value) { return (_value == null) ? "NULL" : _value.toString(); }
From source file:jp.furplag.util.commons.NumberUtilsTest.java
/** * {@link jp.furplag.util.commons.NumberUtils#compareTo(java.lang.Number, java.lang.Number)}. *///from w w w. j av a2 s. c o m @SuppressWarnings("unchecked") @Test public void testCompareToNumberNumber() { assertEquals("null", (Object) 0, compareTo(null, null)); assertEquals("null", (Object) 1, compareTo(1, null)); assertEquals("null", (Object) 1, compareTo(-1, null)); assertEquals("null", (Object) 1, compareTo(Float.NEGATIVE_INFINITY, null)); assertEquals("null", (Object) (-1), compareTo(null, 1)); assertEquals("null", (Object) (-1), compareTo(null, -1)); assertEquals("null", (Object) (-1), compareTo(null, Double.NEGATIVE_INFINITY)); assertEquals("Infinity", (Object) 0, compareTo(Float.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY)); assertEquals("Infinity", (Object) 0, compareTo(Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)); assertEquals("NaN", (Object) 1, compareTo(Float.NaN, null)); assertEquals("NaN", (Object) 1, compareTo(Float.NaN, 1)); assertEquals("NaN", (Object) 1, compareTo(Float.NaN, -1)); assertEquals("NaN", (Object) 1, compareTo(Float.NaN, Double.POSITIVE_INFINITY)); assertEquals("NaN", (Object) 0, compareTo(Float.NaN, Double.NaN)); assertEquals("NaN", (Object) (-1), compareTo(null, Double.NaN)); assertEquals("NaN", (Object) (-1), compareTo(1, Double.NaN)); assertEquals("NaN", (Object) (-1), compareTo(-1, Double.NaN)); assertEquals("NaN", (Object) (-1), compareTo(Float.NEGATIVE_INFINITY, Double.NaN)); assertEquals("NaN", (Object) 0, compareTo(Double.NaN, Float.NaN)); for (Class<?> type : NUMBERS) { Class<? extends Number> wrapper = (Class<? extends Number>) ClassUtils.primitiveToWrapper(type); try { Number n = null; if (ClassUtils.isPrimitiveWrapper(type)) { n = (Number) wrapper.getField("MAX_VALUE").get(null); } else { n = INFINITY_DOUBLE.pow(2); if (BigInteger.class.equals(type)) n = ((BigDecimal) n).toBigInteger(); } assertEquals("equals: " + type.getSimpleName(), 0, compareTo(n, new BigDecimal(n.toString()))); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace())); } } }
From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java
private void writeAttr(PrintStream output, boolean first, String name, Number value) { writeAttrRaw(output, first, name, value.toString()); }
From source file:api.Client.java
public Request<CategorySearchResult> listCategoryService(Number storeId, String token, Number parent, Boolean hidden_categories, Boolean productIds, Number limit, Number offset) { try {//from w w w . j a v a2 s . c o m URIBuilder builder = new URIBuilder(url + "/" + storeId + "/categories"); if (token != null) builder.setParameter("token", token.toString()); if (parent != null) builder.setParameter("parent", parent.toString()); if (hidden_categories != null) builder.setParameter("hidden_categories", hidden_categories.toString()); if (productIds != null) builder.setParameter("productIds", productIds.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<CategorySearchResult>(getRequestExecutor(), builder.build()) { @Override public CategorySearchResult 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 CategorySearchResult(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }