List of usage examples for java.util TreeMap tailMap
public NavigableMap<K, V> tailMap(K fromKey, boolean inclusive)
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"); System.out.println("Getting tail map"); SortedMap<Integer, String> treemapincl = treemap.tailMap(3, true); System.out.println("Tail map values: " + treemapincl); }
From source file:org.apache.ambari.server.controller.metrics.timeline.cache.TimelineMetricCacheEntryFactory.java
private void updateExistingMetricValues(TimelineMetrics existingMetrics, Long requestedStartTime, Long requestedEndTime, boolean removeAll) { for (TimelineMetric existingMetric : existingMetrics.getMetrics()) { if (removeAll) { existingMetric.setMetricValues(new TreeMap<Long, Double>()); } else {//from w w w . j a va 2s .co m TreeMap<Long, Double> existingMetricValues = existingMetric.getMetricValues(); LOG.trace( "Existing metric: " + existingMetric.getMetricName() + " # " + existingMetricValues.size()); // Retain only the values that are within the [requestStartTime, requestedEndTime] window existingMetricValues.headMap(requestedStartTime, false).clear(); existingMetricValues.tailMap(requestedEndTime, false).clear(); } } }
From source file:com.eucalyptus.tests.awssdk.S3ListMpuTests.java
@Test public void keyMarker() throws Exception { testInfo(this.getClass().getSimpleName() + " - keyMarker"); try {//w w w .j a v a 2 s.com int numKeys = 3 + random.nextInt(3); // 3-5 keys int numUploads = 3 + random.nextInt(3); // 3-5 uploads print("Number of keys: " + numKeys); print("Number of uploads per key: " + numUploads); // Generate some mpus TreeMap<String, List<String>> keyUploadIdMap = initiateMpusForMultipleKeys(s3ClientA, accountA, numKeys, numUploads, new String()); // Starting with every key in the ascending order, list the mpus using that key as the key marker and verify that the results. for (String keyMarker : keyUploadIdMap.keySet()) { // Compute what the sorted mpus should look like NavigableMap<String, List<String>> tailMap = keyUploadIdMap.tailMap(keyMarker, false); // List mpus using the key marker and verify MultipartUploadListing listing = listMpu(s3ClientA, accountA, bucketName, keyMarker, null, null, null, null, false); assertTrue( "Expected " + (tailMap.size() * numUploads) + " mpu listings, but got " + listing.getMultipartUploads().size(), (tailMap.size() * numUploads) == listing.getMultipartUploads().size()); Iterator<MultipartUpload> mpuIterator = listing.getMultipartUploads().iterator(); for (Entry<String, List<String>> tailMapEntry : tailMap.entrySet()) { for (String uploadId : tailMapEntry.getValue()) { MultipartUpload mpu = mpuIterator.next(); assertTrue("Expected key to be " + tailMapEntry.getKey() + ", but got " + mpu.getKey(), mpu.getKey().equals(tailMapEntry.getKey())); assertTrue("Expected upload ID to be " + uploadId + ", but got " + mpu.getUploadId(), mpu.getUploadId().equals(uploadId)); verifyCommonElements(mpu); } } assertTrue("Expected mpu iterator to be empty", !mpuIterator.hasNext()); } } catch (AmazonServiceException ase) { printException(ase); assertThat(false, "Failed to run keyMarker"); } }
From source file:com.eucalyptus.tests.awssdk.S3ListMpuTests.java
@Test public void keyMarkerUploadIdMarker() throws Exception { testInfo(this.getClass().getSimpleName() + " - keyMarkerUploadIdMarker"); try {/* w w w . j a v a 2s . co m*/ int numKeys = 3 + random.nextInt(3); // 3-5 keys int numUploads = 3 + random.nextInt(3); // 3-5 uploads print("Number of keys: " + numKeys); print("Number of uploads per key: " + numUploads); // Generate some mpus TreeMap<String, List<String>> keyUploadIdMap = initiateMpusForMultipleKeys(s3ClientA, accountA, numKeys, numUploads, new String()); // Starting with every key and upload ID in the ascending order, list the mpus using the pair and verify that the results. for (Map.Entry<String, List<String>> mapEntry : keyUploadIdMap.entrySet()) { // Compute what the sorted mpus should look like NavigableMap<String, List<String>> tailMap = keyUploadIdMap.tailMap(mapEntry.getKey(), false); for (int i = 0; i < numUploads; i++) { // Compute what the sorted uploadIds should look like this key List<String> tailList = mapEntry.getValue().subList(i + 1, numUploads); // List mpus using the key marker and upload ID marker and verify MultipartUploadListing listing = listMpu(s3ClientA, accountA, bucketName, mapEntry.getKey(), mapEntry.getValue().get(i), null, null, null, false); assertTrue( "Expected " + ((tailMap.size() * numUploads) + (numUploads - i - 1)) + " mpu listings, but got " + listing.getMultipartUploads().size(), ((tailMap.size() * numUploads) + (numUploads - i - 1)) == listing.getMultipartUploads() .size()); Iterator<MultipartUpload> mpuIterator = listing.getMultipartUploads().iterator(); for (String uploadId : tailList) { MultipartUpload mpu = mpuIterator.next(); assertTrue("Expected key to be " + mapEntry.getKey() + ", but got " + mpu.getKey(), mpu.getKey().equals(mapEntry.getKey())); assertTrue("Expected upload ID to be " + uploadId + ", but got " + mpu.getUploadId(), mpu.getUploadId().equals(uploadId)); verifyCommonElements(mpu); } for (Entry<String, List<String>> tailMapEntry : tailMap.entrySet()) { for (String uploadId : tailMapEntry.getValue()) { MultipartUpload mpu = mpuIterator.next(); assertTrue("Expected key to be " + tailMapEntry.getKey() + ", but got " + mpu.getKey(), mpu.getKey().equals(tailMapEntry.getKey())); assertTrue("Expected upload ID to be " + uploadId + ", but got " + mpu.getUploadId(), mpu.getUploadId().equals(uploadId)); verifyCommonElements(mpu); } } assertTrue("Expected mpu iterator to be empty", !mpuIterator.hasNext()); } } } catch (AmazonServiceException ase) { printException(ase); assertThat(false, "Failed to run keyMarkerUploadIdMarker"); } }
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 *//*from w w w .ja va 2s.com*/ 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; }