Example usage for java.lang Double compareTo

List of usage examples for java.lang Double compareTo

Introduction

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

Prototype

public int compareTo(Double anotherDouble) 

Source Link

Document

Compares two Double objects numerically.

Usage

From source file:AlgorithmAnimation.java

public void run() {
    Comparator<Double> comp = new Comparator<Double>() {
        public int compare(Double i1, Double i2) {
            component.setValues(values, i1, i2);
            try {
                if (run)
                    Thread.sleep(DELAY);
                else
                    gate.acquire();/*  w w  w  .j av a2  s  .c o  m*/
            } catch (InterruptedException exception) {
                Thread.currentThread().interrupt();
            }
            return i1.compareTo(i2);
        }
    };
    Arrays.sort(values, comp);
    component.setValues(values, null, null);
}

From source file:main.java.edu.isistan.genCom.redSocial.RedSocial.java

/**
 * Obtiene las distancias no dirigidas de cada candidato en comisionNodes al
 * resto de la red//from   w  w  w  .  j  av  a2  s  .c o m
 * 
 * @param comisionNodes
 *            coleccion de nodos
 * @return
 */
public List<Double> getDistanciasProportion(List<Investigador> comisionNodes) {
    List<Double> distancias = new ArrayList<>();
    UnweightedShortestPath<Investigador, String> uWSP = new UnweightedShortestPath(red);
    Double diameter = getDiameter();
    List<Investigador> nodos = getNodos();

    for (Investigador nodo : nodos) {
        Double minDistanceK = diameter;

        if (!comisionNodes.contains(nodo)) {

            for (Investigador miembro : comisionNodes) {

                Double d = uWSP.getDistance(miembro, nodo).doubleValue();

                minDistanceK = d.compareTo(minDistanceK) < 0 ? d : minDistanceK;
            }

            distancias.add(minDistanceK);
        }
    }

    return distancias;

}

From source file:com.zilbo.flamingSailor.TE.model.Component.java

@Override
/**//  w ww .j  a  v a 2 s  .  c  om
 * j
 * Sorts text pieces by position by comparing the location of this text piece
 *  with a given text piece t
 * @param t
 *       the text piece to compare with
 * @return
 *       the comparison result
 *            -1: this text piece is located in the left-side or the top of another text piece t
 *             1: this text piece is located in the right-side or the below of another text piece t
 *             0: this text piece is located in the same location as another text piece t
 */
