List of usage examples for java.util TreeMap higherEntry
public Map.Entry<K, V> higherEntry(K key)
From source file:Main.java
public static void main(String[] args) { TreeMap<Integer, String> treemap = new TreeMap<Integer, String>(); // populating tree map treemap.put(2, "two"); treemap.put(1, "one"); treemap.put(3, "three"); treemap.put(6, "six"); treemap.put(5, "from java2s.com"); // getting higher entry for key 4 System.out.println("Checking values of the map"); System.out.println("Value is: " + treemap.higherEntry(4)); }
From source file:com.evolveum.midpoint.provisioning.impl.ResourceObjectConverter.java
private List<Collection<Operation>> sortOperationsIntoWaves(Collection<Operation> operations, RefinedObjectClassDefinition objectClassDefinition) { TreeMap<Integer, Collection<Operation>> waves = new TreeMap<>(); // operations indexed by priority List<Operation> others = new ArrayList<>(); // operations executed at the end (either non-priority ones or non-attribute modifications) for (Operation operation : operations) { RefinedAttributeDefinition rad = getRefinedAttributeDefinitionIfApplicable(operation, objectClassDefinition);//from w w w . ja v a 2s. com if (rad != null && rad.getModificationPriority() != null) { putIntoWaves(waves, rad.getModificationPriority(), operation); continue; } others.add(operation); } // computing the return value List<Collection<Operation>> retval = new ArrayList<>(waves.size() + 1); Map.Entry<Integer, Collection<Operation>> entry = waves.firstEntry(); while (entry != null) { retval.add(entry.getValue()); entry = waves.higherEntry(entry.getKey()); } retval.add(others); return retval; }
From source file:org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor.java
/** * Choose a single datanode from the provided list of possible * targets, weighted by the percentage of free space remaining on the node. * //from ww w. ja va 2 s. c o m * @return The chosen datanode */ private static DatanodeDescriptor chooseRandomDatanodeByRemainingCapacity( final List<DatanodeDescriptor> targets) { // Use a weighted probability to choose the target datanode float total = 0; for (DatanodeDescriptor d : targets) { total += d.getCacheRemainingPercent(); } // Give each datanode a portion of keyspace equal to its relative weight // [0, w1) selects d1, [w1, w2) selects d2, etc. TreeMap<Integer, DatanodeDescriptor> lottery = new TreeMap<Integer, DatanodeDescriptor>(); int offset = 0; for (DatanodeDescriptor d : targets) { // Since we're using floats, be paranoid about negative values int weight = Math.max(1, (int) ((d.getCacheRemainingPercent() / total) * 1000000)); offset += weight; lottery.put(offset, d); } // Choose a number from [0, offset), which is the total amount of weight, // to select the winner DatanodeDescriptor winner = lottery.higherEntry(random.nextInt(offset)).getValue(); return winner; }