List of usage examples for java.lang Double compare
public static int compare(double d1, double d2)
From source file:org.apache.ode.bpel.elang.xpath10.runtime.XPath10ExpressionRuntime.java
public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException { try {// w ww .ja va 2 s . c om XPath compiledXPath = compile((OXPath10Expression) cexp); Context context = createContext((OXPath10Expression) cexp, ctx); List retVal = compiledXPath.selectNodes(context); if ((retVal.size() == 1) && !(retVal.get(0) instanceof Node)) { Document d = DOMUtils.newDocument(); // Giving our node a parent just in case it's an LValue // expression Element wrapper = d.createElement("wrapper"); Object ret = retVal.get(0); if (ret instanceof Double && !((Double) ret).isNaN()) { // safely convert a double into a long if they are numerically equal. This // makes 1 from 1.0, which is more reliable when calling web services. if (Double.compare((Double) ret, Math.ceil((Double) ret)) == 0) { // the double is actually an int/long ret = ((Double) ret).longValue(); } } Text text = d.createTextNode(ret.toString()); wrapper.appendChild(text); d.appendChild(wrapper); retVal = Collections.singletonList(text); } return retVal; } catch (JaxenException je) { handleJaxenException(je); } throw new AssertionError("UNREACHABLE"); }
From source file:edu.cudenver.bios.matrix.test.TestMatrixUtils.java
/** * Determines if dimensions and all cells are equal between the * two matrices/* www . j a v a 2s. c om*/ * * @param A matrix A * @param B matrix B * @return true if equal, false if not equal */ private boolean compareMatrices(RealMatrix A, RealMatrix B) { if (A.getRowDimension() == B.getRowDimension() && A.getColumnDimension() == B.getColumnDimension()) { for (int r = 0; r < A.getRowDimension(); r++) { for (int c = 0; c < A.getColumnDimension(); c++) { if (Double.compare(A.getEntry(r, c), B.getEntry(r, c)) != 0) { System.err.println("Value mismatch at row=" + r + ", column=" + c); return false; } } } } else { System.err.println("Dimensions do not match: A (" + A.getRowDimension() + " x " + A.getColumnDimension() + "), B (" + B.getRowDimension() + " x " + B.getColumnDimension() + ")"); return false; } return true; }
From source file:com.opengamma.financial.analytics.volatility.surface.FunctionalVolatilitySurfaceData.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }//from ww w. java 2s . com if (!(obj instanceof FunctionalVolatilitySurfaceData)) { return false; } final FunctionalVolatilitySurfaceData other = (FunctionalVolatilitySurfaceData) obj; if (_nX != other._nX) { return false; } if (_nY != other._nY) { return false; } if (Double.compare(_xMinimum, other._xMinimum) != 0) { return false; } if (Double.compare(_xMaximum, other._xMaximum) != 0) { return false; } if (Double.compare(_yMinimum, other._yMinimum) != 0) { return false; } if (Double.compare(_yMaximum, other._yMaximum) != 0) { return false; } if (Double.compare(_zMinimum, other._zMinimum) != 0) { return false; } if (Double.compare(_zMaximum, other._zMaximum) != 0) { return false; } if (!ObjectUtils.equals(_xLabel, other._xLabel)) { return false; } if (!ObjectUtils.equals(_yLabel, other._yLabel)) { return false; } if (!ObjectUtils.equals(_surface, other._surface)) { return false; } return true; }
From source file:com.rapidminer.operator.learner.tree.SelectionCreator.java
/** * Creates in parallel an example index start selection for each numerical attribute, or if * there is none, only one./* w ww .jav a 2s .com*/ * * @param operator * the operator for which the calculation is done * @return a map containing for each numerical attribute an example index array such that the * associated attribute values are in ascending order. * @throws OperatorException */ public Map<Integer, int[]> getStartSelectionParallel(Operator operator) throws OperatorException { Map<Integer, int[]> selection = new HashMap<>(); if (columnTable.getNumberOfRegularNumericalAttributes() == 0) { selection.put(0, createFullArray(columnTable.getNumberOfExamples())); } else { List<Callable<int[]>> tasks = new ArrayList<Callable<int[]>>(); final Integer[] bigSelectionArray = createFullBigArray(columnTable.getNumberOfExamples()); for (int j = columnTable.getNumberOfRegularNominalAttributes(); j < columnTable .getTotalNumberOfRegularAttributes(); j++) { final double[] attributeColumn = columnTable.getNumericalAttributeColumn(j); tasks.add(new Callable<int[]>() { @Override public int[] call() { Integer[] startSelection = Arrays.copyOf(bigSelectionArray, bigSelectionArray.length); Arrays.sort(startSelection, new Comparator<Integer>() { @Override public int compare(Integer a, Integer b) { return Double.compare(attributeColumn[a], attributeColumn[b]); } }); return ArrayUtils.toPrimitive(startSelection); } }); } List<int[]> results = null; try { results = Resources.getConcurrencyContext(operator).call(tasks); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof Error) { throw (Error) cause; } else { throw new OperatorException(cause.getMessage(), cause); } } for (int j = columnTable.getNumberOfRegularNominalAttributes(); j < columnTable .getTotalNumberOfRegularAttributes(); j++) { selection.put(j, results.get(j - columnTable.getNumberOfRegularNominalAttributes())); } } return selection; }
From source file:org.onebusaway.nyc.vehicle_tracking.impl.inference.CategoricalDist.java
@SuppressWarnings("unchecked") public T sample() { Preconditions.checkState(!_entriesToLogProbs.isEmpty(), "No entries in the CDF"); Preconditions.checkState(!Double.isInfinite(_logCumulativeProb), "No cumulative probability in CDF"); if (_entriesToLogProbs.size() == 1) { return Iterables.getOnlyElement(_entriesToLogProbs.keySet()); }// ww w . j av a 2 s. c o m if (_emd == null) { initializeDistribution(); } _emd.setNumTrials(1); final Vector sampleRes = _emd.sample(threadLocalRng.get()); final int newIdx = Iterables.indexOf(sampleRes, new Predicate<VectorEntry>() { @Override public boolean apply(VectorEntry input) { return Double.compare(input.getValue(), 0.0) >= 1; } }); // final double u = threadLocalRng.get().nextDouble(); // final int newIdx = (int) emd.inverseF(u); return (T) _entries[_objIdx.get(newIdx)]; }
From source file:org.xlsx4j.org.apache.poi.ss.usermodel.FractionFormat.java
public String format(Number num) { final double doubleValue = num.doubleValue(); final boolean isNeg = (doubleValue < 0.0f) ? true : false; final double absDoubleValue = Math.abs(doubleValue); final double wholePart = Math.floor(absDoubleValue); final double decPart = absDoubleValue - wholePart; if (wholePart + decPart == 0) { return "0"; }/* w ww. java 2 s.c om*/ // if the absolute value is smaller than 1 over the exact or maxDenom // you can stop here and return "0" // reciprocal is result of an int devision ... and so it's nearly always 0 // double reciprocal = 1/Math.max(exactDenom, maxDenom); // if (absDoubleValue < reciprocal) { // return "0"; // } //this is necessary to prevent overflow in the maxDenom calculation if (Double.compare(decPart, 0) == 0) { StringBuilder sb = new StringBuilder(); if (isNeg) { sb.append("-"); } sb.append((int) wholePart); return sb.toString(); } SimpleFraction fract = null; try { //this should be the case because of the constructor if (exactDenom > 0) { fract = SimpleFraction.buildFractionExactDenominator(decPart, exactDenom); } else { fract = SimpleFraction.buildFractionMaxDenominator(decPart, maxDenom); } } catch (RuntimeException e) { e.printStackTrace(); return Double.toString(doubleValue); } StringBuilder sb = new StringBuilder(); //now format the results if (isNeg) { sb.append("-"); } //if whole part has to go into the numerator if ("".equals(wholePartFormatString)) { int trueNum = (fract.getDenominator() * (int) wholePart) + fract.getNumerator(); sb.append(trueNum).append("/").append(fract.getDenominator()); return sb.toString(); } //short circuit if fraction is 0 or 1 if (fract.getNumerator() == 0) { sb.append(Integer.toString((int) wholePart)); return sb.toString(); } else if (fract.getNumerator() == fract.getDenominator()) { sb.append(Integer.toString((int) wholePart + 1)); return sb.toString(); } //as mentioned above, this ignores the exact space formatting in Excel if (wholePart > 0) { sb.append(Integer.toString((int) wholePart)).append(" "); } sb.append(fract.getNumerator()).append("/").append(fract.getDenominator()); return sb.toString(); }
From source file:com.htmlhifive.pitalium.image.model.RectangleArea.java
/** * ???????//from ww w. jav a 2s. co m * * @param o ? * @return ????true */ @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } RectangleArea that = (RectangleArea) o; if (Double.compare(that.x, x) != 0) { return false; } if (Double.compare(that.y, y) != 0) { return false; } if (Double.compare(that.width, width) != 0) { return false; } return Double.compare(that.height, height) == 0; }
From source file:org.diorite.entity.attrib.BasicAttributeModifier.java
@Override public boolean equals(final Object o) { if (this == o) { return true; }/*w w w .j a va 2 s .co m*/ if (!(o instanceof BasicAttributeModifier)) { return false; } final BasicAttributeModifier that = (BasicAttributeModifier) 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:com.opengamma.analytics.financial.equity.option.EquityIndexFutureOptionDefinition.java
@Override public boolean equals(final Object obj) { if (this == obj) { return true; }//from w w w . j av a2 s.c o m if (!(obj instanceof EquityIndexFutureOptionDefinition)) { return false; } final EquityIndexFutureOptionDefinition other = (EquityIndexFutureOptionDefinition) obj; if (_exerciseType != other._exerciseType) { return false; } if (_isCall != other._isCall) { return false; } if (Double.compare(_strike, other._strike) != 0) { return false; } if (Double.compare(_referencePrice, other._referencePrice) != 0) { return false; } if (Double.compare(_pointValue, other._pointValue) != 0) { return false; } if (!ObjectUtils.equals(_expiryDate, other._expiryDate)) { return false; } if (!ObjectUtils.equals(_underlying, other._underlying)) { return false; } return true; }
From source file:com.iciql.test.IciqlSuite.java
public static boolean equivalentTo(double expected, double actual) { if (Double.compare(expected, actual) == 0) { return true; }//ww w . j av a2 s .c om return Math.abs(expected - actual) <= 0.000001d; }