List of usage examples for java.util OptionalDouble isPresent
boolean isPresent
To view the source code for java.util OptionalDouble isPresent.
Click Source Link
From source file:com.aba.market.fetch.impl.CrestMarketPriceFetcher.java
@Override @Cacheable("adjusted-price") public Double getAdjustedPrice(long typeId) { Double result = 0d;/*from w ww . j a va 2 s . 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;/*from ww w .ja v a2 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/*from ww w . j ava2s . c o m*/ 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 ww. ja v a 2s.c om*/ 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; }