public int compareTo(Component t) {
    //   Line2D g1 = this.getGeom();
    //  Line2D g2 = t.getGeom();
    // int ret;
    /*
    if (g1.getP1() == g2.getP1() && g1.getP2() == g2.getP2()) {
    ret = 0;
    //   logger.info(ret + "\t" + GeomUtil.getRectangleDebug(g1) + "\t" + GeomUtil.getRectangleDebug(g2));
    return ret;
    }
    */

    if (onSameLine(t)) {
        //ret = new Long(Math.round(y1 / 10)).compareTo(Math.round(y2 / 10));
        //if (ret == 0) {
        //if ( Math.abs(y1-y2) <2) {
        Double x1 = getGeom().getMinX();
        return x1.compareTo(t.getGeom().getMinX());

    } else {
        Double y1 = getGeom().getMinY();
        // double y2 = g2.getY1();

        return y1.compareTo(t.getGeom().getMinY());
    }
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.teacher.onlineTests.SimulateTest.java

private InfoQuestion correctQuestionValues(InfoQuestion infoQuestion, Double questionValue) {
    Double maxValue = Double.valueOf(0);
    for (ResponseProcessing responseProcessing : infoQuestion.getResponseProcessingInstructions()) {
        if (responseProcessing.getAction().intValue() == ResponseProcessing.SET
                || responseProcessing.getAction().intValue() == ResponseProcessing.ADD) {
            if (maxValue.compareTo(responseProcessing.getResponseValue()) < 0) {
                maxValue = responseProcessing.getResponseValue();
            }/*from w  ww . jav a2s .co m*/
        }
    }
    if (maxValue.compareTo(questionValue) != 0) {
        double difValue = questionValue * Math.pow(maxValue, -1);
        for (ResponseProcessing responseProcessing : infoQuestion.getResponseProcessingInstructions()) {
            responseProcessing
                    .setResponseValue(Double.valueOf(responseProcessing.getResponseValue() * difValue));
        }
    }

    return infoQuestion;
}

From source file:nl.b3p.viewer.stripes.CycloramaActionBean.java

public Resolution directRequest() throws UnsupportedEncodingException, URISyntaxException, URIException,
        IOException, SAXException, ParserConfigurationException {
    Double x1 = x - offset;//from ww  w .jav  a 2  s  . c  o  m
    Double y1 = y - offset;
    Double x2 = x + offset;
    Double y2 = y + offset;
    final String username = "B3_develop";
    final String password = "8ndj39";
    GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();

    Coordinate coord = new Coordinate(x, y);
    Point point = geometryFactory.createPoint(coord);

    URL url2 = new URL(
            "https://atlas.cyclomedia.com/recordings/wfs?service=WFS&VERSION=1.1.0&maxFeatures=100&request=GetFeature&SRSNAME=EPSG:28992&typename=atlas:Recording"
                    + "&filter=<Filter><And><BBOX><gml:Envelope%20srsName=%27EPSG:28992%27>"
                    + "<gml:lowerCorner>" + x1.intValue() + "%20" + y1.intValue() + "</gml:lowerCorner>"
                    + "<gml:upperCorner>" + x2.intValue() + "%20" + y2.intValue()
                    + "</gml:upperCorner></gml:Envelope></BBOX><ogc:PropertyIsNull><ogc:PropertyName>expiredAt</ogc:PropertyName></ogc:PropertyIsNull></And></Filter>");

    Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password.toCharArray());
        }
    });
    InputStream is = url2.openStream();

    // wrap the urlconnection in a bufferedreader
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));

    String line;

    StringBuilder content = new StringBuilder();
    // read from the urlconnection via the bufferedreader
    while ((line = bufferedReader.readLine()) != null) {
        content.append(line + "\n");
    }
    bufferedReader.close();

    String s = content.toString();
    String tsString = "timeStamp=";
    int indexOfTimestamp = s.indexOf(tsString);
    int indexOfLastQuote = s.indexOf("\"", indexOfTimestamp + 2 + tsString.length());
    String contentString = s.substring(0, indexOfTimestamp - 2);
    contentString += s.substring(indexOfLastQuote);

    contentString = removeDates(contentString, "<atlas:recordedAt>", "</atlas:recordedAt>");

    Configuration configuration = new org.geotools.gml3.GMLConfiguration();
    configuration.getContext().registerComponentInstance(new GeometryFactory(new PrecisionModel(), 28992));

    Parser parser = new Parser(configuration);
    parser.setValidating(false);
    parser.setStrict(false);
    parser.setFailOnValidationError(false);

    ByteArrayInputStream bais = new ByteArrayInputStream(contentString.getBytes());
    Object obj = parser.parse(bais);

    SimpleFeatureCollection fc = (SimpleFeatureCollection) obj;

    SimpleFeatureIterator it = fc.features();
    SimpleFeature sf = null;
    List<SimpleFeature> fs = new ArrayList<SimpleFeature>();
    while (it.hasNext()) {
        sf = it.next();
        sf.getUserData().put(DISTANCE_KEY, point.distance((Geometry) sf.getDefaultGeometry()));
        fs.add(sf);
    }
    Collections.sort(fs, new Comparator<SimpleFeature>() {
        @Override
        public int compare(SimpleFeature o1, SimpleFeature o2) {
            Double d1 = (Double) o1.getUserData().get(DISTANCE_KEY);
            Double d2 = (Double) o2.getUserData().get(DISTANCE_KEY);
            return d1.compareTo(d2);
        }
    });
    SimpleFeature f = fs.get(0);
    imageId = (String) f.getAttribute("imageId");
    sign();
    return new ForwardResolution("/WEB-INF/jsp/app/globespotter.jsp");
}

From source file:com.hbc.api.fund.biz.service.MISFundWithdrawService.java

/**
 * /*w w w  . j av a2 s .  c om*/
 * @param bossTransferGuideInfos
 * @param totalAmount
 * @param targetBossGuideId
 * @param targetBossGuideNo
 * @param targetAccountNo
 * @param targetBankNo
 * @param optId
 * @param optName
 */
private void validBossTransferGuideInfo(List<BossTransferGuideInfo> bossTransferGuideInfos, Double totalAmount,
        String targetBossGuideId, String targetBossGuideNo, String targetAccountNo, String targetBankNo,
        String optId, String optName) {
    if (bossTransferGuideInfos == null || bossTransferGuideInfos.size() <= 0 || totalAmount.compareTo(0.0d) <= 0
            || StringUtils.isBlank(targetBossGuideId) || StringUtils.isBlank(targetAccountNo)
            || StringUtils.isBlank(targetBossGuideNo) || StringUtils.isBlank(optId)
            || StringUtils.isBlank(optName) || StringUtils.isBlank(targetBankNo)) {
        throw new FundException(FundReturnCodeEnum.ERR_INSERT, "?");
    }

    Double allTotalAmountInlist = 0.0d;
    Iterator<BossTransferGuideInfo> bossTransferGuideInfosIterator = bossTransferGuideInfos.iterator();
    while (bossTransferGuideInfosIterator.hasNext()) {
        BossTransferGuideInfo bossTransferGuideInfo = (BossTransferGuideInfo) bossTransferGuideInfosIterator
                .next();
        allTotalAmountInlist = DoubleUtil.addDouble(allTotalAmountInlist, bossTransferGuideInfo.getAmount());
    }

    logger.info("BOSS-??|?:{} |?:{}", allTotalAmountInlist, totalAmount);
    if (!allTotalAmountInlist.equals(totalAmount)) {
        throw new FundException(FundReturnCodeEnum.ERR_INSERT, "???");
    }
}

