List of usage examples for java.lang Double toString
public static String toString(double d)
From source file:com.mk4droid.IMC_Services.Download_Data.java
/** * Download issues in a certain geographic rectangle * /* w w w. j a v a 2 s . com*/ * @param x0down minimum longitude of the rectangle * @param x0up maximum longitude of the rectangle * @param y0down minimum latitude of the rectangle * @param y0up maximum latitude of the rectangle * @param IssueNolimit maximum number of issues to download within this rectangle starting from the most recent ones * @return */ public static String Download_Issues(double x0down, double x0up, double y0down, double y0up, int IssueNolimit) { RestCaller rc = new RestCaller(); String response = rc.now(Constants_API.COM_Protocol + Constants_API.ServerSTR + Constants_API.phpExec, "GET", new String[] { "option", "com_improvemycity", "task", Phptasks.TASK_GET_ISSUES, //_Zipped "format", "json", "x0down", Double.toString(x0down), "x0up", Double.toString(x0up), "y0down", Double.toString(y0down), "y0up", Double.toString(y0up), "limit", Integer.toString(IssueNolimit) }, "UTF-8", "Download_Issues"); return response; }
From source file:statUtil.TurnMovementPlot.java
public TurnMovementPlot(String title) throws IOException { super(title); Data data = CSVData.getCSVData(TURN_CSV_LOG); JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", XYDatasetGenerator.generateXYDataset(data.csvData)); final XYPlot xyPlot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesStroke(0, new BasicStroke(3f)); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); Shape cross = ShapeUtilities.createDiagonalCross(2f, 0.5f); renderer.setSeriesShape(1, cross);/* w w w. j a v a 2 s . c o m*/ xyPlot.setRenderer(renderer); xyPlot.setQuadrantOrigin(new Point(0, 0)); int i = 0; for (Double[] csvRow : data.csvData) { if (i % 20 == 1) { final XYTextAnnotation annotation = new XYTextAnnotation(Double.toString(csvRow[3]), csvRow[0], csvRow[1]); annotation.setFont(new Font("SansSerif", Font.PLAIN, 10)); xyPlot.addAnnotation(annotation); } i++; } int width = (int) Math.round(data.maxX - data.minX) + 50; int height = (int) Math.round(data.maxY - data.minY) + 50; ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(width, height)); setContentPane(chartPanel); File XYChart = new File(FILE_PATH + "\\TurnMovementPlot.png"); ChartUtilities.saveChartAsPNG(XYChart, chart, width, height); }
From source file:com.cloudbase.datacommands.CBSearchCondition.java
/** * Creates a new search condition for geographical searches. This looks for documents whose location data * places them near the given location./*from w w w. j a v a 2s .c o m*/ * @param nearLoc The location we are looking for * @param maxDistance The maximum distance in meters from the given location */ public CBSearchCondition(BlackBerryLocation nearLoc, int maxDistance) { Vector points = new Vector(); points.addElement(Double.toString(nearLoc.getQualifiedCoordinates().getLatitude())); points.addElement(Double.toString(nearLoc.getQualifiedCoordinates().getLongitude())); Hashtable searchQuery = new Hashtable(); this.setField("cb_location"); this.setOperator(CBSearchConditionOperator.CBOperatorEqual); searchQuery.put("$near", points); if (maxDistance > 0) searchQuery.put("$maxDistance", Integer.toString(maxDistance)); this.setValue(searchQuery); this.limit = -1; this.setCommandType(CBDataAggregationCommandType.CBDataAggregationMatch); }
From source file:eu.optimis.ecoefficiencytool.core.tools.EnergyCreditsManager.java
/** * * @param consumedEnergy Consumed energy in kWh. *///from www .j a v a 2 s. c o m private static void setRemainingEnergyInRECs(double consumedEnergy) throws ConfigurationException { PropertiesConfiguration configEnergyCredits = ConfigManager .getPropertiesConfiguration(ConfigManager.ENERGYCREDITS_CONFIG_FILE); Iterator recs = configEnergyCredits.getKeys("REC"); while (recs.hasNext()) { String key = (String) recs.next(); double remainingCredit = configEnergyCredits.getDouble(key); if (consumedEnergy < remainingCredit) { remainingCredit = remainingCredit - consumedEnergy; configEnergyCredits.setProperty(key, Double.toString(remainingCredit)); configEnergyCredits.save(); return; } else { consumedEnergy = consumedEnergy - remainingCredit; configEnergyCredits.setProperty(key, Double.toString(0.0)); } } if (consumedEnergy > 0.0) { log.warn("All REC Energy credits are exhausted"); } configEnergyCredits.save(); }
From source file:com.zte.ums.zenap.itm.agent.plugin.linux.util.Calculator.java
public String calculateItem(Map variables, String formula) throws MonitorException { Set vKeySet = variables.keySet(); Object[] keys = vKeySet.toArray(); Arrays.sort(keys);//from w w w.j a v a 2s . com JexlContext jexlContext = new MapContext(); for (int i = keys.length - 1; i >= 0; i--) { String s = keys[i].toString(); String s1 = s.replace('.', 'a'); formula = formula.replaceAll(s, s1); jexlContext.set(s1, variables.get(s)); } try { while (true) { int eIndex = formula.indexOf("E"); if (eIndex == -1) { break; } int startIndex = getBackwardNumIndex(formula, eIndex); int endIndex = getForwardNumIndex(formula, eIndex); String eNum = formula.substring(eIndex + 1, endIndex); String tenNumString = null; int num = Integer.parseInt(eNum); if (num > 5) { int tenNum = 1; for (int i = 0; i < (num - 5); i++) { tenNum = tenNum * 10; } tenNumString = "100000.0 * " + Integer.toString(tenNum); } else if (num > 0) { int tenNum = 1; for (int i = 0; i < num; i++) { tenNum = tenNum * 10; } tenNumString = Integer.toString(tenNum); } else if (num < 0) { double tenNum = 1; for (int i = 0; i > num; i--) { tenNum = tenNum * 0.1; } tenNumString = Double.toString(tenNum); } String variable = formula.substring(startIndex, endIndex); String headVariable = formula.substring(startIndex, eIndex); formula = formula.replaceFirst(variable, "(" + headVariable + " * " + tenNumString + ")"); } JexlEngine jexlEngine = new JexlEngine(); Expression expression = jexlEngine.createExpression(formula); Object result = expression.evaluate(jexlContext); if (result instanceof Double) { Double dd = (Double) result; NumberFormat formater = new DecimalFormat("#.00"); formater.setRoundingMode(RoundingMode.HALF_UP); return formater.format(dd); } return result.toString(); } catch (Exception e) { throw new MonitorException("Error!Something wrong happened! ", e); } }
From source file:com.cloudera.sqoop.mapreduce.db.FloatSplitter.java
public List<InputSplit> split(Configuration conf, ResultSet results, String colName) throws SQLException { LOG.warn("Generating splits for a floating-point index column. Due to the"); LOG.warn("imprecise representation of floating-point values in Java, this"); LOG.warn("may result in an incomplete import."); LOG.warn("You are strongly encouraged to choose an integral split column."); List<InputSplit> splits = new ArrayList<InputSplit>(); if (results.getString(1) == null && results.getString(2) == null) { // Range is null to null. Return a null split accordingly. splits.add(// www .j a va2 s. c o m new DataDrivenDBInputFormat.DataDrivenDBInputSplit(colName + " IS NULL", colName + " IS NULL")); return splits; } double minVal = results.getDouble(1); double maxVal = results.getDouble(2); // Use this as a hint. May need an extra task if the size doesn't // divide cleanly. int numSplits = ConfigurationHelper.getConfNumMaps(conf); double splitSize = (maxVal - minVal) / (double) numSplits; if (splitSize < MIN_INCREMENT) { splitSize = MIN_INCREMENT; } String lowClausePrefix = colName + " >= "; String highClausePrefix = colName + " < "; double curLower = minVal; double curUpper = curLower + splitSize; while (curUpper < maxVal) { splits.add(new DataDrivenDBInputFormat.DataDrivenDBInputSplit( lowClausePrefix + Double.toString(curLower), highClausePrefix + Double.toString(curUpper))); curLower = curUpper; curUpper += splitSize; } // Catch any overage and create the closed interval for the last split. if (curLower <= maxVal || splits.size() == 1) { splits.add(new DataDrivenDBInputFormat.DataDrivenDBInputSplit( lowClausePrefix + Double.toString(curUpper), colName + " <= " + Double.toString(maxVal))); } if (results.getString(1) == null || results.getString(2) == null) { // At least one extrema is null; add a null split. splits.add( new DataDrivenDBInputFormat.DataDrivenDBInputSplit(colName + " IS NULL", colName + " IS NULL")); } return splits; }
From source file:com.sonoport.freesound.response.mapping.Mapper.java
/** * Extract a named value from a {@link JSONObject}. This method checks whether the value exists and is not an * instance of <code>JSONObject.NULL</code>. * * @param jsonObject The {@link JSONObject} being processed * @param field The field to retrieve// ww w. java2 s.co m * @param fieldType The data type of the field * @return The field value (or null if not found) * * @param <T> The data type to return */ @SuppressWarnings("unchecked") protected <T extends Object> T extractFieldValue(final JSONObject jsonObject, final String field, final Class<T> fieldType) { T fieldValue = null; if ((jsonObject != null) && jsonObject.has(field) && !jsonObject.isNull(field)) { try { if (fieldType == String.class) { fieldValue = (T) jsonObject.getString(field); } else if (fieldType == Integer.class) { fieldValue = (T) Integer.valueOf(jsonObject.getInt(field)); } else if (fieldType == Long.class) { fieldValue = (T) Long.valueOf(jsonObject.getLong(field)); } else if (fieldType == Float.class) { fieldValue = (T) Float.valueOf(Double.toString(jsonObject.getDouble(field))); } else if (fieldType == JSONArray.class) { fieldValue = (T) jsonObject.getJSONArray(field); } else if (fieldType == JSONObject.class) { fieldValue = (T) jsonObject.getJSONObject(field); } else { fieldValue = (T) jsonObject.get(field); } } catch (final JSONException | ClassCastException e) { // TODO Log a warning } } return fieldValue; }
From source file:co.nubetech.apache.hadoop.FloatSplitter.java
public List<InputSplit> split(Configuration conf, ResultSet results, String colName) throws SQLException { LOG.warn("Generating splits for a floating-point index column. Due to the"); LOG.warn("imprecise representation of floating-point values in Java, this"); LOG.warn("may result in an incomplete import."); LOG.warn("You are strongly encouraged to choose an integral split column."); List<InputSplit> splits = new ArrayList<InputSplit>(); if (results.getString(1) == null && results.getString(2) == null) { // Range is null to null. Return a null split accordingly. splits.add(//w ww .j a v a 2 s . c o m new DataDrivenDBInputFormat.DataDrivenDBInputSplit(colName + " IS NULL", colName + " IS NULL")); return splits; } double minVal = results.getDouble(1); double maxVal = results.getDouble(2); // Use this as a hint. May need an extra task if the size doesn't // divide cleanly. int numSplits = conf.getInt(MRJobConfig.NUM_MAPS, 1); double splitSize = (maxVal - minVal) / (double) numSplits; if (splitSize < MIN_INCREMENT) { splitSize = MIN_INCREMENT; } String lowClausePrefix = colName + " >= "; String highClausePrefix = colName + " < "; double curLower = minVal; double curUpper = curLower + splitSize; while (curUpper < maxVal) { splits.add(new DataDrivenDBInputFormat.DataDrivenDBInputSplit( lowClausePrefix + Double.toString(curLower), highClausePrefix + Double.toString(curUpper))); curLower = curUpper; curUpper += splitSize; } // Catch any overage and create the closed interval for the last split. if (curLower <= maxVal || splits.size() == 1) { splits.add(new DataDrivenDBInputFormat.DataDrivenDBInputSplit( lowClausePrefix + Double.toString(curUpper), colName + " <= " + Double.toString(maxVal))); } if (results.getString(1) == null || results.getString(2) == null) { // At least one extrema is null; add a null split. splits.add( new DataDrivenDBInputFormat.DataDrivenDBInputSplit(colName + " IS NULL", colName + " IS NULL")); } return splits; }
From source file:io.wcm.config.core.management.util.TypeConversion.java
/** * Converts a typed value to it's string representation. * @param value Typed value// ww w . ja v a 2s .c o m * @return String value */ public static String objectToString(Object value) { if (value == null) { return null; } if (value instanceof String) { return (String) value; } if (value instanceof String[]) { return StringUtils.join((String[]) value, ARRAY_DELIMITER); } else if (value instanceof Integer) { return Integer.toString((Integer) value); } else if (value instanceof Long) { return Long.toString((Long) value); } else if (value instanceof Double) { return Double.toString((Double) value); } else if (value instanceof Boolean) { return Boolean.toString((Boolean) value); } else if (value instanceof Map) { Map<?, ?> map = (Map<?, ?>) value; StringBuilder stringValue = new StringBuilder(); Map.Entry<?, ?>[] entries = Iterators.toArray(map.entrySet().iterator(), Map.Entry.class); for (int i = 0; i < entries.length; i++) { Map.Entry<?, ?> entry = entries[i]; String entryKey = Objects.toString(entry.getKey(), ""); String entryValue = Objects.toString(entry.getValue(), ""); stringValue.append(entryKey).append(KEY_VALUE_DELIMITER).append(entryValue); if (i < entries.length - 1) { stringValue.append(ARRAY_DELIMITER); } } return stringValue.toString(); } throw new IllegalArgumentException("Unsupported type: " + value.getClass().getName()); }
From source file:com.oneteam.framework.android.location.gplaces.PlacesService.java
private String makeUrl(double latitude, double longitude, String place) { StringBuilder urlString = new StringBuilder("https://maps.googleapis.com/maps/api/place/search/json?"); urlString.append("&location="); urlString.append(Double.toString(latitude)); urlString.append(","); urlString.append(Double.toString(longitude)); urlString.append("&radius=5000"); urlString.append("&keyword=" + place); urlString.append("&name=" + place); urlString.append("&sensor=false&key=" + API_KEY); return urlString.toString(); }