Example usage for java.lang Double compare

List of usage examples for java.lang Double compare

Introduction

In this page you can find the example usage for java.lang Double compare.

Prototype

public static int compare(double d1, double d2) 

Source Link

Document

Compares the two specified double values.

Usage

From source file:edu.clemson.lph.utils.LabeledCSVParser.java

/**
 * Sort everything but the top row/*from  w  w  w. j a v a 2  s . c  o m*/
 * NOTE: This is a unique sort the values in iCol should be unique or duplicates will be trimmed randomly.
 * @param iCol  column to sort (see LabeledCSVParser.getLabelIdx( ColumnLabel ) )
 * @param bNumbericCompare set to true to parse column to an number before comparing
 */
@Override
public void sort(int iCol, boolean bNumericCompare, boolean bUniqueSort) {
    final int iSortCol = iCol;
    final boolean bNumeric = bNumericCompare;
    final boolean bUnique = bUniqueSort;
    //      final ArrayList<List<String>> aRowsHold = (ArrayList<List<String>>)aRows.clone();
    if (aRows == null || iRows <= 1 || iCol < 0 || iCol >= aRows.get(0).size())
        return;
    ArrayList<String> lHeader = (ArrayList<String>) aRows.get(0);
    List<List<String>> lRows = aRows.subList(1, aRows.size());
    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)
                    return -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 : lRows)
        setRows.add(lRow);
    aRows.clear();
    aRows.add(lHeader);
    for (List<String> lRow : setRows) {
        aRows.add(lRow);
    }
    iRows = aRows.size();
}

From source file:org.openiot.gsn.http.rest.PushDelivery.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;
    PushDelivery that = (PushDelivery) o;
    if (Double.compare(that.notificationId, notificationId) != 0)
        return false;
    if (httpPut != null ? !httpPut.getURI().equals(that.httpPut.getURI()) : that.httpPut != null)
        return false;
    return true;//from   w w w .j a va  2s  .  co m
}

From source file:org.deeplearning4j.clustering.kdtree.KDTree.java

public List<Pair<Double, INDArray>> knn(INDArray point, double distance) {
    List<Pair<Double, INDArray>> best = new ArrayList<>();
    knn(root, point, rect, distance, best, 0);
    Collections.sort(best, new Comparator<Pair<Double, INDArray>>() {
        @Override//from w  w  w . j  av  a  2  s. c o m
        public int compare(Pair<Double, INDArray> o1, Pair<Double, INDArray> o2) {
            return Double.compare(o1.getKey(), o2.getKey());
        }
    });

    return best;
}

From source file:org.niord.core.aton.vo.AtonNodeVo.java

/** {@inheritDoc} */
@Override//from w w w.  j a  v  a 2  s  .c  o  m
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;

    AtonNodeVo that = (AtonNodeVo) o;

    if (id != that.id)
        return false;
    if (Double.compare(that.lat, lat) != 0)
        return false;
    if (Double.compare(that.lon, lon) != 0)
        return false;
    if (uid != that.uid)
        return false;
    if (visible != that.visible)
        return false;
    if (version != that.version)
        return false;
    if (changeset != that.changeset)
        return false;
    if (user != null ? !user.equals(that.user) : that.user != null)
        return false;
    if (timestamp != null ? !timestamp.equals(that.timestamp) : that.timestamp != null)
        return false;
    // Probably incorrect - comparing Object[] arrays with Arrays.equals
    return Arrays.equals(tags, that.tags);

}

From source file:com.inform.jamps.solver.gurobi.GurobiVariable.java

@Override
public int compareTo(final Variable var) {
    if (!(var instanceof GurobiVariable)) {
        return -1;
    }/*  w  w  w .j  a  v  a2 s  .  c o  m*/

    int result = name.compareTo(var.getName());
    if (result != 0) {
        return result;
    }

    result = type.compareTo(var.getType());
    if (result != 0) {
        return result;
    }

    result = Double.compare(lowerBound, var.getLowerBound());
    if (result != 0) {
        return result;
    }

    return Double.compare(upperBound, var.getUpperBound());
}

From source file:io.coala.time.AbstractInstant.java

