本文整理汇总了Java中java.util.NavigableMap.floorEntry方法的典型用法代码示例。如果您正苦于以下问题:Java NavigableMap.floorEntry方法的具体用法?Java NavigableMap.floorEntry怎么用?Java NavigableMap.floorEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.NavigableMap
的用法示例。
在下文中一共展示了NavigableMap.floorEntry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFloorEntry
import java.util.NavigableMap; //导入方法依赖的package包/类
/**
* floorEntry returns preceding entry.
*/
public void testFloorEntry() {
NavigableMap map = map5();
Map.Entry e1 = map.floorEntry(three);
assertEquals(three, e1.getKey());
Map.Entry e2 = map.floorEntry(six);
assertEquals(five, e2.getKey());
Map.Entry e3 = map.floorEntry(one);
assertEquals(one, e3.getKey());
Map.Entry e4 = map.floorEntry(zero);
assertNull(e4);
}
示例2: testDescendingFloorEntry
import java.util.NavigableMap; //导入方法依赖的package包/类
/**
* floorEntry returns preceding entry.
*/
public void testDescendingFloorEntry() {
NavigableMap map = dmap5();
Map.Entry e1 = map.floorEntry(m3);
assertEquals(m3, e1.getKey());
Map.Entry e2 = map.floorEntry(m6);
assertEquals(m5, e2.getKey());
Map.Entry e3 = map.floorEntry(m1);
assertEquals(m1, e3.getKey());
Map.Entry e4 = map.floorEntry(zero);
assertNull(e4);
}
示例3: addInterval
import java.util.NavigableMap; //导入方法依赖的package包/类
/**
* Add a resource for the specified interval
*
* @param reservationInterval the interval for which the resource is to be
* added
* @param capacity the resource to be added
* @return true if addition is successful, false otherwise
*/
public boolean addInterval(ReservationInterval reservationInterval,
ReservationRequest capacity) {
Resource totCap =
Resources.multiply(capacity.getCapability(),
(float) capacity.getNumContainers());
if (totCap.equals(ZERO_RESOURCE)) {
return true;
}
writeLock.lock();
try {
long startKey = reservationInterval.getStartTime();
long endKey = reservationInterval.getEndTime();
NavigableMap<Long, Resource> ticks =
cumulativeCapacity.headMap(endKey, false);
if (ticks != null && !ticks.isEmpty()) {
Resource updatedCapacity = Resource.newInstance(0, 0, 0);
Entry<Long, Resource> lowEntry = ticks.floorEntry(startKey);
if (lowEntry == null) {
// This is the earliest starting interval
cumulativeCapacity.put(startKey, totCap);
} else {
updatedCapacity = Resources.add(lowEntry.getValue(), totCap);
// Add a new tick only if the updated value is different
// from the previous tick
if ((startKey == lowEntry.getKey())
&& (isSameAsPrevious(lowEntry.getKey(), updatedCapacity))) {
cumulativeCapacity.remove(lowEntry.getKey());
} else {
cumulativeCapacity.put(startKey, updatedCapacity);
}
}
// Increase all the capacities of overlapping intervals
Set<Entry<Long, Resource>> overlapSet =
ticks.tailMap(startKey, false).entrySet();
for (Entry<Long, Resource> entry : overlapSet) {
updatedCapacity = Resources.add(entry.getValue(), totCap);
entry.setValue(updatedCapacity);
}
} else {
// This is the first interval to be added
cumulativeCapacity.put(startKey, totCap);
}
Resource nextTick = cumulativeCapacity.get(endKey);
if (nextTick != null) {
// If there is overlap, remove the duplicate entry
if (isSameAsPrevious(endKey, nextTick)) {
cumulativeCapacity.remove(endKey);
}
} else {
// Decrease capacity as this is end of the interval
cumulativeCapacity.put(endKey, Resources.subtract(cumulativeCapacity
.floorEntry(endKey).getValue(), totCap));
}
return true;
} finally {
writeLock.unlock();
}
}