Java 8 NavigableMap - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 NavigableMap class.

This code example shows how to use the following methods:ceilingEntry, lowerEntry
	} 
 
	public V get(K key) {
		lock.lock();
		try { 
			Map.Entry<K, Value<V>> start = map.lowerEntry(key);
			Map.Entry<K, Value<V>> end = map.ceilingEntry(key);
			if (start == null || end == null) {
				return null; 
			} 
			return end.getValue().get();
		} finally { 
			lock.unlock();
		} 
	} 
	 
	public void removeIfExpired(K key) {
		lock.lock();
		try { 
			Map.Entry<K, Value<V>> end = map.ceilingEntry(key);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:put, size, pollLastEntry
		assertEquals(BAD_FIRST_ENTRY_KEY, "ka", firstEntry.getKey());
		assertEquals("must have 2 entries", 2, navigableMap.size());
	} 
 
	public void testPollLastEntry() { 
		assertNull("must not have last entry", navigableMap.pollLastEntry());
		navigableMap.put("ka", "xx");
		navigableMap.put("kb", "aa");
		navigableMap.put("kc", "zz");
		assertEquals("must have 3 entries", 3, navigableMap.size());
		final Entry<String, String> lastEntry = navigableMap.pollLastEntry();
		assertNotNull("must have last entry", lastEntry);
		assertEquals("bad last entry value", "zz", lastEntry.getValue());
		assertEquals("bad last entry key", "kc", lastEntry.getKey());
		assertEquals("must have 2 entries", 2, navigableMap.size());
	} 
 
//  TODO implement this 
// 
//	public void testDescendingMap() { 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:get, put, remove, floorEntry
  } 
 
  @Override 
  public boolean add(Long aLong) {
    // Find the largest LongSegment with a min value of less than or equal to aLong 
    Map.Entry<Long, LongSegment> lowerEntry = map.floorEntry(aLong);
 
    // This value is already added 
    if (lowerEntry != null && lowerEntry.getValue().contains(aLong)) {
      return false; 
    } 
 
    // Get the LongSegment with a min value directly after aLong 
    LongSegment upperSegment = map.get(aLong + 1);
 
    // Determine possibly adjacencies with lower and upper bound LongSegments 
    boolean lowerAdjacent = lowerEntry != null && lowerEntry.getValue().getMax() + 1 == aLong;
    boolean upperAdjacent = upperSegment != null && upperSegment.getMin() - 1 == aLong;
 
    if (lowerAdjacent && upperAdjacent) {

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:lastEntry
        } 
 
        @Override 
        public Entry next() { 
            final Map.Entry<byte[], NavigableMap<Long, byte[]>> entry = iterator.next();
            return new StaticBufferEntry(new StaticByteBuffer(entry.getKey()), new StaticByteBuffer(entry.getValue().lastEntry().getValue()));
        } 
 
        @Override 
        public void remove() { 
            throw new UnsupportedOperationException();
        } 
    } 
 
} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:ceilingEntry, ceilingKey, floorEntry, floorKey, higherEntry
    assertNull(navigableMap.pollFirstEntry());
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptyMapNearby() { 
    assertNull(navigableMap.lowerEntry(samples.e0.getKey()));
    assertNull(navigableMap.lowerKey(samples.e0.getKey()));
    assertNull(navigableMap.floorEntry(samples.e0.getKey()));
    assertNull(navigableMap.floorKey(samples.e0.getKey()));
    assertNull(navigableMap.ceilingEntry(samples.e0.getKey()));
    assertNull(navigableMap.ceilingKey(samples.e0.getKey()));
    assertNull(navigableMap.higherEntry(samples.e0.getKey()));
    assertNull(navigableMap.higherKey(samples.e0.getKey()));
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptyMapLast() { 
    assertNull(navigableMap.lastEntry());
  } 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isEmpty, tailMap
   * so that an {@link Iterator} can be created   
   * for iterating the given {@link NavigableMap}. 
   * The iteration begins from the starting key exclusively. 
   */ 
  public CyclicIteration(NavigableMap<K, V> navigablemap, K startingkey) {
    if (navigablemap == null || navigablemap.isEmpty()) {
      this.navigablemap = null;
      this.tailmap = null;
    } 
    else { 
      this.navigablemap = navigablemap;
      this.tailmap = navigablemap.tailMap(startingkey, false); 
    } 
  } 
 
  /** {@inheritDoc} */ 
  public Iterator<Map.Entry<K, V>> iterator() {
    return new CyclicIterator(); 
  } 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:put, ceilingEntry, floorKey, higherKey, lowerKey
    public static void main(String[] args)
    { 
        final Customer max = new Customer("Max", "Muster", "Bremen", 47);
        final Customer moritz = new Customer("Moritz", "Muster", "Aachen", 39);
 
        final NavigableMap<String, Customer> customers = new TreeMap<String, Customer>();
        customers.put("Max", max);
        customers.put("Moritz", moritz);
 
        System.out.println("floor   Ma: " + customers.floorKey("Ma"));
        System.out.println("higher  Ma: " + customers.higherKey("Ma"));
        System.out.println("lower   Mc: " + customers.lowerKey("Mc"));
        System.out.println("ceiling Mc: " + customers.ceilingEntry("Mc"));
    } 
     
    private TreeMapExample() 
    { 
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:floorKey, firstKey, lastKey
    } 
    if (value > lastKey()) {
      throw new IllegalArgumentException("Could not get lower bound key for " + value + ": highest x-value is "
          + lastKey()); 
    } 
    return _backingMap.floorKey(value);
  } 
 
  @Override 
  public int getLowerBoundIndex(final Double value) {
    final Double lower = getLowerBoundKey(value);
    int i = 0;
    final Iterator<Double> iter = _backingMap.keySet().iterator();
    Double key = iter.next();
    while (!key.equals(lower)) {
      key = iter.next();
      i++;
    } 
    return i;
  } 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:subMap
 
    return changes; 
  } 
 
  public Collection<OTransactionIndexChangesPerKey> getChangesForKeys(final Object firstKey, final Object lastKey) { 
    return changesPerKey.subMap(firstKey, lastKey).values(); 
  } 
 
  public void setCleared() { 
    changesPerKey.clear(); 
    cleared = true; 
  } 
 
  public boolean containsChangesPerKey(final Object iKey) { 
    return changesPerKey.containsKey(iKey); 
  } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:ceilingEntry, ceilingKey, floorEntry, floorKey, higherEntry
    assertNull(navigableMap.pollFirstEntry());
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptyMapNearby() { 
    assertNull(navigableMap.lowerEntry(samples.e0.getKey()));
    assertNull(navigableMap.lowerKey(samples.e0.getKey()));
    assertNull(navigableMap.floorEntry(samples.e0.getKey()));
    assertNull(navigableMap.floorKey(samples.e0.getKey()));
    assertNull(navigableMap.ceilingEntry(samples.e0.getKey()));
    assertNull(navigableMap.ceilingKey(samples.e0.getKey()));
    assertNull(navigableMap.higherEntry(samples.e0.getKey()));
    assertNull(navigableMap.higherKey(samples.e0.getKey()));
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptyMapLast() { 
    assertNull(navigableMap.lastEntry());
    try { 
      assertNull(navigableMap.lastKey());
6
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 NavigableMap Methods: