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:de.bund.bfr.knime.gis.GisUtils.java

public static Point2D getCenterOfLargestPolygon(MultiPolygon poly) {
    Map<Polygon, Double> areas = new LinkedHashMap<>();

    getPolygons(poly).forEach(p -> areas.put(p, p.getArea()));

    Point center = Collections.max(areas.entrySet(), (p1, p2) -> Double.compare(p1.getValue(), p2.getValue()))
            .getKey().getCentroid();/*ww  w.  j  a va  2  s.c o  m*/

    return new Point2D.Double(center.getX(), center.getY());
}

From source file:pt.scanner.server.data.Line.java

@Override
public Coordinate lineIntersection(LineSegment line) {
    Coordinate c = super.lineIntersection(line);
    if (c == null) {
        return null;
    }/*from  ww w .ja  v a2  s .  co  m*/
    c.x = Double.compare(c.x, -0.0) == 0 ? 0.0 : c.x;
    c.y = Double.compare(c.y, -0.0) == 0 ? 0.0 : c.y;
    return c;
}

From source file:de.hsheilbronn.mi.configuration.SvmConfigurationImpl.java

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

    SvmConfigurationImpl that = (SvmConfigurationImpl) o;

    if (Double.compare(that.cacheSize, cacheSize) != 0)
        return false;
    if (Double.compare(that.coef0, coef0) != 0)
        return false;
    if (Double.compare(that.cost, cost) != 0)
        return false;
    if (crossValidation != that.crossValidation)
        return false;
    if (degree != that.degree)
        return false;
    if (Double.compare(that.eps, eps) != 0)
        return false;
    if (Double.compare(that.gamma, gamma) != 0)
        return false;
    if (nFold != that.nFold)
        return false;
    if (nrWeight != that.nrWeight)
        return false;
    if (Double.compare(that.nu, nu) != 0)
        return false;
    if (Double.compare(that.p, p) != 0)
        return false;
    if (probability != that.probability)
        return false;
    if (shrinking != that.shrinking)
        return false;
    if (kernelType != that.kernelType)
        return false;
    if (svmType != that.svmType)
        return false;
    if (!Arrays.equals(weight, that.weight))
        return false;
    return Arrays.equals(weightLabel, that.weightLabel);

}

From source file:uk.ac.susx.tag.method51.twitter.NBClassifierIGImpl.java

