List of usage examples for java.util SortedMap lastKey
K lastKey();
From source file:Main.java
public static void main(String[] args) { SortedMap<String, Integer> sortedMap = new TreeMap<String, Integer>(); sortedMap.put("A", 1); sortedMap.put("B", 2); sortedMap.put("C", 3); sortedMap.put("D", 4); sortedMap.put("E", 5); sortedMap.put("java2s", 6); System.out.println(sortedMap.lastKey()); }
From source file:Main.java
public static void main(String[] args) { SortedMap<String, String> sMap = new TreeMap<>(); sMap.put("CSS", "style"); sMap.put("HTML", "mark up"); sMap.put("Oracle", "database"); sMap.put("XML", "data"); SortedMap<String, String> subMap = sMap.subMap("CSS", "XML"); System.out.println(subMap);/*from w ww .j ava 2 s .co m*/ // Get the first and last keys String firstKey = sMap.firstKey(); String lastKey = sMap.lastKey(); System.out.println("First Key: " + firstKey); System.out.println("Last key: " + lastKey); }
From source file:Main.java
public static void main(String[] args) { Comparator<String> keyComparator = Comparator.comparing(String::length) .thenComparing(String::compareToIgnoreCase); SortedMap<String, String> sMap = new TreeMap<>(keyComparator); sMap.put("CSS", "style"); sMap.put("HTML", "mark up"); sMap.put("Oracle", "database"); sMap.put("XML", "data"); SortedMap<String, String> subMap = sMap.subMap("CSS", "XML"); System.out.println(subMap);// w w w .j av a2s . com // Get the first and last keys String firstKey = sMap.firstKey(); String lastKey = sMap.lastKey(); System.out.println("First Key: " + firstKey); System.out.println("Last key: " + lastKey); }
From source file:org.archive.util.PrefixFinder.java
private static String last(SortedMap<String, ?> map) { // TODO Auto-generated method stub return map.isEmpty() ? null : map.lastKey(); }
From source file:dev.drsoran.moloko.fragments.TagCloudFragment.java
private final static float getMagnifyFactor(int count) { Float result = MAGNIFY_LOOKUP.get(count); if (result == null) { final Integer min = MAGNIFY_LOOKUP.firstKey(); if (count < min) result = MAGNIFY_LOOKUP.get(MAGNIFY_LOOKUP.firstKey()); else {//from w w w . j av a 2 s .c om final Integer max = MAGNIFY_LOOKUP.lastKey(); if (count > max) result = MAGNIFY_LOOKUP.get(MAGNIFY_LOOKUP.lastKey()); else { final SortedMap<Integer, Float> subMap = MAGNIFY_LOOKUP.headMap(count); result = MAGNIFY_LOOKUP.get(subMap.lastKey()); } } } return result; }
From source file:org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.java
public static <S> S forStationAdjacent(final SortedMap<BigDecimal, S> stationIndex, final BigDecimal station, final boolean upstream) { final BigDecimal pred = NumberUtils.decrement(station); final BigDecimal succ = NumberUtils.increment(station); if (upstream) { final SortedMap<BigDecimal, ? extends Object> successors = stationIndex.tailMap(succ); if (!successors.isEmpty()) return stationIndex.get(successors.firstKey()); } else {//from ww w .j av a 2 s. c om final SortedMap<BigDecimal, ? extends Object> predecessors = stationIndex.headMap(pred); if (!predecessors.isEmpty()) return stationIndex.get(predecessors.lastKey()); } return null; }
From source file:org.orekit.models.earth.GeoMagneticFieldFactory.java
/** Gets a geomagnetic field model for the given year. In case the specified * year does not match an existing model epoch, the resulting field is * generated by either time-transforming an existing model using its secular * variation coefficients, or by linear interpolating two existing models. * @param type the type of the field (e.g. WMM or IGRF) * @param models all loaded field models, sorted by their epoch * @param year the epoch of the resulting field model * @return a {@link GeoMagneticField} model for the given year * @throws OrekitException if the specified year is out of range of the available models *//*www. j a va 2s . c om*/ private static GeoMagneticField getModel(final FieldModel type, final TreeMap<Integer, GeoMagneticField> models, final double year) throws OrekitException { final int epochKey = (int) (year * 100d); final SortedMap<Integer, GeoMagneticField> head = models.headMap(epochKey, true); if (head.isEmpty()) { throw new OrekitException(OrekitMessages.NON_EXISTENT_GEOMAGNETIC_MODEL, type.name(), year); } GeoMagneticField model = models.get(head.lastKey()); if (model.getEpoch() < year) { if (model.supportsTimeTransform()) { model = model.transformModel(year); } else { final SortedMap<Integer, GeoMagneticField> tail = models.tailMap(epochKey, false); if (tail.isEmpty()) { throw new OrekitException(OrekitMessages.NON_EXISTENT_GEOMAGNETIC_MODEL, type.name(), year); } final GeoMagneticField secondModel = models.get(tail.firstKey()); if (secondModel != model) { model = model.transformModel(secondModel, year); } } } return model; }
From source file:nu.yona.app.api.service.ActivityMonitorService.java
private static String printForegroundTask(Context context) { currentApp = "NULL"; try {//w ww . j ava2 s . c o m if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { UsageStatsManager usm = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE); long time = System.currentTimeMillis(); List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - AppConstant.ONE_SECOND * AppConstant.ONE_SECOND, time); if (appList != null && appList.size() > 0) { SortedMap<Long, UsageStats> mySortedMap = new TreeMap<>(); for (UsageStats usageStats : appList) { mySortedMap.put(usageStats.getLastTimeUsed(), usageStats); } if (!mySortedMap.isEmpty()) { currentApp = mySortedMap.get(mySortedMap.lastKey()).getPackageName(); } } } else { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); currentApp = am.getRunningAppProcesses().get(0).processName; } } catch (Exception e) { AppUtils.reportException(ActivityMonitorService.class.getSimpleName(), e, Thread.currentThread()); } return currentApp; }
From source file:co.cask.cdap.logging.save.LogSaverPluginTest.java
private static Location getLatestFile(Location logBaseDir, String filePattern) throws Exception { String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); Location dir = logBaseDir.append(String.format(filePattern, date)); if (!dir.exists()) { return null; }// ww w . j a v a2s . c o m List<Location> files = dir.list(); if (files.isEmpty()) { return null; } SortedMap<Long, Location> map = Maps.newTreeMap(); for (Location file : files) { String filename = FilenameUtils.getBaseName(file.getName()); map.put(Long.parseLong(filename), file); } return map.get(map.lastKey()); }
From source file:org.apache.hadoop.hbase.client.TestClientNoCluster.java
static GetResponse doMetaGetResponse(final SortedMap<byte[], Pair<HRegionInfo, ServerName>> meta, final GetRequest request) { ClientProtos.Result.Builder resultBuilder = ClientProtos.Result.newBuilder(); ByteString row = request.getGet().getRow(); Pair<HRegionInfo, ServerName> p = meta.get(row.toByteArray()); if (p == null) { if (request.getGet().getClosestRowBefore()) { byte[] bytes = row.toByteArray(); SortedMap<byte[], Pair<HRegionInfo, ServerName>> head = bytes != null ? meta.headMap(bytes) : meta; p = head == null ? null : head.get(head.lastKey()); }/*w w w.j av a 2 s .com*/ } if (p != null) { resultBuilder.addCell(getRegionInfo(row, p.getFirst())); resultBuilder.addCell(getServer(row, p.getSecond())); } resultBuilder.addCell(getStartCode(row)); GetResponse.Builder builder = GetResponse.newBuilder(); builder.setResult(resultBuilder.build()); return builder.build(); }