java.util.NavigableMap#size ( )源码实例Demo

下面列出了java.util.NavigableMap#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ambry   文件: IndexSegmentTest.java
/**
 * 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;
}
 
源代码2 项目: besu   文件: AbstractWorldUpdater.java
@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;
}
 
/**
 * 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;
}
 
源代码4 项目: mzmine3   文件: ADAPInterface.java
@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);
}
 
源代码5 项目: alfresco-repository   文件: ImapServiceImplTest.java
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);
    }
}
 
源代码6 项目: alfresco-repository   文件: ImapServiceImplTest.java
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));
    }
}
 
源代码7 项目: openjdk-jdk9   文件: ConcurrentSkipListMapTest.java
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);
    }
}
 
源代码8 项目: openjdk-jdk9   文件: TreeMapTest.java
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);
    }
}
 
源代码9 项目: rcrs-server   文件: FileLogReader.java
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);
}
 
源代码10 项目: hipparchus   文件: Frequency.java
/**
 * 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();
}
 
源代码11 项目: biomedicus   文件: VocabularySearchExprFactory.java
/**
 * 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);
}
 
源代码12 项目: j2objc   文件: ConcurrentSkipListMapTest.java
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);
    }
}
 
源代码13 项目: mzmine2   文件: ADAPInterface.java
@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);
}
 
源代码14 项目: metron   文件: HBaseDao.java
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;
  }
}
 
源代码15 项目: metron   文件: UserSettingsClient.java
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;
}
 
源代码16 项目: alfresco-repository   文件: ImapServiceImplTest.java
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);
    }
}
 
源代码17 项目: openjdk-jdk9   文件: ConcurrentSkipListMapTest.java
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) {}
        }
    }
}
 
源代码18 项目: openjdk-jdk9   文件: TreeMapTest.java
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) {}
        }
    }
}
 
源代码19 项目: j2objc   文件: TreeMapTest.java
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) {}
        }
    }
}
 
源代码20 项目: bitsy   文件: AdjacencyMap.java
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);
}