List of usage examples for java.lang Double compareTo
public int compareTo(Double anotherDouble)
From source file:org.kalypso.jts.JTSUtilities.java
/** * @return coordinates in range sorted by distance */// w w w. j av a2 s. co m public static Coordinate[] findCoordinatesInRange(final Coordinate[] coordinates, final Coordinate base, final double radius) { final Comparator<Coordinate> comparator = new Comparator<Coordinate>() { @Override public int compare(final Coordinate c1, final Coordinate c2) { final Double d1 = Double.valueOf(c1.distance(base)); final Double d2 = Double.valueOf(c2.distance(base)); return d1.compareTo(d2); } }; final Set<Coordinate> myCoordinates = new TreeSet<>(comparator); for (final Coordinate c : coordinates) { final double distance = base.distance(c); if (distance <= radius) myCoordinates.add(c); } return myCoordinates.toArray(new Coordinate[] {}); }
From source file:ubic.gemma.web.controller.visualization.ExpressionExperimentVisualizationFormController.java
@Override public int compare(Measurement o1, Measurement o2) { PrimitiveType ptype = o1.getRepresentation(); if (ptype.equals(PrimitiveType.STRING) || ptype.equals(PrimitiveType.BOOLEAN)) { return o1.getValue().compareTo(o2.getValue()); } else if (ptype.equals(PrimitiveType.DOUBLE)) { Double d1 = Double.parseDouble(o1.getValue()); Double d2 = Double.parseDouble(o2.getValue()); return d1.compareTo(d2); } else if (ptype.equals(PrimitiveType.INT)) { Integer d1 = Integer.parseInt(o1.getValue()); Integer d2 = Integer.parseInt(o2.getValue()); return d1.compareTo(d2); } else {/*from w ww . j av a 2 s .co m*/ throw new UnsupportedOperationException("Don't know how to compare " + ptype + "'s"); } }
From source file:org.structr.schema.action.Function.java
private int compareNumberNumber(final Object o1, final Object o2) { final Double value1 = getDoubleForComparison(o1); final Double value2 = getDoubleForComparison(o2); return value1.compareTo(value2); }
From source file:edu.ku.brc.specify.toycode.mexconabio.CollectionStats.java
/** * /*from ww w . jav a 2 s .c om*/ */ public void createCharts() { loadInstCodesAndtotals(); //for (CollStatInfo csi : institutions) //{ // csi.setInstName(getProviderNameFromInstCode(csi.getProviderId())); //} List<CollStatSQLDefs> statTypes = getStatSQL(); HashMap<StatType, CollStatSQLDefs> statTypeHash = new HashMap<StatType, CollStatSQLDefs>(); for (CollStatSQLDefs cs : statTypes) { statTypeHash.put(cs.getType(), cs); } CollStatInfo totals = new CollStatInfo(" Totals"); for (CollStatInfo csi : institutions) { for (CollStatSQLDefs csqd : statTypes) { StatType type = csqd.getType(); int totVal = totals.getValue(type) + csi.getValue(type); totals.setValue(type, totVal); } } try { FileUtils.deleteDirectory(new File("reports/charts/")); } catch (IOException e) { e.printStackTrace(); } Collections.sort(institutions, new Comparator<CollStatInfo>() { @Override public int compare(CollStatInfo o1, CollStatInfo o2) { return o1.getInstName().compareToIgnoreCase(o2.getInstName()); //Integer cnt1 = o1.getTotalNumRecords(); //Integer cnt2 = o2.getTotalNumRecords(); //return cnt2.compareTo(cnt1); } }); institutions.insertElementAt(totals, 0); CollStatInfo clsi = totals; //tblWriter.logHdr(titles); int i = 0; for (CollStatInfo csi : institutions) { if (StringUtils.isEmpty(csi.getInstName())) { csi.setInstName(getProviderNameFromInstCode(csi.getProviderId())); } String title = csi.getTitle() + " - " + csi.getTotalNumRecords(); if (i == 0) { startLogging("reports", "charts", clsi.hashCode() + ".html", title, false); tblWriter.startTable(); tblInstHash.put(tblWriter, csi); } else { tblWriter.endTable(); startNewDocument(csi.hashCode() + ".html", title, false); tblInstHash.put(tblWriter, csi); tblWriter.startTable(); } if (generateChart(csi, statTypeHash)) { int total = csi.getValue(StatType.eTotalNumRecords); tblWriter.setHasLines(); tblWriter.print("<TR><TD>"); tblWriter.print(String.format("<img src=\"%s\">", csi.getChartFileName())); tblWriter.println("<BR><BR><BR><BR></TD><TD>"); tblWriter.startTable(); tblWriter.logHdr("Stat", "Percent"); int rowCnt = 0; int cnt = 0; double totalPercent = 0.0; for (StatType type : StatType.values()) { if (type == StatType.eTotalNumRecords) continue; CollStatSQLDefs csqd = statTypeHash.get(type); double dVal = (double) csi.getValue(type); double val = (((dVal / (double) total) * 100.0)); if (type.ordinal() < StatType.eHasYearOnly.ordinal()) { tblWriter.print(String.format("<TR class=\"%s\">", (rowCnt % 2 == 0 ? "od" : "ev"))); totalPercent += val; cnt++; } else { tblWriter.print(String.format("<TR>", csqd.getName())); } tblWriter.println(String.format("<TD>%s</TD><TD style=\"text-align:right\">%6.2f</TD></TR>", csqd.getName(), val)); rowCnt++; } totalPercent = Math.max(totalPercent, 0.0); double avePercent = (totalPercent / (double) cnt); tblWriter.println(String .format("<TR><TD>Average</TD><TD style=\"text-align:right\">%6.2f</TD></TR>", avePercent)); csi.setAveragePercent(avePercent); tblWriter.endTable(); tblWriter.println("</TD></TR>"); } i++; /*if (i % 25 == 0) { tblWriter.endTable(); startNewDocument("institutions"+i+".html", "Institutions " + i, false); tblWriter.setHasLines(); }*/ //if (i == 100) break; } tblWriter.endTable(); Vector<CollStatInfo> sortedByAvesList = new Vector<CollStatInfo>(institutions); Collections.sort(sortedByAvesList, new Comparator<CollStatInfo>() { @Override public int compare(CollStatInfo o1, CollStatInfo o2) { Double i1 = o1.getAveragePercent(); Double i2 = o2.getAveragePercent(); int rv = i2.compareTo(i1); if (rv == 0) { Integer cnt1 = o1.getTotalNumRecords(); Integer cnt2 = o2.getTotalNumRecords(); return cnt2.compareTo(cnt1); } return rv; } }); Integer rank = 0; String average = ""; startNewDocument("SortedByAverages.html", " Sorted By Averages", false); sortByTblWriter = tblWriter; tblWriter.startTable(); tblWriter.logHdr("Rank", "Institution", "Num of Records", "Percentage"); for (CollStatInfo csi : sortedByAvesList) { String aveStr = String.format("%8.2f", csi.getAveragePercent()); Integer cnt = csi.getTotalNumRecords(); if (!aveStr.equals(average)) { rank++; average = aveStr; } String fileName = StringUtils.replace(csi.getChartFileName(), "png", "html"); String link = String.format("<a href=\"%s\">%s</>", fileName, csi.getTitle()); tblWriter.log(rank.toString(), link, cnt.toString(), aveStr); } tblWriter.endTable(); //tblWriter.println("</BODY></HTML>"); endLogging(true); //saveInstitutions(); }
From source file:com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator.java
public void validate(Object object) throws ValidationException { String fieldName = getFieldName(); Double value; try {/*from w w w . j a v a2s. c o m*/ Object obj = this.getFieldValue(fieldName, object); if (obj == null) { return; } value = Double.valueOf(obj.toString()); } catch (NumberFormatException e) { return; } Double maxInclusiveToUse = getMaxInclusive(); Double minInclusiveToUse = getMinInclusive(); Double maxExclusiveToUse = getMaxExclusive(); Double minExclusiveToUse = getMinExclusive(); if ((maxInclusiveToUse != null && value.compareTo(maxInclusiveToUse) > 0) || (minInclusiveToUse != null && value.compareTo(minInclusiveToUse) < 0) || (maxExclusiveToUse != null && value.compareTo(maxExclusiveToUse) >= 0) || (minExclusiveToUse != null && value.compareTo(minExclusiveToUse) <= 0)) { addFieldError(fieldName, object); } }
From source file:org.dspace.storage.rdbms.DatabaseUtils.java
/** * Print any warnings about current database setup to System.err (if any). * This is utilized by both the 'test' and 'info' commandline options. * @param connection current database connection * @return boolean true if database issues found, false otherwise * @throws SQLException if database error occurs *//*ww w .ja v a2s .c om*/ private static boolean printDBIssues(Connection connection) throws SQLException { boolean issueFound = false; // Get the DB Type String dbType = getDbType(connection); // For PostgreSQL databases, we need to check for the 'pgcrypto' extension. // If it is NOT properly installed, we'll need to warn the user, as DSpace will be unable to proceed. if (dbType.equals(DBMS_POSTGRES)) { // Get version of pgcrypto available in this postgres instance Double pgcryptoAvailable = PostgresUtils.getPgcryptoAvailableVersion(connection); // Generic requirements message String requirementsMsg = "\n** DSpace REQUIRES PostgreSQL >= " + PostgresUtils.POSTGRES_VERSION + " AND " + PostgresUtils.PGCRYPTO + " extension >= " + PostgresUtils.PGCRYPTO_VERSION + " **\n"; // Check if installed in PostgreSQL & a supported version if (pgcryptoAvailable != null && pgcryptoAvailable.compareTo(PostgresUtils.PGCRYPTO_VERSION) >= 0) { // We now know it's available in this Postgres. Let's see if it is installed in this database. Double pgcryptoInstalled = PostgresUtils.getPgcryptoInstalledVersion(connection); // Check if installed in database, but outdated version if (pgcryptoInstalled != null && pgcryptoInstalled.compareTo(PostgresUtils.PGCRYPTO_VERSION) < 0) { System.out.println("\nWARNING: Required PostgreSQL '" + PostgresUtils.PGCRYPTO + "' extension is OUTDATED (installed version=" + pgcryptoInstalled + ", available version = " + pgcryptoAvailable + ")."); System.out.println(requirementsMsg); System.out.println( "To update it, please connect to your DSpace database as a 'superuser' and manually run the following command: "); System.out.println("\n ALTER EXTENSION " + PostgresUtils.PGCRYPTO + " UPDATE TO '" + pgcryptoAvailable + "';\n"); issueFound = true; } else if (pgcryptoInstalled == null) // If it's not installed in database { System.out.println("\nWARNING: Required PostgreSQL '" + PostgresUtils.PGCRYPTO + "' extension is NOT INSTALLED on this database."); System.out.println(requirementsMsg); System.out.println( "To install it, please connect to your DSpace database as a 'superuser' and manually run the following command: "); System.out.println("\n CREATE EXTENSION " + PostgresUtils.PGCRYPTO + ";\n"); issueFound = true; } } // Check if installed in Postgres, but an unsupported version else if (pgcryptoAvailable != null && pgcryptoAvailable.compareTo(PostgresUtils.PGCRYPTO_VERSION) < 0) { System.out.println("\nWARNING: UNSUPPORTED version of PostgreSQL '" + PostgresUtils.PGCRYPTO + "' extension found (version=" + pgcryptoAvailable + ")."); System.out.println(requirementsMsg); System.out.println("Make sure you are running a supported version of PostgreSQL, and then install " + PostgresUtils.PGCRYPTO + " version >= " + PostgresUtils.PGCRYPTO_VERSION); System.out.println("The '" + PostgresUtils.PGCRYPTO + "' extension is often provided in the 'postgresql-contrib' package for your operating system."); issueFound = true; } else if (pgcryptoAvailable == null) // If it's not installed in Postgres { System.out.println("\nWARNING: PostgreSQL '" + PostgresUtils.PGCRYPTO + "' extension is NOT AVAILABLE. Please install it into this PostgreSQL instance."); System.out.println(requirementsMsg); System.out.println("The '" + PostgresUtils.PGCRYPTO + "' extension is often provided in the 'postgresql-contrib' package for your operating system."); System.out.println( "Once the extension is installed globally, please connect to your DSpace database as a 'superuser' and manually run the following command: "); System.out.println("\n CREATE EXTENSION " + PostgresUtils.PGCRYPTO + ";\n"); issueFound = true; } } return issueFound; }
From source file:edu.uga.cs.fluxbuster.clustering.ClusterGenerator.java
/** * Copies candidate flux domains into a list if its candidate score is greater * than a threshold up to a limit on the size of the list. The candidate flux * domains are copied from a map of candidate flux domains. Domains are only * considered if they appear in the all domains list. Once a candidate flux * domain is copied it's corresponding domain name is removed from the all * domains list./*from ww w .ja v a 2s .c o m*/ * * @param maxCandidateDomains the limit on the total number of domains to add * @param goodCandidateThreshold the candidate score threshold * @param resultBuf the list in which to store the candidate flux domains * @param seenDomains the map of candidate flux domains. * @param allDomains this list of domains to consider */ private void addThresholdMeetingDomains(int maxCandidateDomains, double goodCandidateThreshold, List<CandidateFluxDomain> resultBuf, HashMap<String, CandidateFluxDomain> seenDomains, ArrayList<String> allDomains) { ArrayList<CandidateFluxDomain> sortedDomains = new ArrayList<CandidateFluxDomain>(); ArrayList<String> removeDomains = new ArrayList<String>(); // get all cfd's whose score is over the threshold for (String domain : allDomains) { CandidateFluxDomain temp = seenDomains.get(domain); if (this.calcCandidateScore(temp) > goodCandidateThreshold) { sortedDomains.add(temp); } } // sort them in descending order by score Collections.sort(sortedDomains, new Comparator<CandidateFluxDomain>() { @Override public int compare(CandidateFluxDomain o1, CandidateFluxDomain o2) { Double o1score = calcCandidateScore(o1); Double o2score = calcCandidateScore(o2); return o2score.compareTo(o1score); // Descending // order } }); for (CandidateFluxDomain cfd2 : sortedDomains) { if (resultBuf.size() == maxCandidateDomains) { break; } resultBuf.add(cfd2); removeDomains.add(cfd2.getDomainName()); } allDomains.removeAll(removeDomains); }
From source file:org.chromium.chrome.browser.physicalweb.UrlManager.java
/** * Get the list of URLs which are both nearby and resolved through PWS. * @param allowUnresolved If true, include unresolved URLs only if the * resolved URL list is empty.// w w w . j a v a2 s. c o m * @return A set of nearby URLs, sorted by distance. */ @VisibleForTesting public List<UrlInfo> getUrls(boolean allowUnresolved) { Set<String> resolvedUrls = mPwsResultMap.keySet(); Set<String> intersection = new HashSet<>(mNearbyUrls); intersection.retainAll(resolvedUrls); Log.d(TAG, "Get URLs With: %d nearby, %d resolved, and %d in intersection.", mNearbyUrls.size(), resolvedUrls.size(), intersection.size()); List<UrlInfo> urlInfos = null; if (allowUnresolved && resolvedUrls.isEmpty()) { urlInfos = getUrlInfoList(mNearbyUrls); } else { urlInfos = getUrlInfoList(intersection); } Collections.sort(urlInfos, new Comparator<UrlInfo>() { @Override public int compare(UrlInfo urlInfo1, UrlInfo urlInfo2) { Double distance1 = Double.valueOf(urlInfo1.getDistance()); Double distance2 = Double.valueOf(urlInfo2.getDistance()); return distance1.compareTo(distance2); } }); return urlInfos; }
From source file:org.structr.schema.action.Function.java
private int compareStringNumber(final String o1, final Number o2) { Double value1; try {// w ww .jav a 2s. com value1 = Double.parseDouble(o1); } catch (NumberFormatException nfe) { value1 = Double.NEGATIVE_INFINITY; } final Double value2 = getDoubleForComparison(o2); return value1.compareTo(value2); }
From source file:org.structr.schema.action.Function.java
private int compareNumberString(final Number o1, final String o2) { final Double value1 = getDoubleForComparison(o1); Double value2;/*from ww w .j av a2 s. co m*/ try { value2 = Double.parseDouble(o2); } catch (NumberFormatException nfe) { value2 = Double.NEGATIVE_INFINITY; } return value1.compareTo(value2); }