From source file:org.mifos.accounts.penalties.business.PenaltyBO.java

private void validateMinAndMax(final Double min, final Double max) throws PenaltyException {
    if (min == null) {
        throw new PenaltyException(PenaltyConstants.INVALID_PENALTY_MINIMUM);
    }/*w w w  .  j a  v a 2 s  .c  o  m*/

    if (max == null) {
        throw new PenaltyException(PenaltyConstants.INVALID_PENALTY_MAXIMUM);
    }

    if (min.compareTo(max) > 0) {
        throw new PenaltyException(PenaltyConstants.INVALID_MAX_GREATER_MIN);
    }
}

From source file:ml.shifu.shifu.core.processor.InitModelProcessor.java

private boolean isBinaryVariable(long distinctCount, String[] items) {
    if (distinctCount != 2) {
        return false;
    }//  w w  w . j a  v  a  2 s  .co m
    if (items.length > 2) {
        return false;
    }
    for (String string : items) {
        try {
            Double doubleValue = Double.valueOf(string);
            if (doubleValue.compareTo(Double.valueOf(0d)) == 0
                    || doubleValue.compareTo(Double.valueOf(1d)) == 0) {
                continue;
            } else {
                return false;
            }
        } catch (NumberFormatException e) {
            return false;
        }
    }
    return true;
}

From source file:org.kuali.kfs.module.cam.util.distribution.AssetPaymentDistributionByTotalCost.java

/**
 * Doing the re-distribution of the cost based on the previous total cost of each asset compared with the total previous cost of
 * the assets./*  w  w w.  j  a v  a  2  s .co m*/
 * 
 * @param detailSize
 * @param totalHistoricalCost
 * @param assetPaymentAssetDetail
 * @return
 */
private Double getAssetDetailPercentage(int detailSize, Double totalHistoricalCost,
        AssetPaymentAssetDetail assetPaymentAssetDetail) {
    Double previousTotalCostAmount = new Double("0");
    if (assetPaymentAssetDetail.getPreviousTotalCostAmount() != null) {
        previousTotalCostAmount = new Double(StringUtils
                .defaultIfEmpty(assetPaymentAssetDetail.getPreviousTotalCostAmount().toString(), "0"));
    }

    Double percentage = new Double(0);
    if (totalHistoricalCost.compareTo(new Double(0)) != 0)
        percentage = (previousTotalCostAmount / totalHistoricalCost);
    else
        percentage = (1 / (new Double(detailSize)));
    return percentage;
}

From source file:net.navasoft.madcoin.backend.services.rest.impl.Provider.java

/**
 * Apply policies./*from w ww .j  ava2 s  . c o  m*/
 * 
 * @return true, if successful, otherwise false
 * @since 8/09/2014, 01:45:38 AM
 */
@Override
public boolean applyPolicies() {
    if (providerPreferrence.getIdServiceCategory().getIdServiceCategory()
            .equals(requestedOrder.getWorkRequestsPK().getCategoryId())) {
        String param1 = providerPreferrence.getIdBusinessParameter().getParameterType();
        String param2 = providerPreferrence.getIdBusinessParameter2().getParameterType();
        Double minCost = 0d;
        Double maxCost = 0d;
        if (param1.equals("java.lang.Double")) {
            minCost = providerPreferrence.getIdBusinessParameter().getDoubleValue();
        }
        if (param2.equals("java.lang.Double")) {
            maxCost = providerPreferrence.getIdBusinessParameter2().getDoubleValue();
        }
        if (minCost.compareTo(requestedOrder.getMinCost().doubleValue()) <= 0
                && maxCost.compareTo(requestedOrder.getMaxCost().doubleValue()) <= 0) {
            if (inicioVentanas != null && finVentanas != null) {
                boolean applicable = (inicioVentanas.length > 0 && finVentanas.length > 0);
                for (Calendar inicio : inicioVentanas) {
                    applicable &= requestedOrder.getRealArrival().before(inicio.getTime());
                }
                for (Calendar fin : finVentanas) {
                    applicable &= requestedOrder.getRealArrival().after(fin.getTime());
                }
                applicable &= (providerContact != null);
                return applicable;
            } else {
                return true;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}