public IGPackage calculateIG(List<Tweet> tweets) {

    Date latest = new Date(0);
    Date earliest = new Date();

    for (Tweet tweet : tweets) {

        if (tweet.getCreated().after(latest)) {
            latest = tweet.getCreated();
        }/*from   w  ww.  ja v  a 2s.c o m*/
        if (tweet.getCreated().before(earliest)) {
            earliest = tweet.getCreated();
        }
    }

    List<ProcessedInstance> processedInstances = getProcessedInstances(tweets);
    classify(processedInstances);

    Map<String, List<String>> igFeatures = Querying
            .labelledFeatures2Strings(Querying.queryFeatures(processedInstances, null, 50), pipeline);

    String s = new Gson().toJson(igFeatures);
    System.out.println(s);

    IntSet vocab = uk.ac.susx.tag.classificationframework.Util.inferVocabulary(processedInstances);
    BiMap<Integer, Integer> features = HashBiMap.create(vocab.size());

    {
        int i = 0;
        for (int j : vocab) {
            features.put(i, j);
            ++i;
        }
    }

    int numClasses = classifier.getLabels().size();
    int numFeatures = features.size();
    int numInstances = processedInstances.size();
    int[][] classFeatureCounts = new int[numClasses][numFeatures];
    int[] featureCounts = new int[numFeatures];
    int[] classCounts = new int[numClasses];
    int[] featureClasses = new int[numFeatures];
    Arrays.fill(featureClasses, -1);

    countClassFeatures(classCounts, featureCounts, classFeatureCounts, processedInstances, features);

    final double[] IG = calcInfoGain(classCounts, featureCounts, classFeatureCounts, featureClasses, 0.1);

    final Integer[] sortedIdx = new Integer[IG.length];
    for (int i = 0; i < sortedIdx.length; ++i) {
        sortedIdx[i] = i;
    }

    Arrays.sort(sortedIdx, new Comparator<Integer>() {
        @Override
        public int compare(final Integer o1, final Integer o2) {
            return Double.compare(IG[o2], IG[o1]);
        }
    });

    int featureMass = 0;
    for (int f : featureCounts) {
        featureMass += f;
    }

    Map<String, List<Term>> out = new HashMap<>();

    int[] numIGFeaturesPerClass = new int[numClasses];

    for (int i = 0; i < classifier.getLabels().size(); i++) {

        List<Term> terms = new ArrayList<>();

        String label = pipeline.labelString(i);

        //System.out.println("---------------");
        //System.out.println(label);

        //System.out.println();

        int n = 0;
        int j = 0;
        while (n < numIGFeatures && j < IG.length) {

            int idx = sortedIdx[j];

            if (featureClasses[idx] == i) {
                String feature = pipeline.featureString(features.get(idx));

                double score = IG[idx];
                int count = featureCounts[idx];
                //int count = classFeatureCounts[i][idx];
                double PCint = (classCounts[i] - classFeatureCounts[i][idx])
                        / (double) (numInstances - featureCounts[idx]);
                double PCif = classFeatureCounts[i][idx] / (double) featureCounts[idx];
                double PfCi = classFeatureCounts[i][idx] / (double) classCounts[i];
                double Pf = featureCounts[idx] / (double) numInstances;

                //System.out.print(feature + " " + score + " " + featureClasses[idx] + " " + featureCounts[idx] + " ");
                ++n;

                Term term = new Term();
                term.setText(feature.replace("_", " "));
                term.setClassIndex(i);
                term.setInfo("score", score);
                term.setInfo("count", count);
                term.setInfo("p(c|nf)", PCint);
                term.setInfo("p(c|f)", PCif);
                term.setInfo("p(f|c)", PfCi);
                term.setInfo("p(f)", Pf);
                term.setInfo("idx", idx);

                terms.add(term);
            }
            ++j;
        }

        numIGFeaturesPerClass[i] = n;

        out.put(label, terms);

        //System.out.println();
    }

    //System.out.println();
    //System.out.println();

    if (print) {
        System.out.println(latest.toString());

        System.out.println("Num Docs " + tweets.size());
        for (int j = 0; j < numClasses; ++j) {
            System.out.println("P(C" + j + ") " + classCounts[j] / (double) numInstances);
        }

        System.out.println(String.format("%-6s %-30s %-10s %-10s %-10s %-10s %-10s %-10s %-10s", "Class",
                "Term", "IG", "Count", "p(f|c)", "p(nf|c)", "p(c|f)", "p(c|nf)", "p(f)"));

        for (int f = 0; f < numIGFeatures; ++f) {

            for (int i = 0; i < numClasses; ++i) {
                String label = pipeline.labelString(i);

                if (numIGFeaturesPerClass[i] <= f) {
                    continue;
                }
                Term term = out.get(label).get(f);

                int idx = (Integer) term.getInfo("idx");

                for (int j = 0; j < numClasses; ++j) {

                    double PCint = (classCounts[j] - classFeatureCounts[j][idx])
                            / (double) (numInstances - featureCounts[idx]);
                    double PCif = classFeatureCounts[j][idx] / (double) featureCounts[idx];

                    double PnfCi = (featureCounts[j] - classFeatureCounts[j][idx])
                            / (double) (numInstances - classCounts[j]);
                    double PfCi = classFeatureCounts[j][idx] / (double) classCounts[j];

                    double Pf = featureCounts[idx] / (double) numInstances;
                    //int count = classFeatureCounts[i][idx];
                    int count = featureCounts[idx];

                    double score = (Double) term.getInfo("score");

                    System.out.println(
                            String.format("%-6d %-30s %-10.5f %-10d %-10.5f %-10.5f %-10.5f %-10.5f %-10.5f", j,
                                    term.getText(), score, count, PfCi, PnfCi, PCif, PCint, Pf));
                }
            }
        }

        System.out.println();
        System.out.println();
    }

    IGPackage igPackage = new IGPackage();
    igPackage.classTerms = out;
    igPackage.earliest = earliest;
    igPackage.latest = latest;

    igPackage.vol = numInstances;

    return igPackage;
}

