List of usage examples for java.lang Double compare
public static int compare(double d1, double d2)
From source file:jasima.core.util.ExperimentTest.java
protected void checkDouble(String name, double act, double exp) { if (Double.compare(exp, act) != 0) { boolean cmp = Precision.equals(act, exp, maxUlps); errorCollector.checkThat(name + "; act: " + act + "; exp: " + exp, cmp, is(true)); }/*from w w w . j av a2 s . c om*/ }
From source file:io.fouad.jtb.core.beans.InlineQueryResultVenue.java
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof InlineQueryResultVenue)) return false; if (!super.equals(o)) return false; InlineQueryResultVenue that = (InlineQueryResultVenue) o; if (Double.compare(that.latitude, latitude) != 0) return false; if (Double.compare(that.longitude, longitude) != 0) return false; if (title != null ? !title.equals(that.title) : that.title != null) return false; if (address != null ? !address.equals(that.address) : that.address != null) return false; if (foursquareId != null ? !foursquareId.equals(that.foursquareId) : that.foursquareId != null) return false; if (inputMessageContent != null ? !inputMessageContent.equals(that.inputMessageContent) : that.inputMessageContent != null) return false; if (thumbUrl != null ? !thumbUrl.equals(that.thumbUrl) : that.thumbUrl != null) return false; if (thumbWidth != null ? !thumbWidth.equals(that.thumbWidth) : that.thumbWidth != null) return false; return thumbHeight != null ? thumbHeight.equals(that.thumbHeight) : that.thumbHeight == null; }
From source file:lisong_mechlab.view.graphs.DamageGraph.java
private TableXYDataset getSeries() { final Collection<Modifier> modifiers = loadout.getModifiers(); SortedMap<Weapon, List<Pair<Double, Double>>> data = new TreeMap<Weapon, List<Pair<Double, Double>>>( new Comparator<Weapon>() { @Override// ww w . j ava2 s. com public int compare(Weapon aO1, Weapon aO2) { int comp = Double.compare(aO2.getRangeMax(modifiers), aO1.getRangeMax(modifiers)); if (comp == 0) return aO1.compareTo(aO2); return comp; } }); Double[] ranges = WeaponRanges.getRanges(loadout); for (double range : ranges) { Set<Entry<Weapon, Double>> damageDistributio = maxSustainedDPS.getWeaponRatios(range).entrySet(); for (Map.Entry<Weapon, Double> entry : damageDistributio) { final Weapon weapon = entry.getKey(); final double ratio = entry.getValue(); final double dps = weapon.getStat("d/s", modifiers); final double rangeEff = weapon.getRangeEffectivity(range, modifiers); if (!data.containsKey(weapon)) { data.put(weapon, new ArrayList<Pair<Double, Double>>()); } data.get(weapon).add(new Pair<Double, Double>(range, dps * ratio * rangeEff)); } } DefaultTableXYDataset dataset = new DefaultTableXYDataset(); for (Map.Entry<Weapon, List<Pair<Double, Double>>> entry : data.entrySet()) { XYSeries series = new XYSeries(entry.getKey().getName(), true, false); for (Pair<Double, Double> pair : entry.getValue()) { series.add(pair.first, pair.second); } dataset.addSeries(series); } return dataset; }
From source file:com.griddynamics.jagger.engine.e1.reporting.WorkloadProcessTimePlotsReporter.java
public Map<String, TaskPlotDTO> createTaskPlots() { String sessionId = getSessionIdProvider().getSessionId(); @SuppressWarnings("unchecked") List<TimeInvocationStatistics> statistics = getHibernateTemplate() .find("select t from TimeInvocationStatistics t where t.taskData.sessionId=?", sessionId); Map<String, List<TimeInvocationStatistics>> aggregatedByTasks = Maps.newLinkedHashMap(); for (TimeInvocationStatistics stat : statistics) { List<TimeInvocationStatistics> taskData = aggregatedByTasks.get(stat.getTaskData().getTaskId()); if (taskData == null) { taskData = new ArrayList<TimeInvocationStatistics>(); aggregatedByTasks.put(stat.getTaskData().getTaskId(), taskData); }/*from ww w .jav a 2 s.c o m*/ taskData.add(stat); } Map<String, TaskPlotDTO> taskPlots = Maps.newHashMap(); for (String taskId : aggregatedByTasks.keySet()) { TaskPlotDTO taskPlot = new TaskPlotDTO(); List<TimeInvocationStatistics> taskStats = aggregatedByTasks.get(taskId); XYSeries throughput = new XYSeries("Throughput"); XYSeries latency = new XYSeries("Latency avg", true, false); XYSeries latencyStdDev = new XYSeries("Latency StdDev", true, false); SortedMap<Integer, XYSeries> percentileSeries = new TreeMap<Integer, XYSeries>(); String taskName = null; for (TimeInvocationStatistics stat : taskStats) { if (taskName == null) { taskName = stat.getTaskData().getTaskName(); } throughput.add(stat.getTime(), stat.getThroughput()); latency.add(stat.getTime(), stat.getLatency()); latencyStdDev.add(stat.getTime(), stat.getLatencyStdDev()); List<TimeLatencyPercentile> percentiles = stat.getPercentiles(); if (percentiles != null && !percentiles.isEmpty()) { Collections.sort(percentiles, new Comparator<Percentile>() { @Override public int compare(Percentile p1, Percentile p2) { return Double.compare(p1.getPercentileKey(), p2.getPercentileKey()); } }); for (int i = 0; i < percentiles.size(); i++) { Percentile currentPercentile = percentiles.get(i); double previousPercentile = i > 0 ? percentiles.get(i - 1).getPercentileValue() : 0; double additivePercentileValue = (currentPercentile.getPercentileValue() - previousPercentile) / 1000; addPercentile(percentileSeries, currentPercentile.getPercentileKey(), additivePercentileValue, stat.getTime()); } } else { for (XYSeries series : percentileSeries.values()) { series.add(stat.getTime(), 0); } } } XYSeriesCollection throughputCollection = new XYSeriesCollection(); throughputCollection.addSeries(throughput); Pair<String, XYSeriesCollection> pair = ChartHelper.adjustTime(throughputCollection, null); throughputCollection = pair.getSecond(); JFreeChart chartThroughput = ChartHelper.createXYChart(null, throughputCollection, "Time (" + pair.getFirst() + ")", "Throughput (TPS)", 2, 2, ChartHelper.ColorTheme.LIGHT); taskPlot.setThroughputPlot(new JCommonDrawableRenderer(chartThroughput)); XYSeriesCollection latencyCollection = new XYSeriesCollection(); latencyCollection.addSeries(latency); latencyCollection.addSeries(latencyStdDev); XYSeriesCollection percentilesCollection = new XYSeriesCollection(); for (XYSeries series : percentileSeries.values()) { percentilesCollection.addSeries(series); } Pair<String, XYSeriesCollection> percentilesPair = ChartHelper.adjustTime(percentilesCollection, null); Pair<String, XYSeriesCollection> latencyPair = ChartHelper.adjustTime(latencyCollection, null); if (!latencyPair.getFirst().equals(percentilesPair.getFirst())) { throw new IllegalStateException("Time dimension for percentiles and latency is not equal"); } JFreeChart chartLatencyPercentiles = ChartHelper.createStackedAreaChart(null, percentilesPair.getSecond(), latencyPair.getSecond(), "Time (" + latencyPair.getFirst() + ")", "Latency (sec)", ChartHelper.ColorTheme.LIGHT); taskPlot.setLatencyPlot(new JCommonDrawableRenderer(chartLatencyPercentiles)); taskPlots.put(taskId, taskPlot); } return taskPlots; }
From source file:org.diorite.impl.entity.attrib.SimpleAttributeModifier.java
@Override public boolean equals(final Object o) { if (this == o) { return true; }//from w ww . j a va2s. co m if (!(o instanceof SimpleAttributeModifier)) { return false; } final SimpleAttributeModifier that = (SimpleAttributeModifier) o; return (Double.compare(that.value, this.value) == 0) && this.uuid.equals(that.uuid) && !((this.name != null) ? !this.name.equals(that.name) : (that.name != null)) && this.operation.equals(that.operation) && this.getModifierSlot().equals(that.getModifierSlot()) && !((this.type != null) ? !this.type.equals(that.type) : (that.type != null)); }
From source file:weatherRoute.MapHandler.java
public void testing() { //replace these with input values String origin = "Boise"; String destination = "Rexburg"; String apiQuery = "https://maps.googleapis.com/maps/api/directions/json?origin=" + origin + "&destination=" + destination + "&key=AIzaSyDbWBUUbN6UHlG9auqFVGmN6WJY9HSe8YI"; try {/*from w w w. j a v a 2s.c o m*/ URL url = new URL(apiQuery); HttpURLConnection request = (HttpURLConnection) url.openConnection(); request.connect(); JsonParser jp = new JsonParser(); JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //You have to step through the ugly, JSON within array within JSON stuff. JsonArray stepsArray = root.getAsJsonObject().getAsJsonArray("routes").get(0).getAsJsonObject() .getAsJsonArray("legs").get(0).getAsJsonObject().getAsJsonArray("steps"); //loop through steps to get city locations for (JsonElement element : stepsArray) { //this gets a string value of the distance in miles String distance = element.getAsJsonObject().get("distance").getAsJsonObject().get("text") .toString(); //parse return value and cast to a Double to be able to compare distance = distance.replace(" mi", ""); distance = distance.replace("\"", ""); Double test = Double.parseDouble(distance); //this limits out all the short .5 mile steps //should mostly get different cities now if (Double.compare(test, 10.0) > 0) { System.out.println("TEST DISTANCE: " + distance + ", " + test); JsonObject location = element.getAsJsonObject().get("end_location").getAsJsonObject(); String latitude = location.get("lat").toString(); String longitude = location.get("lng").toString(); //now I need to hit a different API and get CITY names from lat long //http://stackoverflow.com/questions/6548504/how-can-i-get-city-name-from-a-latitude-and-longitude-point //fortunately it shows me how here ^ System.out.println("TEST LOCATION LAT: " + latitude + " LONG: " + longitude); } } } catch (Exception e) { System.out.println("Error: " + e); } }
From source file:fmiquerytest.Coordinates.java
@Override public int compareTo(distance o) { return Double.compare(this.stationDistance, o.stationDistance); }
From source file:edu.clemson.lph.utils.CSVParserWrapper.java
/** * Sort everything including the top row * @param iCol column to sort (see LabeledCSVParser.getLabelIdx( ColumnLabel ) ) * @param bNumbericCompare set to true to parse column to an number before comparing *//*w ww .jav a 2s .c o m*/ protected void sort(int iCol, boolean bNumericCompare, boolean bUniqueSort) { // final ArrayList<List<String>> aRowHold = (ArrayList<List<String>>)aRows.clone(); final int iSortCol = iCol; final boolean bUnique = bUniqueSort; final boolean bNumeric = bNumericCompare; if (aRows == null || iRows <= 0 || iCol < 0 || iCol >= aRows.get(0).size()) return; Comparator<List<String>> compRows = new Comparator<List<String>>() { // Compare Strings in the indicated column. The only weird part is // numeric comparison. Try casting to Double. If both fail they are equal // if one fails it is GREATER than the other so it sorts later in the list. @Override public int compare(List<String> arg0, List<String> arg1) { int iRet = 0; String s0 = arg0.get(iSortCol); String s1 = arg1.get(iSortCol); if (bNumeric) { Double d0 = null; Double d1 = null; try { d0 = Double.parseDouble(s0); } catch (NumberFormatException e) { } try { d1 = Double.parseDouble(s1); } catch (NumberFormatException e) { } if (d0 != null && d1 != null) iRet = Double.compare(d0, d1); else if (d0 != null && d1 == null) iRet = -1; else if (d0 == null && d1 != null) iRet = 1; else iRet = 0; } else { iRet = s0.compareTo(s1); } // If the compared column values are equal find SOMETHING different or the set logic // will only include the first row with that value if (!bUnique && iRet == 0) { for (int i = arg0.size() - 1; i >= 0; i--) { if (i != iSortCol) { String s0a = arg0.get(i); String s1a = arg1.get(i); iRet = s0a.compareTo(s1a); if (iRet != 0) { break; } } } } return iRet; } }; TreeSet<List<String>> setRows = new TreeSet<List<String>>(compRows); for (List<String> lRow : aRows) setRows.add(lRow); aRows.clear(); for (List<String> lRow : setRows) { aRows.add(lRow); } iRows = aRows.size(); }
From source file:com.github.gdfm.shobaidogu.StatsUtils.java
/** * Compute top-k elements with largest values in a map from string to numbers (e.g., term frequency counts). * //from www . j a v a2 s. c o m * @param counts * the map. * @param k * how many elements to keep. * @return a map with top-k elements. */ public static <K, V extends Number> Map<K, V> topK(Map<K, V> counts, int k) { MinMaxPriorityQueue<Entry<K, V>> maxHeap = MinMaxPriorityQueue .<Entry<K, V>>orderedBy(new Comparator<Entry<K, V>>() { @Override public int compare(Entry<K, V> o1, Entry<K, V> o2) { return -1 * Double.compare(o1.getValue().doubleValue(), o2.getValue().doubleValue()); // reverse comparator } }).maximumSize(k).create(); // keep top-k for (Entry<K, V> e : counts.entrySet()) maxHeap.add(e); Map<K, V> result = Maps.newHashMapWithExpectedSize(k); for (Entry<K, V> e : maxHeap) result.put(e.getKey(), e.getValue()); return result; }
From source file:com.milaboratory.core.tree.TreeSearchParameters.java
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof TreeSearchParameters)) return false; TreeSearchParameters that = (TreeSearchParameters) o; if (Double.compare(that.maxPenalty, maxPenalty) != 0) return false; if (!Arrays.equals(maxErrors, that.maxErrors)) return false; if (!Arrays.equals(penalty, that.penalty)) return false; return true;//from ww w .j av a 2s . com }