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:io.fouad.jtb.core.beans.InlineQueryResultLocation.java

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (!(o instanceof InlineQueryResultLocation))
        return false;
    if (!super.equals(o))
        return false;

    InlineQueryResultLocation that = (InlineQueryResultLocation) o;

    if (Double.compare(that.latitude, latitude) != 0)
        return false;
    if (Double.compare(that.longitude, longitude) != 0)
        return false;
    if (title != null ? !title.equals(that.title) : that.title != null)
        return false;
    if (inputMessageContent != null ? !inputMessageContent.equals(that.inputMessageContent)
            : that.inputMessageContent != null)
        return false;
    if (thumbUrl != null ? !thumbUrl.equals(that.thumbUrl) : that.thumbUrl != null)
        return false;
    if (thumbWidth != null ? !thumbWidth.equals(that.thumbWidth) : that.thumbWidth != null)
        return false;
    return thumbHeight != null ? thumbHeight.equals(that.thumbHeight) : that.thumbHeight == null;

}

From source file:yaphyre.core.math.Vector3D.java

@Override
public int compareTo(@Nonnull Vector3D vector3D) {
    return Double.compare(this.lengthSquared(), vector3D.lengthSquared());
}

From source file:com.proofpoint.units.Duration.java

@Override
public int compareTo(Duration o) {
    return Double.compare(getValue(MILLISECONDS), o.getValue(MILLISECONDS));
}

From source file:br.com.OCTur.view.ClassificacaoController.java

@FXML
private void dpDatasActionEvent(ActionEvent actionEvent) {
    if (dpInicio.getValue() != null && dpFim.getValue() != null) {
        Date inicio = DateFormatter.toDate(dpInicio.getValue());
        Date fim = DateFormatter.toDate(dpFim.getValue());
        cidades.clear();/*from   w  w  w.j  av a2  s .com*/
        for (Cidade cidade : new CidadeDAO().pegarTodos()) {
            double total = new PassagemDAO().pegarPorDestinoInicioFim(cidade, inicio, fim).stream()
                    .mapToDouble(Passagem::getNumeropessoas).sum();
            cidades.add(new EntidadeGrafico<>(cidade, total));
        }
        double max = cidades.stream().mapToDouble(EntidadeGrafico::getValue).max().orElse(0);
        for (EntidadeGrafico<Cidade> cidade : cidades) {
            cidade.setValue(cidade.getValue() * 100 / max);
        }
        cidades.sort((EntidadeGrafico<Cidade> o1,
                EntidadeGrafico<Cidade> o2) -> Double.compare(o1.getValue(), o2.getValue()) * -1);
    }
}

From source file:org.esa.beam.framework.dataop.resamp.BiSincInterpolationResampling.java

private static double sinc(final double x) {
    return (Double.compare(x, 0.0) == 0) ? 1.0 : FastMath.sin(x * Math.PI) / (x * Math.PI);
}

From source file:edu.txstate.dmlab.clusteringwiki.web.AdminController.java

/**
 * Get admin page/*  w ww . java 2s  . co  m*/
 * 
 * @param request
 * @param response
 * @param model
 * @return
 */