From source file:org.apache.hadoop.hive.ql.udf.UDFBetween.java

public BooleanWritable evaluate(DoubleWritable a, DoubleWritable b, DoubleWritable c) {
    if (a == null || b == null || c == null) {
        return new BooleanWritable(false);
    }//from   w  w  w. j a  va2  s  .  c om

    double aa = a.get();
    double bb = b.get();
    double cc = c.get();
    int tmp_a = Double.compare(aa, bb);
    int tmp_b = Double.compare(aa, cc);

    if (tmp_a >= 0 && tmp_b <= 0) {
        return new BooleanWritable(true);
    } else {
        return new BooleanWritable(false);
    }
}

From source file:io.yields.math.framework.kpi.ScoreResult.java

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

    ScoreResult that = (ScoreResult) o;

    if (official != that.official) {
        return false;
    }
    if (Double.compare(that.score, score) != 0) {
        return false;
    }
    if (group != null ? !group.equals(that.group) : that.group != null) {
        return false;
    }
    if (name != null ? !name.equals(that.name) : that.name != null) {
        return false;
    }

    return true;
}

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

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

    final DoubleRange that = (DoubleRange) o;

    return (Double.compare(that.max, this.max) == 0) && (Double.compare(that.min, this.min) == 0);

}

From source file:com.aurel.track.item.AddScreenshotAction.java

public String saveScreenshot() {
    LOGGER.debug("Save screenshot workItemID=" + workItemID);
    List<LabelValueBean> errors = new ArrayList<LabelValueBean>();
    if (file == null || file.length() == 0) {
        String err = getText("common.err.required",
                new String[] { getText("report.export.manager.upload.file") });
        errors.add(new LabelValueBean(err, "file"));
        JSONUtility.encodeJSONErrors(ServletActionContext.getResponse(), errors);
        return null;
    }//w w  w . j a va  2  s  .  com
    if (!file.endsWith(".png")) {
        file = file + ".png";
    }
    ApplicationBean applicationBean = (ApplicationBean) application.get(Constants.APPLICATION_BEAN);
    Double maxAttachmentSizeInMb = AttachBL.getMaxAttachmentSizeInMb(applicationBean);
    int MAXFILESIZE = AttachBL.getMaxFileSize(applicationBean);
    if (maxAttachmentSizeInMb != null && Double.compare(maxAttachmentSizeInMb.doubleValue(), 0.0) != 0) {
        MAXFILESIZE = (int) (maxAttachmentSizeInMb.doubleValue() * 1024 * 1024);
    } else {
        MAXFILESIZE = 4 * 1024 * 1024;
    }
    byte[] bytearray = null;
    try {
        bytearray = new Base64().decode(bytes);
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        LOGGER.error(ExceptionUtils.getStackTrace(e1));
        errors.add(new LabelValueBean(e1.getMessage(), "file"));
        JSONUtility.encodeJSONErrors(ServletActionContext.getResponse(), errors);
        return null;
    }

    if (bytearray.length > MAXFILESIZE) {
        errors.add(new LabelValueBean(
                getText("attachment.maxLengthExceeded", new String[] { maxAttachmentSizeInMb + "" }), "file"));
        JSONUtility.encodeJSONErrors(ServletActionContext.getResponse(), errors);
        return null;
    }
    int maxDescriptionSize = ApplicationBean.getInstance().getDescriptionMaxLength();
    if (description.length() > maxDescriptionSize) {
        errors.add(new LabelValueBean(getText("item.err.tooLong",
                new String[] { getText("common.lbl.description"), Integer.toString(maxDescriptionSize) }),
                "description"));
        JSONUtility.encodeJSONErrors(ServletActionContext.getResponse(), errors);
        return null;

    }
    InputStream is = new ByteArrayInputStream(bytearray);
    ApplicationBean appBean = ApplicationBean.getInstance();
    if (appBean.isBackupInProgress()) {
        errors.add(new LabelValueBean(getText("item.tabs.attachment.err.backupInProgress"), "file"));
        JSONUtility.encodeJSONErrors(ServletActionContext.getResponse(), errors);
        return null;
    }
    if (workItemID == null/*||workItemID.intValue()==-1*/) {
        HttpServletRequest request = org.apache.struts2.ServletActionContext.getRequest();
        HttpSession httpSession = request.getSession();
        WorkItemContext ctx = (WorkItemContext) session.get("workItemContext");
        if (ctx == null) {
            LOGGER.error("No context on session");
            errors.add(new LabelValueBean("No context on session", "file"));
            JSONUtility.encodeJSONErrors(ServletActionContext.getResponse(), errors);
            return null;
        }
        List<TAttachmentBean> attachments = ctx.getAttachmentsList();
        if (attachments == null) {
            attachments = new ArrayList<TAttachmentBean>();
        }
        String sessionID = httpSession.getId();
        try {
            AttachBL.saveLocal(workItemID, description, file, is, attachments, sessionID, personID);
        } catch (AttachBLException e) {
            String err = "";
            if (e.getLocalizedKey() != null) {
                err = getText(e.getLocalizedKey(), e.getLocalizedParameteres());
            } else {
                err = e.getMessage();
            }
            errors.add(new LabelValueBean(err, "file"));
            JSONUtility.encodeJSONErrors(ServletActionContext.getResponse(), errors);
            return null;

        }
        ctx.setAttachmentsList(attachments);
    } else {
        try {
            AttachBL.save(workItemID, description, file, is, personID);
            //add to history
            HistorySaverBL.addAttachment(workItemID, personID, locale, file, description,
                    Long.valueOf(bytearray.length), false);
        } catch (AttachBLException e) {
            LOGGER.error("Can't save attachemnt", e);
            String err = "";
            if (e.getLocalizedKey() != null) {
                err = getText(e.getLocalizedKey(), e.getLocalizedParameteres());
            } else {
                err = e.getMessage();
            }
            errors.add(new LabelValueBean(err, "file"));
            JSONUtility.encodeJSONErrors(ServletActionContext.getResponse(), errors);
            return null;
        }
    }
    description = null;
    JSONUtility.encodeJSONSuccess(ServletActionContext.getResponse());
    return null;
}

