List of usage examples for java.lang Double compareTo
public int compareTo(Double anotherDouble)
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJDoubleEditor.java
public Double getDoubleValue() { final String S_ProcName = "getDoubleValue"; Double retval;//from w ww. j a va2s . co m String text = getText(); if ((text == null) || (text.length() <= 0)) { retval = null; } else { if (!isEditValid()) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, "Field is not valid"); } try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = null; } else if (obj instanceof Float) { Float f = (Float) obj; Double v = new Double(f.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Double) { Double v = (Double) obj; if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Short) { Short s = (Short) obj; Double v = new Double(s.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Integer) { Integer i = (Integer) obj; Double v = new Double(i.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Long) { Long l = (Long) obj; Double v = new Double(l.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof BigDecimal) { BigDecimal b = (BigDecimal) obj; Double v = new Double(b.toString()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Number) { Number n = (Number) obj; Double v = new Double(n.toString()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number"); } } return (retval); }
From source file:org.openmrs.activelist.Problem.java
/** * @see java.lang.Comparable#compareTo(java.lang.Object) *///from w ww. j a va 2s. c om public int compareTo(Problem item) { Double mySW = this.sortWeight; Double theirSW = item.getSortWeight(); if ((mySW == null) && (theirSW == null)) return 0; if ((mySW == null) && (theirSW != null)) return -1; if ((mySW != null) && (theirSW == null)) return 1; return mySW.compareTo(theirSW); }
From source file:org.apache.pig.test.TestFilterOpNumeric.java
@Test public void testNumericGt() throws Throwable { File tmpFile = File.createTempFile("test", "txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); for (int i = 0; i < LOOP_COUNT; i++) { if (i % 5 == 0) { ps.println(i + ":" + (double) i); } else {/*from w ww . ja v a 2 s .c om*/ ps.println(i + 1 + ":" + (double) (i)); } } ps.close(); pig.registerQuery("A=load '" + Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext())) + "' using " + PigStorage.class.getName() + "(':') as (f1: double, f2:double);"); String query = "A = filter A by ($0 > $1 and $0 >= $1);"; log.info(query); pig.registerQuery(query); Iterator<Tuple> it = pig.openIterator("A"); tmpFile.delete(); while (it.hasNext()) { Tuple t = it.next(); Double first = Double.valueOf(t.get(0).toString()); Double second = Double.valueOf(t.get(1).toString()); assertTrue(first.compareTo(second) > 0); } }
From source file:org.apache.pig.test.TestFilterOpNumeric.java
@Test public void testNumericLt() throws Throwable { File tmpFile = File.createTempFile("test", "txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); for (int i = 0; i < LOOP_COUNT; i++) { if (i % 5 == 0) { ps.println(i + ":" + (double) i); } else {//from w ww . ja v a 2 s .c o m ps.println(i + ":" + (double) (i + 1)); } } ps.close(); pig.registerQuery("A=load '" + Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext())) + "' using " + PigStorage.class.getName() + "(':') as (a: double, b:double);"); String query = "A = filter A by ($0 <= $1 and $0 < $1);"; log.info(query); pig.registerQuery(query); Iterator<Tuple> it = pig.openIterator("A"); tmpFile.delete(); while (it.hasNext()) { Tuple t = it.next(); Double first = Double.valueOf(t.get(0).toString()); Double second = Double.valueOf(t.get(1).toString()); assertTrue(first.compareTo(second) < 0); } }
From source file:org.apache.pig.test.TestFilterOpNumeric.java
@Test public void testNumericGte() throws Throwable { File tmpFile = File.createTempFile("test", "txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); for (int i = 0; i < LOOP_COUNT; i++) { if (i % 5 == 0) { ps.println(i + ":" + (double) i); } else if (i % 3 == 0) { ps.println(i - 1 + ":" + (double) (i)); } else {/*from w w w .j av a 2s. c om*/ ps.println(i + 1 + ":" + (double) (i)); } } ps.close(); pig.registerQuery("A=load '" + Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext())) + "' using " + PigStorage.class.getName() + "(':');"); String query = "A = filter A by ($0 > $1 or $0 >= $1);"; log.info(query); pig.registerQuery(query); Iterator<Tuple> it = pig.openIterator("A"); tmpFile.delete(); while (it.hasNext()) { Tuple t = it.next(); Double first = Double.valueOf(t.get(0).toString()); Double second = Double.valueOf(t.get(1).toString()); assertTrue(first.compareTo(second) >= 0); } }
From source file:org.apache.pig.test.TestFilterOpNumeric.java
@Test public void testNumericLte() throws Throwable { File tmpFile = File.createTempFile("test", "txt"); PrintStream ps = new PrintStream(new FileOutputStream(tmpFile)); for (int i = 0; i < LOOP_COUNT; i++) { if (i % 5 == 0) { ps.println(i + ":" + (double) i); } else if (i % 3 == 0) { ps.println(i - 1 + ":" + (double) (i)); } else {/*from w w w .j a v a2s. c o m*/ ps.println(i + 1 + ":" + (double) (i)); } } ps.close(); pig.registerQuery("A=load '" + Util.encodeEscape(Util.generateURI(tmpFile.toString(), pig.getPigContext())) + "' using " + PigStorage.class.getName() + "(':') as (a: double, b:double);"); String query = "A = filter A by ($0 <= $1 or $0 < $1);"; log.info(query); pig.registerQuery(query); Iterator<Tuple> it = pig.openIterator("A"); tmpFile.delete(); while (it.hasNext()) { Tuple t = it.next(); Double first = Double.valueOf(t.get(0).toString()); Double second = Double.valueOf(t.get(1).toString()); assertTrue(first.compareTo(second) <= 0); } }
From source file:org.sakaiproject.tool.gradebook.GradeMapping.java
/** * This algorithm is slow, since it checks each grade option, starting from * the "top" (in this case an 'A'). We can make it faster by starting in the * middle (as in a bubble sort), but since there are so few grade options, I * think I'll leave it for now./*w w w .jav a 2s. c o m*/ * * @see org.sakaiproject.tool.gradebook.GradeMapping#getGrade(Double) */ public String getGrade(Double value) { if (value == null) { return null; } for (Iterator iter = getGrades().iterator(); iter.hasNext();) { String grade = (String) iter.next(); Double mapVal = (Double) gradeMap.get(grade); // If the value in the map is less than the value passed, then the // map value is the letter grade for this value if (mapVal != null && mapVal.compareTo(value) <= 0) { return grade; } } // As long as 'F' is zero, this should never happen. return null; }
From source file:org.powertac.auctioneer.AuctionService.java
private int compareQty(Double thisQty, Double otherQty) { return -thisQty.compareTo(otherQty); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJDoubleEditor.java
public void setMinValue(Double value) { final String S_ProcName = "setMinValue"; if (value == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "value"); }// w ww . j a v a2s . c om if (value.compareTo(Double.MIN_VALUE) < 0) { throw CFLib.getDefaultExceptionFactory().newArgumentUnderflowException(getClass(), S_ProcName, 1, "value", value, Float.MIN_VALUE); } minValue = value; }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJDoubleEditor.java
public void setMaxValue(Double value) { final String S_ProcName = "setMaxValue"; if (value == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "value"); }//ww w . j a va 2 s.com if (value.compareTo(Double.MAX_VALUE) > 0) { throw CFLib.getDefaultExceptionFactory().newArgumentOverflowException(getClass(), S_ProcName, 1, "value", value, Float.MAX_VALUE); } maxValue = value; }