Java Code Examples for java.util.NavigableMap#size()
The following examples show how to use
java.util.NavigableMap#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractWorldUpdater.java From besu with Apache License 2.0 | 6 votes |
@Override public NavigableMap<Bytes32, AccountStorageEntry> storageEntriesFrom( final Bytes32 startKeyHash, final int limit) { final NavigableMap<Bytes32, AccountStorageEntry> entries; if (account != null) { entries = account.storageEntriesFrom(startKeyHash, limit); } else { entries = new TreeMap<>(); } updatedStorage.entrySet().stream() .map(entry -> AccountStorageEntry.forKeyAndValue(entry.getKey(), entry.getValue())) .filter(entry -> entry.getKeyHash().compareTo(startKeyHash) >= 0) .forEach(entry -> entries.put(entry.getKeyHash(), entry)); while (entries.size() > limit) { entries.remove(entries.lastKey()); } return entries; }
Example 2
Source File: ADAPInterface.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
@Nonnull public static Feature peakToFeature(@Nonnull RawDataFile file, @Nonnull Peak peak) { NavigableMap<Double, Double> chromatogram = peak.getChromatogram(); double[] retTimes = new double[chromatogram.size()]; double[] intensities = new double[chromatogram.size()]; int index = 0; for (Entry<Double, Double> e : chromatogram.entrySet()) { retTimes[index] = e.getKey(); intensities[index] = e.getValue(); ++index; } BetterPeak betterPeak = new BetterPeak( peak.getInfo().peakID, new Chromatogram(retTimes, intensities), peak.getInfo()); return peakToFeature(file, betterPeak); }
Example 3
Source File: ConcurrentSkipListMapTest.java From j2objc with Apache License 2.0 | 6 votes |
void mutateMap(NavigableMap<Integer, Integer> map, int min, int max) { int size = map.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(map, min - 5 + rnd.nextInt(rangeSize + 10)); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (map.size() < size) { int key = min + rnd.nextInt(rangeSize); assertTrue(key >= min && key <= max); put(map, key); } }
Example 4
Source File: VocabularySearchExprFactory.java From biomedicus with Apache License 2.0 | 6 votes |
/** * Parses the expression, performing substitutions. * * @param expression the expression with substitution keywords * @return search expression with the indices values inserted */ public SearchExpr parseExpression(String expression) { NavigableMap<Span, String> replacements = new TreeMap<>(); findReplacements(replacements, WORD_REPLACE.matcher(expression), wordsIndex); findReplacements(replacements, TERM_REPLACE.matcher(expression), termsIndex); findReplacements(replacements, NORM_REPLACE.matcher(expression), normsIndex); if (replacements.size() > 0) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(expression); for (Entry<Span, String> entry : replacements.descendingMap().entrySet()) { stringBuilder.replace(entry.getKey().getStartIndex(), entry.getKey().getEndIndex(), entry.getValue()); } expression = stringBuilder.toString(); } return searchExprFactory.parse(expression); }
Example 5
Source File: Frequency.java From hipparchus with Apache License 2.0 | 6 votes |
/** * Returns the cumulative frequency of values less than or equal to v. * * @param v the value to lookup. * @return the proportion of values equal to v */ public long getCumFreq(T v) { if (getSumFreq() == 0) { return 0; } NavigableMap<T, Long> headMap = freqTable.headMap(v, true); if (headMap.isEmpty()) { // v is less than first value return 0; } else if (headMap.size() == freqTable.size()) { // v is greater than or equal to last value return getSumFreq(); } return headMap.values() .stream() .mapToLong(Long::longValue) .sum(); }
Example 6
Source File: FileLogReader.java From rcrs-server with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void removeStaleKeyFrames() { Logger.trace("Removing stale key frames"); int size = keyFrames.size(); if (size < KEY_FRAME_BUFFER_MAX_SIZE) { Logger.trace("Key frame buffer is not full: " + size + (size == 1 ? " entry" : " entries")); return; } // Try to balance the number of key frames. int window = maxTime / KEY_FRAME_BUFFER_MAX_SIZE; for (int i = 0; i < maxTime; i += window) { NavigableMap<Integer, WorldModel<? extends Entity>> next = keyFrames.subMap(i, false, i + window, true); Logger.trace("Window " + i + " -> " + (i + window) + " has " + next.size() + " entries"); if (next.size() > 1) { // Remove all but the last entry in this window Map.Entry<Integer, WorldModel<? extends Entity>> last = next.lastEntry(); next.clear(); next.put(last.getKey(), last.getValue()); Logger.trace("Retained entry " + last); } } Logger.trace("New key frame set: " + keyFrames); }
Example 7
Source File: TreeMapTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
void mutateMap(NavigableMap<Integer, Integer> map, int min, int max) { int size = map.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(map, min - 5 + rnd.nextInt(rangeSize + 10)); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (map.size() < size) { int key = min + rnd.nextInt(rangeSize); assertTrue(key >= min && key <= max); put(map, key); } }
Example 8
Source File: ConcurrentSkipListMapTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
void mutateMap(NavigableMap<Integer, Integer> map, int min, int max) { int size = map.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(map, min - 5 + rnd.nextInt(rangeSize + 10)); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (map.size() < size) { int key = min + rnd.nextInt(rangeSize); assertTrue(key >= min && key <= max); put(map, key); } }
Example 9
Source File: ImapServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public void testGetFlags() throws Exception { NavigableMap<Long, FileInfo> fis = imapService.getFolderStatus(authenticationService.getCurrentUserName(), testImapFolderNodeRef, ImapViewMode.ARCHIVE).search; if (fis != null && fis.size() > 0) { FileInfo messageFileInfo = fis.firstEntry().getValue(); reauthenticate(USER_NAME, USER_PASSWORD); permissionService.setPermission(testImapFolderNodeRef, anotherUserName, PermissionService.WRITE, true); imapService.setFlags(messageFileInfo, flags, true); reauthenticate(anotherUserName, anotherUserName); Flags fl = imapService.getFlags(messageFileInfo); assertTrue(fl.contains(flags)); } }
Example 10
Source File: ImapServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public void testSetFlag() throws Exception { NavigableMap<Long, FileInfo> fis = imapService.getFolderStatus(authenticationService.getCurrentUserName(), testImapFolderNodeRef, ImapViewMode.ARCHIVE).search; if (fis != null && fis.size() > 0) { FileInfo messageFileInfo = fis.firstEntry().getValue(); reauthenticate(USER_NAME, USER_PASSWORD); permissionService.setPermission(testImapFolderNodeRef, anotherUserName, PermissionService.WRITE, true); reauthenticate(anotherUserName, anotherUserName); imapService.setFlag(messageFileInfo, Flags.Flag.RECENT, true); Serializable prop = nodeService.getProperty(messageFileInfo.getNodeRef(), ImapModel.PROP_FLAG_RECENT); assertNotNull("Can't set RECENT flag", prop); } }
Example 11
Source File: ADAPInterface.java From mzmine3 with GNU General Public License v2.0 | 6 votes |
@Nonnull public static Feature peakToFeature(@Nonnull RawDataFile file, @Nonnull Peak peak) { NavigableMap<Double, Double> chromatogram = peak.getChromatogram(); double[] retTimes = new double[chromatogram.size()]; double[] intensities = new double[chromatogram.size()]; int index = 0; for (Entry<Double, Double> e : chromatogram.entrySet()) { retTimes[index] = e.getKey(); intensities[index] = e.getValue(); ++index; } BetterPeak betterPeak = new BetterPeak(peak.getInfo().peakID, new Chromatogram(retTimes, intensities), peak.getInfo()); return peakToFeature(file, betterPeak); }
Example 12
Source File: AbstractPlacemarkDataController.java From collect-earth with MIT License | 6 votes |
/** * Sort parameters based on schema order (BFS) * @param parameters Parameters to be sorted * @return The parameters sorted alphabetically */ public Map<String, String> sortParameters(Map<String, String> parameters) { NavigableMap<String, String> navigableParameters = new TreeMap<String, String>(parameters); //extract parameter names in order BalloonInputFieldsUtils collectParametersHandler = new BalloonInputFieldsUtils(); Map<String, String> sortedParameterNameByNodePath = collectParametersHandler.getHtmlParameterNameByNodePath(earthSurveyService.getRootEntityDefinition()); List<String> sortedParameterNames = new ArrayList<String>(sortedParameterNameByNodePath.values()); //create a new map and put the parameters in order there Map<String, String> result = new LinkedHashMap<String, String>(navigableParameters.size()); for (String parameterName : sortedParameterNames) { //get all the entries with key starting with parameterName SortedMap<String,String> subMap = new TreeMap<String, String>( navigableParameters.subMap(parameterName, parameterName + Character.MAX_VALUE) ); Set<Entry<String,String>> entrySet = subMap.entrySet(); for (Entry<String, String> entry : entrySet) { result.put(entry.getKey(), entry.getValue()); navigableParameters.remove(entry.getKey()); } } //add remaining parameters (if any) result.putAll(navigableParameters); return result; }
Example 13
Source File: IndexSegmentTest.java From ambry with Apache License 2.0 | 6 votes |
/** * Gets some IDs for ttl update. Picks the first half of ids from {@code referenceIndex} and also randomly generates * {@code outOfSegmentIdCount} ids. * @param referenceIndex the index entries to pick for ttl update from. * @param outOfSegmentIdCount the number of ids to be generated that are not in {@code referenceIndex}. * @return a {@link Set} of IDs to create ttl update entries for. */ private Set<MockId> getIdsToTtlUpdate(NavigableMap<MockId, NavigableSet<IndexValue>> referenceIndex, int outOfSegmentIdCount) { Set<MockId> idsToTtlUpdate = new HashSet<>(); // return the first half of ids in the map int needed = referenceIndex.size() / 2; int current = 0; for (MockId id : referenceIndex.keySet()) { if (current >= needed) { break; } idsToTtlUpdate.add(id); current++; } // generate some ids for ttl update idsToTtlUpdate.addAll(generateIds(referenceIndex, outOfSegmentIdCount)); return idsToTtlUpdate; }
Example 14
Source File: ConcurrentSkipListMapTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void mutateSubMap(NavigableMap<Integer, Integer> map, int min, int max) { int size = map.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(map, min - 5 + rnd.nextInt(rangeSize + 10)); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (map.size() < size) { int key = min - 5 + rnd.nextInt(rangeSize + 10); if (key >= min && key <= max) { put(map, key); } else { try { map.put(key, 2 * key); shouldThrow(); } catch (IllegalArgumentException success) {} } } }
Example 15
Source File: ImapServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void testSetFlags() throws Exception { NavigableMap<Long, FileInfo> fis = imapService.getFolderStatus(authenticationService.getCurrentUserName(), testImapFolderNodeRef, ImapViewMode.ARCHIVE).search; if (fis != null && fis.size() > 0) { FileInfo messageFileInfo = fis.firstEntry().getValue(); try { setFlags(messageFileInfo); fail("Can't set flags"); } catch (Exception e) { if (e instanceof AccessDeniedException) { // expected } else { throw e; } } reauthenticate(USER_NAME, USER_PASSWORD); permissionService.setPermission(testImapFolderNodeRef, anotherUserName, PermissionService.WRITE, true); reauthenticate(anotherUserName, anotherUserName); setFlags(messageFileInfo); } }
Example 16
Source File: TreeMapTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void mutateSubMap(NavigableMap<Integer, Integer> map, int min, int max) { int size = map.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(map, min - 5 + rnd.nextInt(rangeSize + 10)); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (map.size() < size) { int key = min - 5 + rnd.nextInt(rangeSize + 10); if (key >= min && key <= max) { put(map, key); } else { try { map.put(key, 2 * key); shouldThrow(); } catch (IllegalArgumentException success) {} } } }
Example 17
Source File: UserSettingsClient.java From metron with Apache License 2.0 | 5 votes |
public Map<String, String> getAllUserSettings(Result result) { if (result == null) { return new HashMap<>(); } NavigableMap<byte[], byte[]> columns = result.getFamilyMap(cf); if(columns == null || columns.size() == 0) { return new HashMap<>(); } Map<String, String> userSettingsMap = new HashMap<>(); for(Map.Entry<byte[], byte[]> column: columns.entrySet()) { userSettingsMap.put(new String(column.getKey(), StandardCharsets.UTF_8), new String(column.getValue(), StandardCharsets.UTF_8)); } return userSettingsMap; }
Example 18
Source File: HBaseDao.java From metron with Apache License 2.0 | 5 votes |
private Document getDocumentFromResult(Result result) throws IOException { NavigableMap<byte[], byte[]> columns = result.getFamilyMap( cf); if(columns == null || columns.size() == 0) { return null; } Map.Entry<byte[], byte[]> entry= columns.lastEntry(); Long ts = Bytes.toLong(entry.getKey()); if(entry.getValue()!= null) { Map<String, Object> json = JSONUtils.INSTANCE.load(new String(entry.getValue(), StandardCharsets.UTF_8), JSONUtils.MAP_SUPPLIER); // Make sure comments are in the proper format @SuppressWarnings("unchecked") List<Map<String, Object>> commentsMap = (List<Map<String, Object>>) json.get(COMMENTS_FIELD); try { if (commentsMap != null) { List<AlertComment> comments = new ArrayList<>(); for (Map<String, Object> commentMap : commentsMap) { comments.add(new AlertComment(commentMap)); } if (comments.size() > 0) { json.put(COMMENTS_FIELD, comments.stream().map(AlertComment::asMap).collect(Collectors.toList())); } } Key k = Key.fromBytes(result.getRow()); return new Document(json, k.getGuid(), k.getSensorType(), ts); } catch (IOException e) { throw new RuntimeException("Unable to convert row key to a document", e); } } else { return null; } }
Example 19
Source File: TreeMapTest.java From j2objc with Apache License 2.0 | 5 votes |
void mutateSubMap(NavigableMap<Integer, Integer> map, int min, int max) { int size = map.size(); int rangeSize = max - min + 1; // Remove a bunch of entries directly for (int i = 0, n = rangeSize / 2; i < n; i++) { remove(map, min - 5 + rnd.nextInt(rangeSize + 10)); } // Remove a bunch of entries with iterator for (Iterator<Integer> it = map.keySet().iterator(); it.hasNext(); ) { if (rnd.nextBoolean()) { bs.clear(it.next()); it.remove(); } } // Add entries till we're back to original size while (map.size() < size) { int key = min - 5 + rnd.nextInt(rangeSize + 10); if (key >= min && key <= max) { put(map, key); } else { try { map.put(key, 2 * key); shouldThrow(); } catch (IllegalArgumentException success) {} } } }
Example 20
Source File: AdjacencyMap.java From bitsy with Apache License 2.0 | 4 votes |
private boolean removeMatchingKeys(NavigableMap<Endpoint, Integer> map, Endpoint endpoint, Map<UUID, TreeMap<Endpoint, Integer>> otherMap, Direction dir) { if (map == null) { return false; } // Mark this endpoint as a marker, because it is used to do a tailMap traversal to remove matching edges endpoint.setMarker(); // Find the first key Endpoint floorKey = map.floorKey(endpoint); Map<Endpoint, Integer> view; if (floorKey == null) { // This means that the element being searched is the minimum view = map; } else { view = map.tailMap(floorKey); } Iterator<Map.Entry<Endpoint, Integer>> entryIter = view.entrySet().iterator(); boolean isFirst = true; while (entryIter.hasNext()) { Map.Entry<Endpoint, Integer> entry = entryIter.next(); Endpoint key = entry.getKey(); if (endpoint.isMatch(key)) { // Remove it from this index entryIter.remove(); // and from the underlying edge map if necessary if (dir != null) { // Direction is null if this is a recursive all // Remove the edge if the map is provided for this purpose UUID edgeId = key.getEdgeId(); IEdge edge = edgeRemover.removeEdge(edgeId); assert (edge != null); // Remove the other endpoint of this edge. NOTE: Self loops are not allowed. Endpoint otherEndpoint; UUID otherVertexId; if (dir == Direction.OUT) { otherVertexId = edge.getInVertexId(); otherEndpoint = new Endpoint(key.getEdgeLabel(), key.getEdgeId()); } else { otherVertexId = edge.getOutVertexId(); otherEndpoint = new Endpoint(key.getEdgeLabel(), key.getEdgeId()); } if (removeMatchingKeys(otherMap.get(otherVertexId), otherEndpoint, null, null)) { otherMap.remove(otherVertexId); } } } else { // Done with removes -- the tree map is sorted if (isFirst) { // continue } else { break; } } isFirst = false; } return (map.size() == 0); }