@RequestMapping("admin.*")
public String getAdminPage(HttpServletRequest request, HttpServletResponse response, Model model) {

    if (!applicationUser.isLoggedIn() || !applicationUser.isAdmin()) {
        request.setAttribute("message", "You must be logged in as Administrator to access this page.");
        return "pageError";
    }

    String action = request.getParameter("applAction");
    if (action != null && action.equals("saveSettings") && isAjaxRequest(request)) {

        JSONArray errors = new JSONArray();

        ApplicationSettings.setTimingEnabled(request.getParameter("timingEnabled"));

        try {
            int topKQueryUrls = Integer.parseInt(request.getParameter("topKQueryUrls"));
            if (topKQueryUrls > -1 && topKQueryUrls < 1001)
                ApplicationSettings.setTopKQueryUrls(topKQueryUrls);
            else
                errors.put("topKQueryUrls must be an integer between 0 and 1000.");
        } catch (NumberFormatException e) {
            errors.put("topKQueryUrls must be an integer between 0 and 1000.");
        }

        try {
            int maxClusteringIterations = Integer.parseInt(request.getParameter("maxClusteringIterations"));
            if (maxClusteringIterations > -1 && maxClusteringIterations < 101)
                ApplicationSettings.setMaxClusteringIterations(maxClusteringIterations);
            else
                errors.put("maxClusteringIterations must be an ineger between 0 and 100.");
        } catch (NumberFormatException e) {
            errors.put("maxClusteringIterations must be an ineger between 0 and 100.");
        }

        String similarityCalculator = request.getParameter("similarityCalculator");
        if (similarityCalculator != null) {
            if (similarityCalculator.equals("jaccard")) {
                ApplicationSettings.setSimilarityCalculator(new JaccardSimilarityCalculator());
            } else if (similarityCalculator.equals("cosine")) {
                ApplicationSettings.setSimilarityCalculator(new CosineSimilarityCalculator());
            } else {
                errors.put("Invalid similarityCalculator choice.");
            }
        }

        try {
            int termSimQueryResultsLimit = Integer.parseInt(request.getParameter("termSimQueryResultsLimit"));
            if (termSimQueryResultsLimit > -1 && termSimQueryResultsLimit < 1001)
                ApplicationSettings.setTermSimQueryResultsLimit(termSimQueryResultsLimit);
            else
                errors.put("termSimQueryResultsLimit must be an integer between 0 and 1000.");
        } catch (NumberFormatException e) {
            errors.put("termSimQueryResultsLimit must be an integer between 0 and 1000.");
        }

        try {
            double termSimThreshold = Double.parseDouble(request.getParameter("termSimThreshold"));
            if (Double.compare(termSimThreshold, 0.0D) >= 0 && Double.compare(termSimThreshold, 1.0D) <= 0)
                ApplicationSettings.setTermSimThreshold(termSimThreshold);
            else
                errors.put("termSimThreshold must be a double between 0.0 and 1.0.");
        } catch (NumberFormatException e) {
            errors.put("termSimThreshold must be a double between 0.0 and 1.0.");
        }

        try {
            double resultSimThreshold = Double.parseDouble(request.getParameter("resultSimThreshold"));
            if (Double.compare(resultSimThreshold, 0.0D) >= 0 && Double.compare(resultSimThreshold, 1.0D) <= 0)
                ApplicationSettings.setResultSimThreshold(resultSimThreshold);
            else
                errors.put("resultSimThreshold must be a double between 0.0 and 1.0.");
        } catch (NumberFormatException e) {
            errors.put("resultSimThreshold must be a double between 0.0 and 1.0.");
        }

        if (errors.length() == 0) {
            sendOutput(response, "{\"success\":true}");
        } else {
            sendOutput(response, "{\"errors\":" + errors + "}");
        }

        return null;
    }

    return "admin";
}

From source file:org.apache.hadoop.mapred.TestSequenceFileAsBinaryOutputFormat.java

