List of usage examples for java.lang Double Double
@Deprecated(since = "9") public Double(String s) throws NumberFormatException
From source file:io.yields.plugins.kpi.KPIReport.java
private KPIReport(String reference, Collection<ScoreResult> kpiScores) { this.reference = reference; List<ScoreResult> sortedKpiScores = new ArrayList<ScoreResult>(kpiScores); sort(sortedKpiScores, new Comparator<ScoreResult>() { @Override/* w w w. ja v a 2 s . c o m*/ public int compare(ScoreResult scoreResult, ScoreResult other) { return new Double(other.getScore()).compareTo(scoreResult.getScore()); } }); this.kpiScores = sortedKpiScores; }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Comparable<?> convertTo(Class<?> clazz, Object obj) { if (obj == null) { return null; }/*from w w w .j a v a2 s .c o m*/ if (clazz.isAssignableFrom(obj.getClass())) { return (Comparable<?>) obj; } if (clazz.isPrimitive()) { if (clazz.equals(Long.TYPE)) { clazz = Long.class; } else if (clazz.equals(Integer.TYPE)) { clazz = Integer.class; } else if (clazz.equals(Float.TYPE)) { clazz = Float.class; } else if (clazz.equals(Double.TYPE)) { clazz = Double.class; } else if (clazz.equals(Boolean.TYPE)) { clazz = Boolean.class; } } if (Number.class.isAssignableFrom(clazz)) { if (obj.getClass().equals(String.class)) { obj = new Double((String) obj); } if (!Number.class.isAssignableFrom(obj.getClass())) { throw new RuntimeException( "Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); } Number number = (Number) obj; if (clazz.equals(Long.class)) { return new Long(number.longValue()); } if (clazz.equals(Integer.class)) { return new Integer(number.intValue()); } if (clazz.equals(Float.class)) { return new Float(number.floatValue()); } if (clazz.equals(Double.class)) { return new Double(number.doubleValue()); } if (clazz.equals(BigDecimal.class)) { return new BigDecimal(number.doubleValue()); } } final String oStr = String.valueOf(obj); if (clazz.equals(String.class)) { return oStr; } if (clazz.equals(java.util.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(java.sql.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(Boolean.class)) { return new Boolean(oStr); } throw new RuntimeException("Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); }
From source file:forge.quest.QuestUtilUnlockSets.java
/** * Consider unlocking a new expansion in limited quest format. * @param qData the QuestController for the current quest * @param freeUnlock this unlock is free (e.g., a challenge reward), NOT IMPLEMENTED YET * @param presetChoices List<CardEdition> a pregenerated list of options, NOT IMPLEMENTED YET * @return CardEdition, the unlocked edition if any. *///www . j a va 2s .c om public static ImmutablePair<CardEdition, Integer> chooseSetToUnlock(final QuestController qData, final boolean freeUnlock, List<CardEdition> presetChoices) { if (qData.getFormat() == null || !qData.getFormat().canUnlockSets()) { return null; } final ReadPriceList prices = new ReadPriceList(); final Map<String, Integer> mapPrices = prices.getPriceList(); final List<ImmutablePair<CardEdition, Integer>> setPrices = new ArrayList<ImmutablePair<CardEdition, Integer>>(); for (CardEdition ed : getUnlockableEditions(qData)) { int price = UNLOCK_COST; if (mapPrices.containsKey(ed.getName() + " Booster Pack")) { price = Math.max( new Double(30 * Math.pow(Math.sqrt(mapPrices.get(ed.getName() + " Booster Pack")), 1.70)) .intValue(), UNLOCK_COST); } setPrices.add(ImmutablePair.of(ed, price)); } final String setPrompt = "You have " + qData.getAssets().getCredits() + " credits. Unlock:"; List<String> options = new ArrayList<String>(); for (ImmutablePair<CardEdition, Integer> ee : setPrices) { options.add(String.format("%s [PRICE: %d credits]", ee.left.getName(), ee.right)); } int index = options.indexOf(SGuiChoose.oneOrNone(setPrompt, options)); if (index < 0 || index >= options.size()) { return null; } ImmutablePair<CardEdition, Integer> toBuy = setPrices.get(index); int price = toBuy.right; CardEdition choosenEdition = toBuy.left; if (qData.getAssets().getCredits() < price) { SOptionPane.showMessageDialog( "Unfortunately, you cannot afford that set yet.\n" + "To unlock " + choosenEdition.getName() + ", you need " + price + " credits.\n" + "You have only " + qData.getAssets().getCredits() + " credits.", "Failed to unlock " + choosenEdition.getName(), null); return null; } if (!SOptionPane .showConfirmDialog( "Unlocking " + choosenEdition.getName() + " will cost you " + price + " credits.\n" + "You have " + qData.getAssets().getCredits() + " credits.\n\n" + "Are you sure you want to unlock " + choosenEdition.getName() + "?", "Confirm Unlocking " + choosenEdition.getName())) { return null; } return toBuy; }
From source file:org.hyperic.hq.plugin.apache.JkStatusCollector.java
private static void initConstants() { if (_filter.size() != 0) { return;//from www. j a v a 2 s . c o m } String[] keys = { //type=lb "member_count", "good", "degraded", "bad", "busy", //type=ajp13 (metrics) "state", "errors", "client_errors", "transferred", "read", "busy" }; for (int i = 0; i < keys.length; i++) { _filter.put(keys[i], Boolean.TRUE); } for (int i = 0; i < WORKER_PROPS.length; i++) { _filter.put(WORKER_PROPS[i], Boolean.TRUE); } _state.put("OK", new Double(Metric.AVAIL_UP)); _state.put("N/A", new Double(Metric.AVAIL_PAUSED)); _state.put("REC", new Double(Metric.AVAIL_WARN)); _state.put("ERR", new Double(Metric.AVAIL_DOWN)); }
From source file:servlet.SalesReportPieChart.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w. j av a 2s.c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DefaultPieDataset dataset = new DefaultPieDataset(); int totalTickets = Integer.valueOf(request.getParameter("totalTickets")); int totalSoldTickets = Integer.valueOf(request.getParameter("totalSoldTickets")); dataset.setValue("Unsold Tickets", new Double(totalTickets - totalSoldTickets)); dataset.setValue("Sold Tickets", new Double(totalSoldTickets)); JFreeChart chart = ChartFactory.createPieChart("Ticket Sales", // chart title dataset, // data true, // include legend true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setSectionPaint("Unsold Tickets", Color.DARK_GRAY); plot.setSectionPaint("Sold Tickets", Color.CYAN); plot.setExplodePercent("Unsold Tickets", 0.10); plot.setSimpleLabels(true); plot.setBackgroundPaint(Color.WHITE); PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})", new DecimalFormat("0"), new DecimalFormat("0%")); plot.setLabelGenerator(gen); final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); int width = 500; /* Width of the image */ int height = 400; /* Height of the image */ response.setContentType("image/png"); OutputStream out = response.getOutputStream(); ChartUtilities.writeChartAsPNG(out, chart, 400, 300, info); }
From source file:com.base.dao.sql.ReflectionUtils.java
public static Object convertValue(Object value, Class toType) { Object result = null;/*from w ww.j a v a 2s . c om*/ if (value != null) { if (value.getClass().isArray() && toType.isArray()) { Class componentType = toType.getComponentType(); result = Array.newInstance(componentType, Array.getLength(value)); for (int i = 0, icount = Array.getLength(value); i < icount; i++) { Array.set(result, i, convertValue(Array.get(value, i), componentType)); } } else { if ((toType == Integer.class) || (toType == Integer.TYPE)) result = Integer.valueOf((int) longValue(value)); if ((toType == Double.class) || (toType == Double.TYPE)) result = new Double(doubleValue(value)); if ((toType == Boolean.class) || (toType == Boolean.TYPE)) result = booleanValue(value) ? Boolean.TRUE : Boolean.FALSE; if ((toType == Byte.class) || (toType == Byte.TYPE)) result = Byte.valueOf((byte) longValue(value)); if ((toType == Character.class) || (toType == Character.TYPE)) result = new Character((char) longValue(value)); if ((toType == Short.class) || (toType == Short.TYPE)) result = Short.valueOf((short) longValue(value)); if ((toType == Long.class) || (toType == Long.TYPE)) result = Long.valueOf(longValue(value)); if ((toType == Float.class) || (toType == Float.TYPE)) result = new Float(doubleValue(value)); if (toType == BigInteger.class) result = bigIntValue(value); if (toType == BigDecimal.class) result = bigDecValue(value); if (toType == String.class) result = stringValue(value); if (toType == Date.class) { result = DateUtils.toDate(stringValue(value)); } if (Enum.class.isAssignableFrom(toType)) result = enumValue((Class<Enum>) toType, value); } } else { if (toType.isPrimitive()) { result = primitiveDefaults.get(toType); } } return result; }
From source file:com.github.tomakehurst.wiremock.matching.MultiValuePattern.java
private static MatchResult getBestMatch(final StringValuePattern valuePattern, List<String> values) { List<MatchResult> allResults = Lists.transform(values, new Function<String, MatchResult>() { public MatchResult apply(String input) { return valuePattern.match(input); }// ww w . j a v a2 s. c om }); return min(allResults, new Comparator<MatchResult>() { public int compare(MatchResult o1, MatchResult o2) { return new Double(o1.getDistance()).compareTo(o2.getDistance()); } }); }
From source file:org.pentaho.reporting.engine.classic.demo.ancient.demo.chartdemo.BasicExtXmlChartDemo.java
/** * Creates a sample dataset for the demo. * * @return A sample dataset./* w ww. j ava2 s. c o m*/ */ private PieDataset createSampleDataset() { final DefaultPieDataset result = new DefaultPieDataset(); result.setValue("Java", new Double(43.2)); result.setValue("Visual Basic", new Double(10.0)); result.setValue("C/C++", new Double(17.5)); result.setValue("PHP", new Double(32.5)); result.setValue("Perl", new Double(0.0)); return result; }
From source file:com.mxgraph.examples.swing.chart.PieChartDemo1.java
/** * Creates a sample dataset.//from w w w .ja v a 2 s . c om * * @return A sample dataset. */ public static PieDataset createDataset() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("", new Double(43.2)); dataset.setValue("", new Double(10.0)); dataset.setValue("Three", new Double(27.5)); dataset.setValue("Four", new Double(17.5)); dataset.setValue("Five", new Double(11.0)); dataset.setValue("Six", new Double(19.4)); return dataset; }
From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.DoubleCalculator.java
public Object sub(Object obj1, Object obj2) { Double doubleData1 = (Double) obj1; Double doubleData2 = (Double) obj2; return (Object) (new Double((double) (doubleData1.doubleValue() - doubleData2.doubleValue()))); }