From source file:org.elasticsoftware.elasticactors.geoevents.Coordinate.java

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

    Coordinate that = (Coordinate) o;/*w  ww .  ja v  a2 s.  com*/

    if (Double.compare(that.latitude, latitude) != 0)
        return false;
    if (Double.compare(that.longitude, longitude) != 0)
        return false;

    return true;
}

From source file:com.github.igor_kudryashov.utils.notes.NotesDocument.java

/**
 * As lotus.domino.Document.replaceItemValue() method modifies the value of the document Lotus
 * Notes, but only if the new value is different from existing
 *
 * @param item//  w w  w.ja va2  s .com
 *            - the lotus.Domino.Item object.
 * @param value
 *            - the new value of Notes item.
 * @return <code>true</code> if the value has been updated, <code>false</code> otherwise.
 * @throws NotesException
 */
@SuppressWarnings("unchecked")
public static boolean updateItemValue(Item item, Object value) throws NotesException {
    Vector<Object> vec = item.getValues();
    if (value.getClass().getName().contains("Vector")) {
        if (vec.equals(value)) {
            return false;
        } else {
            item.setValues((Vector<Object>) value);
        }
    } else {
        if (vec.size() == 1) {
            if (vec.firstElement() instanceof Number) {
                // because lotus.docmino.Item.getValues() alvays return java.util.Vector with
                // Double elements for Numeric items,
                // value parameter must be converted to Double
                MutableDouble md = new MutableDouble((Number) value);
                if (Double.compare((Double) vec.firstElement(), md.getValue()) == 0) {
                    return false;
                }
            } else if (vec.firstElement() instanceof String) {
                if (vec.firstElement().equals((String) value)) {
                    return false;
                }
            } else {
                if (vec.firstElement().equals(value)) {
                    return false;
                }
            }
        }
        vec = new Vector<Object>();
        vec.add(value);
        item.setValues(vec);
    }

    return true;

}