public void testBinary() throws IOException {
    JobConf job = new JobConf();
    FileSystem fs = FileSystem.getLocal(job);

    Path dir = new Path(
            new Path(new Path(System.getProperty("test.build.data", ".")), FileOutputCommitter.TEMP_DIR_NAME),
            "_" + attempt);
    Path file = new Path(dir, "testbinary.seq");
    Random r = new Random();
    long seed = r.nextLong();
    r.setSeed(seed);/*ww  w .  j  a v  a2 s  .  co m*/

    fs.delete(dir, true);
    if (!fs.mkdirs(dir)) {
        fail("Failed to create output directory");
    }

    job.set("mapred.task.id", attempt);
    FileOutputFormat.setOutputPath(job, dir.getParent().getParent());
    FileOutputFormat.setWorkOutputPath(job, dir);

    SequenceFileAsBinaryOutputFormat.setSequenceFileOutputKeyClass(job, IntWritable.class);
    SequenceFileAsBinaryOutputFormat.setSequenceFileOutputValueClass(job, DoubleWritable.class);

    SequenceFileAsBinaryOutputFormat.setCompressOutput(job, true);
    SequenceFileAsBinaryOutputFormat.setOutputCompressionType(job, CompressionType.BLOCK);

    BytesWritable bkey = new BytesWritable();
    BytesWritable bval = new BytesWritable();

    RecordWriter<BytesWritable, BytesWritable> writer = new SequenceFileAsBinaryOutputFormat()
            .getRecordWriter(fs, job, file.toString(), Reporter.NULL);

    IntWritable iwritable = new IntWritable();
    DoubleWritable dwritable = new DoubleWritable();
    DataOutputBuffer outbuf = new DataOutputBuffer();
    LOG.info("Creating data by SequenceFileAsBinaryOutputFormat");
    try {
        for (int i = 0; i < RECORDS; ++i) {
            iwritable = new IntWritable(r.nextInt());
            iwritable.write(outbuf);
            bkey.set(outbuf.getData(), 0, outbuf.getLength());
            outbuf.reset();
            dwritable = new DoubleWritable(r.nextDouble());
            dwritable.write(outbuf);
            bval.set(outbuf.getData(), 0, outbuf.getLength());
            outbuf.reset();
            writer.write(bkey, bval);
        }
    } finally {
        writer.close(Reporter.NULL);
    }

    InputFormat<IntWritable, DoubleWritable> iformat = new SequenceFileInputFormat<IntWritable, DoubleWritable>();
    int count = 0;
    r.setSeed(seed);
    DataInputBuffer buf = new DataInputBuffer();
    final int NUM_SPLITS = 3;
    SequenceFileInputFormat.addInputPath(job, file);
    LOG.info("Reading data by SequenceFileInputFormat");
    for (InputSplit split : iformat.getSplits(job, NUM_SPLITS)) {
        RecordReader<IntWritable, DoubleWritable> reader = iformat.getRecordReader(split, job, Reporter.NULL);
        try {
            int sourceInt;
            double sourceDouble;
            while (reader.next(iwritable, dwritable)) {
                sourceInt = r.nextInt();
                sourceDouble = r.nextDouble();
                assertEquals("Keys don't match: " + "*" + iwritable.get() + ":" + sourceInt + "*", sourceInt,
                        iwritable.get());
                assertTrue("Vals don't match: " + "*" + dwritable.get() + ":" + sourceDouble + "*",
                        Double.compare(dwritable.get(), sourceDouble) == 0);
                ++count;
            }
        } finally {
            reader.close();
        }
    }
    assertEquals("Some records not found", RECORDS, count);
}

From source file:org.briljantframework.array.netlib.NetlibLinearAlgebraRoutinesTest.java

@Test
public void testCi() throws Exception {
    final int n = 3;
    // DoubleArray a =
    // bj.newDoubleVector(-1.01, 3.98, 3.30, 4.43, 7.31, 0.86, 0.53, 8.26, 4.96, -6.43, -4.60,
    // -7.04, -3.89, -7.66, -6.16, 3.31, 5.29, 8.20, -7.33, 2.47, -4.81, 3.55, -1.51, 6.18,
    // 5.58).reshape(n, n);
    // System.out.println(a);

    DoubleArray a = bj.newDoubleMatrix(new double[][] { { 0, 2, 3 }, { 2, 0, 2 }, { 3, 2, 0 } });

    DoubleArray wr = bj.newDoubleArray(n);
    DoubleArray wi = bj.newDoubleArray(n);
    DoubleArray vl = bj.newDoubleArray(n, n);
    DoubleArray vr = bj.newDoubleArray(n, n);
    DoubleArray copy = a.copy();/*from w w w  .j av a  2  s .com*/
    // linalg.geev('v', 'v', copy, wr, wi, vl, vr);
    linalg.syev('v', 'u', copy, wr);

    wr.sort((i, j) -> Double.compare(j, i));
    System.out.println(copy);
    System.out.println(wr);

    ComplexArray v = bj.newComplexArray(n, n);
    for (int i = 0; i < n; i++) {
        if (Precision.equals(wi.get(i), 0, 1e-6)) {
            v.setColumn(i, vr.getColumn(i).asComplex());
        } else {
            DoubleArray real = vr.getColumn(i);
            DoubleArray imag = vr.getColumn(i + 1);
            v.setColumn(i, toComplex(real, imag));
            v.setColumn(i + 1, toComplex(real, imag.negate()));
            i++;
        }
    }
    //    System.out.println(v);

    RealMatrix matrix = Matrices.asRealMatrix(a);
    EigenDecomposition d = new EigenDecomposition(matrix);
    System.out.println(Matrices.toArray(d.getD()));
    System.out.println(Matrices.toArray(d.getV()));
    // System.out.println(d.getEigenvector(0));
    System.out.println(Arrays.toString(d.getRealEigenvalues()));
    // System.out.println(Arrays.toString(d.getImagEigenvalues()));
}

