@Nullable private BuildingLocation getTargetFromMapBasedOnTime(TreeMap<Long, BuildingLocation> hourlyMap, long time) { long Ttime = hourlyMap.lowerKey(time) == null ? time : hourlyMap.lowerKey(time); if (hourlyMap.containsKey(Ttime)) { BuildingLocation location = hourlyMap.get(Ttime); if (location != null) return location; } return null; } }
public Long getPositionBefore(Long key) { if(timeByPosition.isEmpty()) { return null; } if(key==null) { return timeByPosition.lastKey(); } return timeByPosition.lowerKey(key); }
public static void main(String[] args) throws Exception { int arrayOne[] = {1, 50, 100, 50, 100, 22, 23, 26}; int arrayTwo[] = {1, 45, 22, 23, 52, 90, 100, 99}; TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>(); for (int i = 0; i < arrayTwo.length; i++) if (!map.containsKey(arrayTwo[i])) // if you want it to choose the first map.put(arrayTwo[i], i); int arrayThree[] = new int[arrayOne.length]; for (int i = 0; i < arrayThree.length; i++) { int v = arrayOne[i]; Integer h = map.higherKey(v - 1); Integer l = map.lowerKey(v); arrayThree[i] = map.get(l !=null && (h ==null || v - l < h - v) ? l : h); } System.out.println(Arrays.toString(arrayThree)); }
private BuildingLocation getTarget(World world, EntityLiving entity, Season season, Weekday weekday, long time) { if (default_ == null) return null; //Holidays take priority over anything else Festival festival = HFApi.calendar.getFestival(world, new BlockPos(entity)); if (!festival.equals(Festival.NONE) && holidayMap.containsKey(festival)) { BuildingLocation location = getTargetFromMapBasedOnTime(holidayMap.get(festival), time); if (location != null) return location; } //Now we stick to normal schedules Season seasonal = seasonalMap.lowerKey(season) == null ? season: seasonalMap.lowerKey(season); if (seasonalMap.containsKey(seasonal)) { TreeMap<Weekday, TreeMap<Long, BuildingLocation>> weekdayMap = seasonalMap.get(seasonal); Weekday weekly = weekdayMap.lowerKey(weekday) == null ? weekday : weekdayMap.lowerKey(weekday); if (weekdayMap.containsKey(weekly)) { BuildingLocation location = getTargetFromMapBasedOnTime(weekdayMap.get(weekly), time); if (location != null) return location; } } return default_; }
private void rotateLeftToRight(Map.Entry<Comparable, InnerNode> leftEntry, Map.Entry<Comparable, InnerNode> rightEntry) { InnerNode leftSubNode = leftEntry.getValue(); InnerNode rightSubNode = rightEntry.getValue(); TreeMap<Comparable, AbstractNode> newLeftSubNodeSubNodes = leftSubNode.duplicateMap(); TreeMap<Comparable, AbstractNode> newRightSubNodeSubNodes = rightSubNode.duplicateMap(); Comparable leftHighestKey = newLeftSubNodeSubNodes.lowerKey(BPlusTree.LAST_KEY); AbstractNode leftHighestValue = newLeftSubNodeSubNodes.get(BPlusTree.LAST_KEY); // move the highest value from the left to the right. Use the split-key as the index. newRightSubNodeSubNodes.put(leftEntry.getKey(), leftHighestValue); leftHighestValue.setParent(rightSubNode); // shift a new child to the last entry on the left leftHighestValue = newLeftSubNodeSubNodes.remove(leftHighestKey); newLeftSubNodeSubNodes.put(BPlusTree.LAST_KEY, leftHighestValue); leftSubNode.setSubNodes(newLeftSubNodeSubNodes); rightSubNode.setSubNodes(newRightSubNodeSubNodes); // update the split-key to be the key we just removed from the left TreeMap<Comparable, AbstractNode> newMap = duplicateMap(); newMap.remove(leftEntry.getKey()); newMap.put(leftHighestKey, leftSubNode); setSubNodes(newMap); }
switch (operator) { case LESS_THAN: return ((TreeMap<Object, StreamEvent>) primaryKeyData).lowerKey(value) != null; case GREATER_THAN: return ((TreeMap<Object, StreamEvent>) primaryKeyData).higherKey(value) != null; return currentIndexedData.lowerKey(value) != null; case GREATER_THAN: return currentIndexedData.higherKey(value) != null;
model.addAttribute("previd", tas.lowerKey(taid)); }else{ model.addAttribute("previd", -1);
public List<Pair<Integer, Float>> getXIC(int scanNum, float mz, Tolerance tol) { ArrayList<Pair<Integer, Float>> xic = new ArrayList<Pair<Integer, Float>>(); Peak p; // Move down Integer curScanNum = scanNum; while (curScanNum != null && scanNum > 0) { curScanNum = ms1SpecMap.lowerKey(curScanNum); if ((p = getMS1Peak(curScanNum, mz, tol)) != null) xic.add(new Pair<Integer, Float>(curScanNum, p.getIntensity())); else break; } // Move up curScanNum = scanNum; while (curScanNum != null && curScanNum < 100000) { curScanNum = ms1SpecMap.higherKey(curScanNum); if ((p = getMS1Peak(curScanNum, mz, tol)) != null) xic.add(new Pair<Integer, Float>(curScanNum, p.getIntensity())); else break; } Collections.sort(xic, new Pair.PairComparator<Integer, Float>()); return xic; }
public boolean checkMS1Peaks(int scanNum, float mz, int charge, Tolerance tol, int windowSize) { int precursorScanNum = ms1SpecMap.floorKey(scanNum); if (checkMS1Peaks(precursorScanNum, mz, charge, tol)) return true; // Move down Integer curScanNum = precursorScanNum; for (int i = 0; i < windowSize; i++) { curScanNum = ms1SpecMap.lowerKey(curScanNum); if (curScanNum == null) break; else { if (checkMS1Peaks(curScanNum, mz, charge, tol)) return true; } } // Move up curScanNum = precursorScanNum; for (int i = 0; i < windowSize; i++) { curScanNum = ms1SpecMap.higherKey(curScanNum); if (curScanNum == null) break; else { if (checkMS1Peaks(curScanNum, mz, charge, tol)) return true; } } return false; }
assertEquals(treemap.floorKey(5), actual.floorKey(5)); assertEquals(treemap.ceilingKey(5), actual.ceilingKey(5)); assertEquals(treemap.lowerKey(5), actual.lowerKey(5)); assertEquals(treemap.higherKey(5), actual.higherKey(5));
(map, key) -> map.lowerKey(key), (map, key) -> null, (map, key) -> null
assertEquals(firstEvent(treemap.lowerEntry(i)), event.get("le")); EPAssertionUtil.assertEqualsExactOrder(allEvents(treemap.lowerEntry(i)), (SupportBean[]) event.get("les")); assertEquals(treemap.lowerKey(i), event.get("lk"));