List of usage examples for java.util SortedMap isEmpty
boolean isEmpty();
From source file:org.jactr.core.queue.collection.PrioritizedQueue.java
/** * first key after afterPriority, or NaN * /*w w w .ja va 2 s . co m*/ * @param afterPriority * @return */ synchronized public double getFirstPriorityAfter(double afterPriority) { SortedMap<Double, Collection<T>> submap = _backingMap.subMap(_backingMap.firstKey(), afterPriority); if (!submap.isEmpty()) return submap.firstKey(); return Double.NaN; }
From source file:com.precioustech.fxtrading.tradingbot.strategies.FadeTheMoveStrategy.java
public void analysePrices() { for (Map.Entry<TradeableInstrument<T>, Cache<DateTime, MarketDataPayLoad<T>>> entry : instrumentRecentPricesCache .entrySet()) {/* w w w. jav a 2s .com*/ SortedMap<DateTime, MarketDataPayLoad<T>> sortedByDate = ImmutableSortedMap .copyOf(entry.getValue().asMap()); if (sortedByDate.isEmpty()) { continue; } Double pipJump = calculatePipJump(sortedByDate.values(), entry.getKey()); Double absPipJump = Math.abs(pipJump); if (absPipJump >= this.pipJumpCutOffCalculator.calculatePipJumpCutOff(entry.getKey())) { MarketDataPayLoad<T> lastPayLoad = sortedByDate.get(sortedByDate.lastKey()); Double pip = this.instrumentService.getPipForInstrument(entry.getKey()); double takeProfitPrice; double limitPrice; TradingSignal signal = null; if (Math.signum(pipJump) > 0) {// Short signal = TradingSignal.SHORT; limitPrice = lastPayLoad.getBidPrice() + tradingConfig.getFadeTheMoveDistanceToTrade() * pip; takeProfitPrice = limitPrice - tradingConfig.getFadeTheMovePipsDesired() * pip; } else { signal = TradingSignal.LONG; limitPrice = lastPayLoad.getAskPrice() - tradingConfig.getFadeTheMoveDistanceToTrade() * pip; takeProfitPrice = limitPrice + tradingConfig.getFadeTheMovePipsDesired() * pip; } this.orderQueue.offer(new TradingDecision<T>(entry.getKey(), signal, takeProfitPrice, 0.0, limitPrice, TradingDecision.SRCDECISION.FADE_THE_MOVE)); entry.getValue().asMap().clear();/* * clear the prices so that we do not keep * working on old decision */ } } }
From source file:com.openkappa.rst.Classifier.java
private Container findWithPrefix(int attributeIndex, String prefix) { SortedMap<String, Container> prefixMap = criteria[attributeIndex].prefixMap(prefix); if (null == prefixMap || prefixMap.isEmpty()) { return fallback(attributeIndex); }//ww w. j a v a 2s .c om return prefixMap.get(prefixMap.firstKey()); }
From source file:org.vbossica.springbox.metrics.HealthCheckController.java
@RequestMapping(value = "/metrics/healthcheck", method = RequestMethod.GET) public void process( @RequestParam(value = "pretty", required = false, defaultValue = "true") boolean prettyPrint, HttpServletResponse resp) throws IOException { SortedMap<String, HealthCheck.Result> results = registry.runHealthChecks(); resp.setContentType("application/json"); resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store"); if (results.isEmpty()) { resp.setStatus(SC_NOT_IMPLEMENTED); } else {// w w w. jav a 2 s . co m resp.setStatus(isAllHealthy(results) ? SC_OK : SC_INTERNAL_SERVER_ERROR); } OutputStream output = resp.getOutputStream(); try { (prettyPrint ? mapper.writerWithDefaultPrettyPrinter() : mapper.writer()).writeValue(output, results); } finally { output.close(); } }
From source file:org.apache.metron.stellar.common.shell.DefaultStellarAutoCompleter.java
/** * Returns a list of viable candidates for auto-completion. * @param buffer The current buffer.// w w w. j a va2 s .c o m * @param opType The type of operation needing auto-completion. * @return Viable candidates for auto-completion. */ private Iterable<String> autoComplete(String buffer, final OperationType opType) { indexLock.readLock().lock(); try { SortedMap<String, AutoCompleteType> ret = autocompleteIndex.prefixMap(buffer); if (ret.isEmpty()) { return new ArrayList<>(); } return Iterables.transform(ret.entrySet(), kv -> kv.getValue().transform(opType, kv.getKey())); } finally { indexLock.readLock().unlock(); } }
From source file:org.opennms.netmgt.rrd.model.RRDv3IT.java
/** * Test samples for multiple RRAs (2)/*from ww w. j a v a 2 s . co m*/ * * @throws Exception the exception */ @Test public void testSamplesMultipleRRAs2() throws Exception { File source = new File("src/test/resources/sample-counter-rras.xml"); RRDv3 rrd = JaxbUtils.unmarshal(RRDv3.class, source); Assert.assertNotNull(rrd); SortedMap<Long, List<Double>> samples = rrd.generateSamples(); Assert.assertFalse(samples.isEmpty()); int size = rrd.getRras().stream().mapToInt(r -> r.getRows().size()).sum(); Assert.assertEquals(size - 3 - 1, samples.size()); // There are 3 timestamps that exist in both RRAs and the last one is incomplete }
From source file:amazon.SignedRequestsHelper.java
/** * Canonicalize the query string as required by Amazon. * //from w w w . j a v a 2s .co m * @param sortedParamMap Parameter name-value pairs in lexicographical order. * @return Canonical form of query string. */ private String canonicalize(SortedMap<String, String> sortedParamMap) { if (sortedParamMap.isEmpty()) { return ""; } StringBuffer buffer = new StringBuffer(); Iterator<Map.Entry<String, String>> iter = sortedParamMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, String> kvpair = iter.next(); buffer.append(percentEncodeRfc3986(kvpair.getKey())); buffer.append("="); buffer.append(percentEncodeRfc3986(kvpair.getValue())); if (iter.hasNext()) { buffer.append("&"); } } String cannoical = buffer.toString(); return cannoical; }
From source file:model.connection.amazon.SignedRequestsHelper.java
/** * Canonicalize the query string as required by Amazon. * /*w ww . j a v a 2 s.c om*/ * @param sortedParamMap Parameter name-value pairs in lexicographical order. * @return Canonical form of query string. */ private String canonicalize(SortedMap<String, String> sortedParamMap) { if (sortedParamMap.isEmpty()) { return ""; } StringBuffer buffer = new StringBuffer(); Iterator<Map.Entry<String, String>> iter = sortedParamMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, String> kvpair = iter.next(); buffer.append(percentEncodeRfc3986(kvpair.getKey())); buffer.append("="); buffer.append(percentEncodeRfc3986(kvpair.getValue())); if (iter.hasNext()) { buffer.append("&"); } } String cannonical = buffer.toString(); return cannonical; }
From source file:com.espertech.esper.schedule.SchedulingServiceImpl.java
public synchronized final void evaluate(Collection<ScheduleHandle> handles) { // Get the values on or before the current time - to get those that are exactly on the // current time we just add one to the current time for getting the head map SortedMap<Long, SortedMap<ScheduleSlot, ScheduleHandle>> headMap = timeHandleMap.headMap(currentTime + 1); if (headMap.isEmpty()) { return;//from w w w . j av a2s . c o m } // First determine all triggers to shoot List<Long> removeKeys = new ArrayList<Long>(); for (Map.Entry<Long, SortedMap<ScheduleSlot, ScheduleHandle>> entry : headMap.entrySet()) { Long key = entry.getKey(); SortedMap<ScheduleSlot, ScheduleHandle> value = entry.getValue(); removeKeys.add(key); for (ScheduleHandle handle : value.values()) { handles.add(handle); } } // Next remove all handles for (Map.Entry<Long, SortedMap<ScheduleSlot, ScheduleHandle>> entry : headMap.entrySet()) { for (ScheduleHandle handle : entry.getValue().values()) { handleSetMap.remove(handle); } } // Remove all triggered msec values for (Long key : removeKeys) { timeHandleMap.remove(key); } }
From source file:gridool.routing.strategy.ConsistentHash.java
public GridNode get(@Nonnull byte[] key) { if (circle.isEmpty()) { return null; }//from ww w . j a va 2s .c o m Long hash = hashFunction.hash(key); GridNode node = circle.get(hash); if (node != null) { return node; } SortedMap<Long, GridNode> tailMap = circle.tailMap(hash); hash = tailMap.isEmpty() ? circle.firstKey() : tailMap.firstKey(); return circle.get(hash); }