List of usage examples for java.lang Number toString
public String toString()
From source file:ro.nextreports.engine.chart.JFreeChartExporter.java
private void addValue(Object chartSerie, Number x, String lastXValue, Number y, HashMap<String, String> formatValues) { if (chart.getType().isLine()) { ((XYSeries) chartSerie).add(x, y); } else if (isLineCombo) { lineBarDataset.addValue(y, (String) chartSerie, lastXValue); } else if (!chart.getType().isPie()) { GFunction function = FunctionFactory.getFunction(chart.getYFunction()); if (!AbstractGFunction.NOOP.equals(function.getName())) { barDataset.setValue(y, (String) chartSerie, lastXValue); } else {/* w ww. j av a2 s . com*/ int serie = 0; Integer i = xValueSerie.get(lastXValue); if (i != null) { serie = i + 1; xValueSerie.put(lastXValue, serie); barDataset.setValue(y, (String) chartSerie, lastXValue + " (" + serie + ")"); } else { barDataset.setValue(y, (String) chartSerie, lastXValue); xValueSerie.put(lastXValue, 0); } } } else if (chart.getType().isPie()) { if (AbstractGFunction.NOOP.equals(chart.getYFunction())) { int serie = 0; Integer i = xValueSerie.get(lastXValue); if (i != null) { serie = i + 1; xValueSerie.put(lastXValue, serie); pieDataset.setValue(lastXValue + " (" + serie + ")", y); } else { pieDataset.setValue(lastXValue, y); xValueSerie.put(lastXValue, 0); } } else { pieDataset.setValue(lastXValue, y); } } formatValues.put(x.toString(), lastXValue); }
From source file:api.Client.java
public Request<DeletedOrdersResponse> ordersDeletedEntityService(Number storeId, String token, String from_date, String to_date, Number offset, Number limit) { try {//from ww w . ja v a 2 s . co m URIBuilder builder = new URIBuilder(url + "/" + storeId + "/orders/deleted"); if (token != null) builder.setParameter("token", token.toString()); if (from_date != null) builder.setParameter("from_date", from_date.toString()); if (to_date != null) builder.setParameter("to_date", to_date.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<DeletedOrdersResponse>(getRequestExecutor(), builder.build()) { @Override public DeletedOrdersResponse 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 DeletedOrdersResponse(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeletedProductsResponse> productsDeletedEntityService(Number storeId, String token, String from_date, String to_date, Number offset, Number limit) { try {/* w w w. ja v a2 s . co m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products/deleted"); if (token != null) builder.setParameter("token", token.toString()); if (from_date != null) builder.setParameter("from_date", from_date.toString()); if (to_date != null) builder.setParameter("to_date", to_date.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<DeletedProductsResponse>(getRequestExecutor(), builder.build()) { @Override public DeletedProductsResponse 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 DeletedProductsResponse(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeletedCustomersResponse> customersDeletedEntityService(Number storeId, String token, String from_date, String to_date, Number offset, Number limit) { try {//from w w w . java 2s.com URIBuilder builder = new URIBuilder(url + "/" + storeId + "/customers/deleted"); if (token != null) builder.setParameter("token", token.toString()); if (from_date != null) builder.setParameter("from_date", from_date.toString()); if (to_date != null) builder.setParameter("to_date", to_date.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<DeletedCustomersResponse>(getRequestExecutor(), builder.build()) { @Override public DeletedCustomersResponse 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 DeletedCustomersResponse(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DeletedDiscountCouponsResponse> discountCouponsDeletedEntityService(Number storeId, String token, String from_date, String to_date, Number offset, Number limit) { try {/*from w ww. j a va 2 s. c o m*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/discount_coupons/deleted"); if (token != null) builder.setParameter("token", token.toString()); if (from_date != null) builder.setParameter("from_date", from_date.toString()); if (to_date != null) builder.setParameter("to_date", to_date.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<DeletedDiscountCouponsResponse>(getRequestExecutor(), builder.build()) { @Override public DeletedDiscountCouponsResponse 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 DeletedDiscountCouponsResponse(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<DiscountCouponResult> listDiscountCouponService(Number storeId, String code, String discount_type, String availability, Number limit, Number offset, String token) { try {/*from ww w .j av a2 s. c om*/ URIBuilder builder = new URIBuilder(url + "/" + storeId + "/discount_coupons"); if (code != null) builder.setParameter("code", code.toString()); if (discount_type != null) builder.setParameter("discount_type", discount_type.toString()); if (availability != null) builder.setParameter("availability", availability.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<DiscountCouponResult>(getRequestExecutor(), builder.build()) { @Override public DiscountCouponResult 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 DiscountCouponResult(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<ProductSearchResult> searchProductApiService(Number storeId, String keyword, Number priceFrom, Number priceTo, Number category, Boolean withSubcategories, String sortBy, Number offset, Number limit, String createdFrom, String createdTo, String updatedFrom, String updatedTo, Boolean enabled, Boolean inStock, String token) { try {//from w w w .j av a 2s . c o m URIBuilder builder = new URIBuilder(url + "/" + storeId + "/products"); if (keyword != null) builder.setParameter("keyword", keyword.toString()); if (priceFrom != null) builder.setParameter("priceFrom", priceFrom.toString()); if (priceTo != null) builder.setParameter("priceTo", priceTo.toString()); if (category != null) builder.setParameter("category", category.toString()); if (withSubcategories != null) builder.setParameter("withSubcategories", withSubcategories.toString()); if (sortBy != null) builder.setParameter("sortBy", sortBy.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (createdFrom != null) builder.setParameter("createdFrom", createdFrom.toString()); if (createdTo != null) builder.setParameter("createdTo", createdTo.toString()); if (updatedFrom != null) builder.setParameter("updatedFrom", updatedFrom.toString()); if (updatedTo != null) builder.setParameter("updatedTo", updatedTo.toString()); if (enabled != null) builder.setParameter("enabled", enabled.toString()); if (inStock != null) builder.setParameter("inStock", inStock.toString()); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<ProductSearchResult>(getRequestExecutor(), builder.build()) { @Override public ProductSearchResult 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 ProductSearchResult(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:api.Client.java
public Request<CustomerSearchResult> searchCustomerApiService(Number storeId, String keyword, String name, String email, Number minOrderCount, Number maxOrderCount, String sortBy, Number offset, Number limit, String token) {// www. j av a2 s .c om try { URIBuilder builder = new URIBuilder(url + "/" + storeId + "/customers"); if (keyword != null) builder.setParameter("keyword", keyword.toString()); if (name != null) builder.setParameter("name", name.toString()); if (email != null) builder.setParameter("email", email.toString()); if (minOrderCount != null) builder.setParameter("minOrderCount", minOrderCount.toString()); if (maxOrderCount != null) builder.setParameter("maxOrderCount", maxOrderCount.toString()); if (sortBy != null) builder.setParameter("sortBy", sortBy.toString()); if (offset != null) builder.setParameter("offset", offset.toString()); if (limit != null) builder.setParameter("limit", limit.toString()); if (token != null) builder.setParameter("token", token.toString()); if (storeId == null) throw new IllegalArgumentException("No parameter storeId is set"); return new Request<CustomerSearchResult>(getRequestExecutor(), builder.build()) { @Override public CustomerSearchResult 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 CustomerSearchResult(new JSONObject(EntityUtils.toString(entity))); } finally { method.releaseConnection(); } } }; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:net.storyspace.StorySpace.java
/** * Returns information of a given user, specified by user-id. * /*from w ww .j av a 2s.c om*/ * @param userId * The user-id of a user. * @throws exception * if the user does not exist - or has been terminated (as * happens to spam bots). */ public User show(Number userId) { Map<String, String> vars = asMap("user_id", userId.toString()); String json = http.getPage(StorySpace_URL + "/users/show.json", vars, http.canAuthenticate()); updateRateLimits(KRequestType.SHOW_USER); try { User user = new User(new JSONObject(json), null); return user; } catch (JSONException e) { throw new StorySpaceException.Parsing(json, e); } }
From source file:com.examples.with.different.packagename.testcarver.NumberConverter.java
/** * Convert any Number object to the specified type for this * <i>Converter</i>.//from w w w . jav a2s.c o 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) + "'"; throw new ConversionException(msg); }