/** @see Comparable#compareTo(Object) */
@Override/*from ww w.j ava 2s.co m*/
public int compareTo(final Instant<?> other) {
    final int compareClockID = getClockID().compareTo(other.getClockID());
    if (compareClockID != 0)
        return compareClockID;

    return Double.compare(doubleValue(), other.toUnit(getUnit()).doubleValue());
}

From source file:org.diorite.utils.math.DioriteRandom.java

public double getRandDouble(final double min, final double max) throws IllegalArgumentException {
    if (Double.compare(min, max) == 0) {
        return max;
    }//from   ww  w. j  av  a2s  . c o m
    Validate.isTrue(max > min, "Max can't be smaller than min!");
    return (this.nextDouble() * (max - min)) + min;
}

From source file:lisong_mechlab.view.graphs.DpsGraph.java

private TableXYDataset getSeries() {
    final Collection<Modifier> modifiers = loadout.getModifiers();
    SortedMap<Weapon, Integer> multiplicity = new TreeMap<Weapon, Integer>(new Comparator<Weapon>() {
        @Override//from  w w  w . ja v a  2  s  .c  o  m
        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;
        }
    });

    for (Weapon weapon : loadout.items(Weapon.class)) {
        if (!weapon.isOffensive())
            continue;
        if (!multiplicity.containsKey(weapon)) {
            multiplicity.put(weapon, 0);
        }
        int v = multiplicity.get(weapon);
        multiplicity.put(weapon, v + 1);
    }

    List<Weapon> orderedWeapons = new ArrayList<>();
    Double[] ranges = WeaponRanges.getRanges(multiplicity.keySet(), modifiers);
    DefaultTableXYDataset dataset = new DefaultTableXYDataset();
    for (Map.Entry<Weapon, Integer> e : multiplicity.entrySet()) {
        Weapon weapon = e.getKey();
        int mult = e.getValue();

        XYSeries series = new XYSeries(weapon.getName(), true, false);
        for (double range : ranges) {
            final double dps = weapon.getStat("d/s", modifiers);
            final double rangeEff = weapon.getRangeEffectivity(range, modifiers);
            series.add(range, dps * rangeEff * mult);
        }
        dataset.addSeries(series);
        orderedWeapons.add(e.getKey());
    }
    Collections.reverse(orderedWeapons);
    colours.updateColoursToMatch(orderedWeapons);
    return dataset;
}

From source file:org.diorite.map.MapIcon.java

@Override
public boolean equals(final Object o) {
    if (this == o) {
        return true;
    }/*from w  w  w.j  a v  a  2  s  . c o m*/
    if (!(o instanceof MapIcon)) {
        return false;
    }

    final MapIcon mapIcon = (MapIcon) o;

    return this.id.equals(mapIcon.id) && (Double.compare(mapIcon.x, this.x) == 0)
            && (Double.compare(mapIcon.z, this.z) == 0)
            && (Double.compare(mapIcon.direction, this.direction) == 0) && this.type.equals(mapIcon.type);
}

From source file:com.act.analysis.surfactant.AtomSplit.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;

    AtomSplit that = (AtomSplit) o;/*from   w w w  .jav a2  s.c o  m*/

    if (Double.compare(that.leftSum, leftSum) != 0)
        return false;
    if (Double.compare(that.rightSum, rightSum) != 0)
        return false;
    if (Double.compare(that.weightedLeftSum, weightedLeftSum) != 0)
        return false;
    if (Double.compare(that.weightedRightSum, weightedRightSum) != 0)
        return false;
    if (leftPosCount != that.leftPosCount)
        return false;
    if (leftNegCount != that.leftNegCount)
        return false;
    if (rightPosCount != that.rightPosCount)
        return false;
    if (rightNegCount != that.rightNegCount)
        return false;
    if (Double.compare(that.leftMin, leftMin) != 0)
        return false;
    if (Double.compare(that.leftMax, leftMax) != 0)
        return false;
    if (Double.compare(that.rightMin, rightMin) != 0)
        return false;
    if (Double.compare(that.rightMax, rightMax) != 0)
        return false;
    if (leftIndices != null ? !leftIndices.equals(that.leftIndices) : that.leftIndices != null)
        return false;
    return !(rightIndices != null ? !rightIndices.equals(that.rightIndices) : that.rightIndices != null);

}