List of usage examples for java.util SortedMap firstKey
K firstKey();
From source file:FocusTraversalExample.java
public Component getComponentAfter(Container focusCycleRoot, Component aComponent) { if (!(aComponent instanceof JButton)) { return null; }/* w ww.j a v a 2s . c o m*/ SortedMap buttons = getSortedButtons(focusCycleRoot); // Find all buttons after the current one. String nextName = ((JButton) aComponent).getText() + "\0"; SortedMap nextButtons = buttons.tailMap(nextName); if (nextButtons.isEmpty()) { // Wrapped back to beginning if (!buttons.isEmpty()) { return (Component) buttons.get(buttons.firstKey()); } return null; // Degenerate case of no buttons. } return (Component) nextButtons.get(nextButtons.firstKey()); }
From source file:com.jostrobin.battleships.view.frames.GameFrame.java
public void initializeFields(int length, int width, SortedMap<Long, String> participants) { this.width = width; this.length = length; this.participants = participants; // first entry is the current player playerId = participants.firstKey(); // remove it from the map Map<Long, String> opponents = new HashMap<Long, String>(participants); opponents.remove(playerId);/*from w ww. j av a 2s .co m*/ gamePanel.initUi(length, width, opponents); initializeFieldSize(length, width); }
From source file:org.apache.hadoop.hbase.security.visibility.VisibilityNewVersionBehaivorTracker.java
@Override public DeleteResult isDeleted(Cell cell) { try {/*from ww w . j a v a 2 s . co m*/ long duplicateMvcc = prepare(cell); for (Map.Entry<Long, DeleteVersionsNode> e : delColMap.tailMap(cell.getSequenceId()).entrySet()) { VisibilityDeleteVersionsNode node = (VisibilityDeleteVersionsNode) e.getValue(); long deleteMvcc = Long.MAX_VALUE; SortedMap<Long, TagInfo> deleteVersionMvccs = node.deletesMap.get(cell.getTimestamp()); if (deleteVersionMvccs != null) { SortedMap<Long, TagInfo> tail = deleteVersionMvccs.tailMap(cell.getSequenceId()); for (Map.Entry<Long, TagInfo> entry : tail.entrySet()) { if (tagMatched(cell, entry.getValue())) { deleteMvcc = tail.firstKey(); break; } } } SortedMap<Long, SortedSet<Long>> subMap = node.mvccCountingMap.subMap(cell.getSequenceId(), true, Math.min(duplicateMvcc, deleteMvcc), true); for (Map.Entry<Long, SortedSet<Long>> seg : subMap.entrySet()) { if (seg.getValue().size() >= maxVersions) { return DeleteResult.VERSION_MASKED; } seg.getValue().add(cell.getSequenceId()); } if (deleteMvcc < Long.MAX_VALUE) { return DeleteResult.VERSION_DELETED; } if (cell.getTimestamp() <= node.ts && tagMatched(cell, node.tagInfo)) { return DeleteResult.COLUMN_DELETED; } } if (duplicateMvcc < Long.MAX_VALUE) { return DeleteResult.VERSION_MASKED; } } catch (IOException e) { LOG.error("Error in isDeleted() check! Will treat cell as not deleted", e); } return DeleteResult.NOT_DELETED; }
From source file:com.cloudera.oryx.kmeans.computation.local.SamplingRun.java
@Override public Collection<RealVector> call() throws Exception { SortedMap<Double, RealVector> reservoir = Maps.newTreeMap(); for (RealVector v : vecs) { Distance d = index.getDistance(v, foldId, true); if (d.getSquaredDistance() > 0.0) { double score = Math.log(random.nextDouble()) / d.getSquaredDistance(); if (reservoir.size() < sampleCount) { reservoir.put(score, v); } else if (score > reservoir.firstKey()) { reservoir.remove(reservoir.firstKey()); reservoir.put(score, v); }/*from w w w.ja v a2 s . co m*/ } } return reservoir.values(); }
From source file:org.bibsonomy.webapp.filters.ContentNegotiationFilter.java
/** * Supports content negotiation using the HTTP accept header. * /*from w w w.j av a 2 s . c o m*/ * Extracts the preferred response format from the accept header and returns * the corresponding URL path for the webapp. Only the format with the * highest priority is regarded. Thus, this method is much stricter than * {@link HeaderUtils#getResponseFormat(String, int)}. * <br/> * If no matching URL path could be found, <code>null</code> is returned. * * * @param acceptHeader - the "Accept" header of the HTTP request. * @return The */ private String getResponseFormat(final String acceptHeader) { if (!present(acceptHeader)) return null; /* * extract ordered list of preferred types */ final SortedMap<Double, Vector<String>> preferredTypes = org.bibsonomy.rest.utils.HeaderUtils .getPreferredTypes(acceptHeader); /* * extract highest ranked formats */ final Vector<String> firstFormats = preferredTypes.get(preferredTypes.firstKey()); /* * return best match */ return FORMAT_MAPPING.get(firstFormats.firstElement()); }
From source file:com.espertech.esper.epl.join.table.PropertySortedEventTable.java
private Set<EventBean> normalize(SortedMap<Object, Set<EventBean>> submap) { if (submap.size() == 0) { return null; }/* w w w. ja va 2 s . co m*/ if (submap.size() == 1) { return submap.get(submap.firstKey()); } Set<EventBean> result = new LinkedHashSet<EventBean>(); for (Map.Entry<Object, Set<EventBean>> entry : submap.entrySet()) { result.addAll(entry.getValue()); } return result; }
From source file:com.espertech.esper.epl.join.table.PropertySortedEventTable.java
private Collection<EventBean> normalizeCollection(SortedMap<Object, Set<EventBean>> submap) { if (submap.size() == 0) { return null; }/*from w w w. j av a 2 s. com*/ if (submap.size() == 1) { return submap.get(submap.firstKey()); } Deque<EventBean> result = new ArrayDeque<EventBean>(); for (Map.Entry<Object, Set<EventBean>> entry : submap.entrySet()) { result.addAll(entry.getValue()); } return result; }
From source file:org.kalypso.model.hydrology.operation.evaporation.AbstractEvaporationCalculator.java
private TupleModelDataSet getDataSet(final ITimeseriesCache humidity, final Calendar ptr, final String type) { final TreeMap<Date, TupleModelDataSet[]> valueMap = humidity.getValueMap(); final Date base = ptr.getTime(); final SortedMap<Date, TupleModelDataSet[]> headMap = valueMap.headMap(base); final SortedMap<Date, TupleModelDataSet[]> tailMap = valueMap.tailMap(base); if (!headMap.isEmpty() && DateUtils.isSameDay(headMap.lastKey(), base)) return getDataSet(headMap.get(headMap.lastKey()), type); else if (!tailMap.isEmpty() && DateUtils.isSameDay(tailMap.firstKey(), base)) return getDataSet(tailMap.get(tailMap.firstKey()), type); return null;//from www . j a v a2 s. c o m }
From source file:org.opencms.workplace.editors.CmsWorkplaceEditorManager.java
/** * Returns the default editor URI for the current resource type.<p> * /*from w w w . j a v a 2 s.com*/ * @param context the request context * @param resourceType the current resource type * @param userAgent the user agent String that identifies the browser * @return a valid default editor URI for the resource type or null, if no editor matches */ protected String getDefaultEditorUri(CmsRequestContext context, String resourceType, String userAgent) { SortedMap filteredEditors = filterEditorsForResourceType(resourceType); while (filteredEditors.size() > 0) { // get the configuration with the lowest key value from the map Float key = (Float) filteredEditors.firstKey(); CmsWorkplaceEditorConfiguration conf = (CmsWorkplaceEditorConfiguration) filteredEditors.get(key); // match the found configuration with the current users browser if (conf.matchesBrowser(userAgent)) { return conf.getEditorUri(); } filteredEditors.remove(key); } if (context == null) { // this is just so that all parameters are used, signature should be identical to getEditorUri(...) return null; } // no valid default editor found return null; }
From source file:org.cloudata.core.client.TabletLocationCache.java
private void removeFromCache(TreeMap<Row.Key, TabletInfo> cache, Row.Key cacheRowKey, TabletInfo removeTablet) { if (cache.containsKey(cacheRowKey)) { cache.remove(cacheRowKey);//from www . ja v a 2 s . co m } SortedMap<Row.Key, TabletInfo> tailMap = cache.tailMap(cacheRowKey); if (tailMap.isEmpty()) { return; } Row.Key tailFirst = tailMap.firstKey(); TabletInfo tabletInfo = tailMap.get(tailFirst); if (tabletInfo.equals(removeTablet)) { cache.remove(tailFirst); } }