Example usage for java.util OptionalDouble getAsDouble

List of usage examples for java.util OptionalDouble getAsDouble

Introduction

In this page you can find the example usage for java.util OptionalDouble getAsDouble.

Prototype

public double getAsDouble() 

Source Link

Document

If a value is present, returns the value, otherwise throws NoSuchElementException .

Usage

From source file:ch.zweivelo.renderer.simple.shapes.Sphere.java

@Override
public Optional<Double> calculateIntersectionDistance(final Ray ray) {
    Vector3D dir = ray.getDirection();
    Vector3D tmp = ray.getOrigin().subtract(center);

    OptionalDouble min = Solver.QUADRATIC
            .solve(tmp.dotProduct(tmp) - radius * radius, 2 * dir.dotProduct(tmp), dir.dotProduct(dir)).min();

    if (min.isPresent()) {
        return Optional.of(min.getAsDouble());
    }// ww  w  .  j  av a  2s. com

    return Optional.empty();
}

From source file:com.aba.market.fetch.impl.CrestMarketPriceFetcher.java

@Override
@Cacheable("adjusted-price")
public Double getAdjustedPrice(long typeId) {
    Double result = 0d;//from   w  w  w . j  a v a 2s . c o  m

    List<CrestMarketPrice> prices = this.getAllMarketPrices();

    OptionalDouble possibleResult = prices.stream().filter(cmp -> cmp.getType().getId() == typeId)
            .mapToDouble(cmp -> cmp.getAdjustedPrice()).findFirst();

    if (possibleResult.isPresent()) {
        result = possibleResult.getAsDouble();
    }

    return result;
}

From source file:com.aba.market.fetch.impl.CrestMarketOrderFetcher.java

@Override
@Cacheable("lowest-sell-price")
public Double getLowestSellPrice(long regionId, long systemId, long itemId) {
    Double result = null;// www  . ja  v  a  2  s  .  c o  m

    //Used in the below lambda, needs to be final
    final Long hubIdToFind = getHubStationIdToUse(systemId);

    List<CrestMarketOrder> sellOrders = getMarketSellOrders(regionId, itemId);

    OptionalDouble price = sellOrders.stream().filter(order -> order.getLocationId() == hubIdToFind)
            .mapToDouble(order -> order.getPrice()).findFirst();

    if (price.isPresent()) {
        result = price.getAsDouble();
    }

    return result;
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.collective_score.scorers.ShapeDistanceCollectiveAnswerScorer.java

@SuppressWarnings("unchecked")
@Override// w w w. ja  va 2s .  com
public void prepare(JCas jcas) {
    answers = TypeUtil.getRankedAnswers(jcas);
    distances = HashBasedTable.create();
    bdistances = HashBasedTable.create();
    ImmutableSet<Answer> answerSet = ImmutableSet.copyOf(answers);
    SetMultimap<Answer, String> answer2shapes = HashMultimap.create();
    answers.forEach(answer -> TypeUtil.getCandidateAnswerVariantNames(answer).stream()
            .map(ShapeDistanceCollectiveAnswerScorer::shape)
            .forEach(shape -> answer2shapes.put(answer, shape)));
    for (List<Answer> pair : Sets.cartesianProduct(answerSet, answerSet)) {
        Answer answer1 = pair.get(0);
        Answer answer2 = pair.get(1);
        if (answer1.equals(answer2)) {
            distances.put(answer1, answer2, 1.0);
            bdistances.put(answer1, answer2, 1.0);
        } else {
            OptionalDouble distance = Sets
                    .cartesianProduct(answer2shapes.get(answer1), answer2shapes.get(answer2)).stream()
                    .mapToDouble(shapepair -> getDistance(shapepair.get(0), shapepair.get(1))).min();
            if (distance.isPresent()) {
                distances.put(answer1, answer2, 1.0 - distance.getAsDouble());
                bdistances.put(answer1, answer2, distance.getAsDouble() == 0.0 ? 1.0 : 0.0);
            }
        }
    }
}

From source file:com.searchcode.app.util.SearchcodeLib.java

/**
 * Determine if a List<String> which is used to represent a code file contains a code file that is
 * suspected to be minified. This is for the purposes of excluding it from the index.
 *//*from  w w  w.j  ava 2 s .com*/
public boolean isMinified(List<String> codeLines, String fileName) {

    String lowerFileName = fileName.toLowerCase();

    for (String extension : this.WHITELIST) {
        if (lowerFileName.endsWith("." + extension)) {
            return false;
        }
    }

    OptionalDouble average = codeLines.stream().map(x -> x.trim().replace(" ", "")).mapToInt(String::length)
            .average();
    if (average.isPresent() && average.getAsDouble() > this.MINIFIEDLENGTH) {
        return true;
    }

    return false;
}