List of usage examples for java.lang Number toString
public String toString()
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJNumberEditor.java
public BigDecimal getNumberValue() { final String S_ProcName = "getNumberValue"; BigDecimal retval;// www . j a v a 2s. c om 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 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)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } 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)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } 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)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof BigDecimal) { BigDecimal v = (BigDecimal) obj; BigDecimal min = getMinValue(); BigDecimal 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; BigDecimal v = new BigDecimal(n.toString()); BigDecimal min = getMinValue(); BigDecimal 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.eclipse.skalli.core.rest.XMLRestWriter.java
@Override public RestWriter value(Number n) throws IOException { return value(n.toString()); }
From source file:org.eclipse.skalli.core.rest.XMLRestWriter.java
@Override public RestWriter pair(String key, Number n) throws IOException { return pair(key, n.toString()); }
From source file:org.eclipse.skalli.core.rest.XMLRestWriter.java
@Override public RestWriter attribute(String key, Number n) throws IOException { return attribute(key, n.toString()); }
From source file:io.coala.config.AbstractPropertyGetter.java
/** * @param defaultValue//from w w w. ja v a2s .c o m * @return */ public Number getNumber(final Number defaultValue) throws NumberFormatException { final String value = get(defaultValue == null ? null : defaultValue.toString()); return value == null ? null : Double.valueOf(value); }
From source file:com.ultrapower.eoms.common.plugin.ecside.view.CsvView.java
public void totals(TableModel model) { // w w w. ja v a 2s. c om rowBuffer = new StringBuffer(); Column firstCalcColumn = model.getColumnHandler().getFirstCalcColumn(); if (firstCalcColumn != null) { int rows = firstCalcColumn.getCalc().length; for (int i = 0; i < rows; i++) { for (Iterator iter = model.getColumnHandler().getColumns().iterator(); iter.hasNext();) { Column column = (Column) iter.next(); if (column.isFirstColumn()) { String calcTitle = CalcUtils.getFirstCalcColumnTitleByPosition(model, i); rowBuffer.append(ExportViewUtils.parseCSV(calcTitle) ); continue; } rowBuffer.append(delimiter); if (column.isCalculated()) { CalcResult calcResult = CalcUtils.getCalcResultsByPosition(model, column, i); java.lang.Number value = calcResult.getValue(); if (value != null){ if (StringUtils.isNotBlank(column.getFormat())){ rowBuffer.append(ExportViewUtils.parseCSV(ExtremeUtils.formatNumber(column.getFormat(), value, model.getLocale()))); }else{ rowBuffer.append(ExportViewUtils.parseCSV(value.toString()) ); } } else { rowBuffer.append(ExportViewUtils.parseCSV("")); } } else { rowBuffer.append(ExportViewUtils.parseCSV("")); } } rowBuffer.append(ExportViewUtils.BR); writeToOutputStream(rowBuffer.toString()); } } }
From source file:de.unioninvestment.eai.portal.portlet.crud.scripting.domain.container.rest.ValueConverter.java
private Object convertNumberToNumber(Class<?> targetClass, Number number) { if (targetClass.isAssignableFrom(number.getClass())) { return number; } else if (targetClass == Integer.class) { return number.intValue(); } else if (targetClass == Long.class) { return number.longValue(); } else if (targetClass == Double.class) { return number.doubleValue(); } else if (targetClass == BigDecimal.class) { return new BigDecimal(number.toString()); }//from w w w.ja v a 2 s.co m throw new IllegalArgumentException("Cannot convert to " + targetClass.getSimpleName() + ": " + number + " of type " + number.getClass().getName()); }
From source file:com.p5solutions.core.json.JsonSerializer.java
/** * Write number./*from ww w . jav a 2 s . co m*/ * * @param output * the output * @param value * the value * @param charset * the charset * @throws IOException * Signals that an I/O exception has occurred. */ protected void writeNumber(OutputStream output, Number value, Charset charset) throws IOException { String stringValue = value.toString(); output.write(stringValue.getBytes(charset)); }
From source file:com.nsano.uat.Imtservlet.java
/** * * @param request/*from w ww .j a v a2s .co m*/ * @return * @throws IOException */ private String moneytransfer(HttpServletRequest request) throws IOException, JSONException, NoSuchAlgorithmException { // joined json string String join = ""; JsonElement root = null; JsonElement root2 = null; JsonElement root3 = null; String responseobject = ""; //String nickname="KENDYIPL"; // These represent parameters received over the network String tag = "", apikey = "", refID = "", sender = "", sender_country = "", receiver = "", receiver_msisdn = "", receiver_country = "", amount = "", mno = ""; //referenceid, customermsisdn, nickname,amount, batchref, username, password, narrative // Get all parameters, the keys of the parameters are specified List<String> lines = IOUtils.readLines(request.getReader()); // used to format/join incoming JSon string join = StringUtils.join(lines.toArray(), ""); //############################################################################### // instantiate the JSon //Note //The = sign is encoded to \u003d. Hence you need to use disableHtmlEscaping(). //############################################################################### Gson g = new GsonBuilder().disableHtmlEscaping().create(); //Gson g = new Gson(); Map<String, String> expected = new HashMap<>(); try { // parse the JSon string //referenceid, customermsisdn, nickname,amount, batchref, username, password, narrative root = new JsonParser().parse(join); tag = root.getAsJsonObject().get("tag").getAsString(); apikey = root.getAsJsonObject().get("apikey").getAsString(); refID = root.getAsJsonObject().get("refID").getAsString(); sender = root.getAsJsonObject().get("sender").getAsString(); sender_country = root.getAsJsonObject().get("sender_country").getAsString(); receiver = root.getAsJsonObject().get("receiver").getAsString(); receiver_msisdn = root.getAsJsonObject().get("receiver_msisdn").getAsString(); receiver_country = root.getAsJsonObject().get("receiver_country").getAsString(); amount = root.getAsJsonObject().get("amount").getAsString(); mno = root.getAsJsonObject().get("mno").getAsString(); } catch (Exception e) { expected.put("command_status", "COMMANDSTATUS_INVALID_PARAMETERS"); String jsonResult = g.toJson(expected); System.out.println(e); return jsonResult; } //check for the presence of all required parameters if (StringUtils.isBlank(tag) || StringUtils.isBlank(apikey) || StringUtils.isBlank(refID) || StringUtils.isBlank(sender) || StringUtils.isBlank(sender_country) || StringUtils.isBlank(receiver) || StringUtils.isBlank(receiver_msisdn) || StringUtils.isBlank(receiver_country) || StringUtils.isBlank(amount) || StringUtils.isBlank(mno)) { //expected.put("username", username); expected.put("status_code", statuscode); expected.put("status_description", Statusdescription); String jsonResult = g.toJson(expected); return jsonResult; } //assign the remit url from properties.config //String processtransaction = airtelbalance.AirtelBalance( nickname, username, password); String processtransaction = cred.sendPOST(); //capture the switch respoinse. System.out.println(processtransaction); //pass the returned json string JsonElement roots = new JsonParser().parse(processtransaction); //JsonElement rootsone = roots.getAsJsonObject(); //exctract a specific json element from the object(status_code) //Double code = roots.getAsJsonObject().get("code").getAsDouble(); Number code = roots.getAsJsonObject().get("code").getAsNumber(); String msg = roots.getAsJsonObject().get("msg").getAsString(); //String data = rootsone.getAsJsonObject().get("error_type").getAsString(); //add //expected.put("username", username); expected.put("code", code.toString()); expected.put("msg", msg.toString()); //expected.put("error_type", data.toString()); String jsonResult = g.toJson(expected); if (code.toString() == "00") { System.out.println("success"); } else { System.out.println("fail"); } return jsonResult; }
From source file:com.googlecode.jtiger.modules.ecside.view.CsvView.java
public void totals(TableModel model) { rowBuffer = new StringBuffer(); Column firstCalcColumn = model.getColumnHandler().getFirstCalcColumn(); if (firstCalcColumn != null) { int rows = firstCalcColumn.getCalc().length; for (int i = 0; i < rows; i++) { for (Iterator iter = model.getColumnHandler().getColumns().iterator(); iter.hasNext();) { Column column = (Column) iter.next(); if (column.isFirstColumn()) { String calcTitle = CalcUtils.getFirstCalcColumnTitleByPosition(model, i); rowBuffer.append(ExportViewUtils.parseCSV(calcTitle)); continue; }//from w w w.ja v a2 s .co m rowBuffer.append(delimiter); if (column.isCalculated()) { CalcResult calcResult = CalcUtils.getCalcResultsByPosition(model, column, i); java.lang.Number value = calcResult.getValue(); if (value != null) { if (StringUtils.isNotBlank(column.getFormat())) { rowBuffer.append(ExportViewUtils.parseCSV( ExtremeUtils.formatNumber(column.getFormat(), value, model.getLocale()))); } else { rowBuffer.append(ExportViewUtils.parseCSV(value.toString())); } } else { rowBuffer.append(ExportViewUtils.parseCSV("")); } } else { rowBuffer.append(ExportViewUtils.parseCSV("")); } } rowBuffer.append(ExportViewUtils.BR); writeToOutputStream(rowBuffer.toString()); } } }