From source file:it.unibo.alchemist.model.implementations.actions.ChangeBiomolConcentrationInEnv.java

@Override
public void execute() {
    // declaring a variable for the node where this action is set, to have faster access
    final Node<Double> thisNode = getNode();
    // get the environment surrounding
    final List<EnvironmentNode> environmentNodesSurrounding = getEnvironmentNodesSurrounding();
    // if the node is an EnvironmentNode...
    if (thisNode instanceof EnvironmentNode) {
        // sort the env node randomly
        changeConcentrationInRandomNodes(environmentNodesSurrounding);
    } else {// w  ww. ja va2s . co m
        // if getNode() instanceof CellNode, check if all nodes are at the same distance
        final boolean areAllEnvNodesAtTheSameDistance = environmentNodesSurrounding.stream()
                .mapToDouble(n -> env.getDistanceBetweenNodes(thisNode, n)).distinct().count() == 1;
        if (areAllEnvNodesAtTheSameDistance) {
            // if they are, check if they have all the same concentration of the biomolecule
            final boolean haveAllNodeTheSameConcentration = environmentNodesSurrounding.stream()
                    .mapToDouble(n -> n.getConcentration(biomolecule)).distinct().count() == 1;
            if (haveAllNodeTheSameConcentration) {
                // if they have, pick up from the list randomly
                changeConcentrationInRandomNodes(environmentNodesSurrounding);
            } else {
                // else, sort the list by the concentration of the biomolecule
                environmentNodesSurrounding.sort((n1, n2) -> Double.compare(n1.getConcentration(biomolecule),
                        n2.getConcentration(biomolecule)));
                changeConcentrationInSortedNodes(environmentNodesSurrounding);
            }
        } else {
            // else, sort the list by the distance from the node
            environmentNodesSurrounding
                    .sort((n1, n2) -> Double.compare(env.getDistanceBetweenNodes(thisNode, n1),
                            env.getDistanceBetweenNodes(thisNode, n2)));
            changeConcentrationInSortedNodes(environmentNodesSurrounding);
        }
    }
}

From source file:org.dspace.rdf.negotiation.Negotiator.java

/**
 * Method to get a comparator to compare media ranges regarding their 
 * content negotiation precedence. Following RFC 2616 a media range is 
 * higher prioritized then another media range if the first one has a higher 
 * quality value then the second. If both quality values are equal, the 
 * media range that is more specific should be used.
 * //from w  w  w  .  ja  va2  s  .  co m
 * <p>Note: this comparator imposes orderings that are inconsistent with 
 * equals! Caution should be exercised when using it to order a sorted set
 * or a sorted map. Take a look at the java.util.Comparator for further 
 * information.</p>
 * @return A comparator that imposes orderings that are inconsistent with equals!
 */
public static Comparator<MediaRange> getMediaRangeComparator() {
    return new Comparator<MediaRange>() {

        @Override
        public int compare(MediaRange mr1, MediaRange mr2) {
            if (Double.compare(mr1.qvalue, mr2.getQvalue()) != 0) {
                return Double.compare(mr1.qvalue, mr2.getQvalue());
            }
            if (mr1.typeIsWildcard() && mr2.typeIsWildcard())
                return 0;
            if (mr1.typeIsWildcard() && !mr2.typeIsWildcard())
                return -1;
            if (!mr1.typeIsWildcard() && mr2.typeIsWildcard())
                return 1;
            if (mr1.subtypeIsWildcard() && mr2.subtypeIsWildcard())
                return 0;
            if (mr1.subtypeIsWildcard() && !mr2.subtypeIsWildcard())
                return -1;
            if (!mr1.subtypeIsWildcard() && mr2.subtypeIsWildcard())
                return 1;

            // if the quality of two media ranges is equal and both don't 
            // use an asterisk either as type or subtype, they are equal in 
            // the sense of content negotiation precedence.
            return 0;
        }
    };
}