Java 8 NavigableSet - 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 NavigableSet class.

This code example shows how to use the following methods:ceiling, floor, higher, lower, add
 
public class SortedSetDemo 
{ 
  public static void main( String[] args )
  { 
    NavigableSet<Calendar> set = new TreeSet<Calendar>();
    set.add( new GregorianCalendar(2007, Calendar.MARCH, 10) );
    set.add( new GregorianCalendar(2007, Calendar.MARCH, 12) );
    set.add( new GregorianCalendar(2007, Calendar.APRIL, 12) );
     
    Calendar cal1 = set.lower( new GregorianCalendar(2007, Calendar.MARCH, 12) );
    System.out.printf( "%tF%n", cal1 );   // 2007-03-10
     
    Calendar cal2 = set.ceiling( new GregorianCalendar(2007, Calendar.MARCH, 12) );
    System.out.printf( "%tF%n", cal2 );   // 2007-03-12
     
    Calendar cal3 = set.floor( new GregorianCalendar(2007, Calendar.MARCH, 12) );
    System.out.printf( "%tF%n", cal3 );   // 2007-03-12
 
    Calendar cal4 = set.higher( new GregorianCalendar(2007, Calendar.MARCH, 12) );

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:ceiling, floor, higher, lower
    assertNull(navigableSet.pollFirst());
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptySetNearby() { 
    assertNull(navigableSet.lower(samples.e0));
    assertNull(navigableSet.floor(samples.e0));
    assertNull(navigableSet.ceiling(samples.e0));
    assertNull(navigableSet.higher(samples.e0));
  } 
 
  @CollectionFeature.Require(SUPPORTS_REMOVE) 
  @CollectionSize.Require(ZERO) 
  public void testEmptySetPollLast() { 
    assertNull(navigableSet.pollLast());
  } 
 
  @CollectionFeature.Require(SUPPORTS_REMOVE) 
  @CollectionSize.Require(ONE) 
  public void testSingletonSetPollFirst() { 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains, remove, first, last
		navigableMap.put("ka", "xx");
		navigableMap.put("kb", "aa");
		navigableMap.put("kc", "zz");
		final NavigableSet<String> navigableSet = navigableMap
				.navigableKeySet();
		assertEquals("bad first element", "ka", navigableSet.first());
		assertEquals("bad last element", "kc", navigableSet.last());
		assertTrue(MUST_CONTAINS_KA, navigableSet.contains("ka"));
		assertTrue(MUST_CONTAINS_KB, navigableSet.contains("kb"));
		assertTrue(MUST_CONTAINS_KC, navigableSet.contains("kc"));
 
		navigableSet.remove("kb");
		assertEquals(BAD_SIZE, 2, navigableMap.size());
		assertFalse(MUST_NOT_BE_EMPTY, navigableMap.isEmpty());
		assertTrue("must contains key 'ka'", navigableMap.containsKey("ka"));
		assertFalse("must not contains key 'kb'", navigableMap
				.containsKey("kb"));
		assertTrue("must contains key 'kc'", navigableMap.containsKey("kc"));
	} 
// TODO implement this 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:add
	} 
	 
	public static void main(String[] args) {
		PrefixSet x = new PrefixSet();
		 
		x.getSet().add("aaa");
		x.getSet().add("bbb");
		x.getSet().add("b");
		x.getSet().add("ccc");
		x.getSet().add("cccd");
		x.getSet().add("cccde");
 
		 
		//TODO Creata JUNIT Test case 
		//Assert.assertTrue(x.containsPrefixOf("cccd")); 
		//Assert.assertTrue(x.isPrefixForItem("bb")); 
	} 
 
	public void removeAll(Collection<String> ps) {
		prefixes.removeAll(ps);
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:headSet, tailSet
  protected NavigableSet<E> standardSubSet(
      E fromElement,
      boolean fromInclusive,
      E toElement,
      boolean toInclusive) {
    return tailSet(fromElement, fromInclusive).headSet(toElement, toInclusive);
  } 
 
  /** 
   * A sensible definition of {@link #subSet(Object, Object)} in terms of the 
   * {@link #subSet(Object, boolean, Object, boolean)} method. If you override 
   * {@link #subSet(Object, boolean, Object, boolean)}, you may wish to override 
   * {@link #subSet(Object, Object)} to forward to this implementation. 
   */ 
  @Override 
  protected SortedSet<E> standardSubSet(E fromElement, E toElement) {
    return subSet(fromElement, true, toElement, false);
  } 
 
  @Override 

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:ceiling, floor, higher, lower
    assertNull(navigableSet.pollFirst());
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptySetNearby() { 
    assertNull(navigableSet.lower(samples.e0));
    assertNull(navigableSet.floor(samples.e0));
    assertNull(navigableSet.ceiling(samples.e0));
    assertNull(navigableSet.higher(samples.e0));
  } 
 
  @CollectionFeature.Require(SUPPORTS_REMOVE) 
  @CollectionSize.Require(ZERO) 
  public void testEmptySetPollLast() { 
    assertNull(navigableSet.pollLast());
  } 
 
  @CollectionFeature.Require(SUPPORTS_REMOVE) 
  @CollectionSize.Require(ONE) 
  public void testSingletonSetPollFirst() { 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:tailSet, add, size, toArray
   * @see java.util.NavigableSet#tailSet(Object, boolean) 
   */ 
  public void testTailSet_entries1_size_keyValue() { 
    NavigableSet<E> sortedSet = createNavigableSet();
    // test with a single entry set 
    sortedSet.add(getKeys()[0]);
 
    Set<E> tailSet = sortedSet.tailSet(getKeys()[0]);
    assertEquals(1, tailSet.size());
    assertEquals(getKeys()[0], tailSet.toArray()[0]);
 
    Set<E> exclusiveTailSet = sortedSet.tailSet(getKeys()[0], false);
    assertEquals(0, exclusiveTailSet.size());
    assertEquals(0, exclusiveTailSet.size());
 
    Set<E> inclusiveTailSet = sortedSet.tailSet(getKeys()[0], true);
    assertEquals(1, inclusiveTailSet.size());
    assertEquals(getKeys()[0], inclusiveTailSet.toArray()[0]);
  } 
 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:ceiling, floor, higher, lower
    assertNull(navigableSet.pollFirst());
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptySetNearby() { 
    assertNull(navigableSet.lower(samples.e0));
    assertNull(navigableSet.floor(samples.e0));
    assertNull(navigableSet.ceiling(samples.e0));
    assertNull(navigableSet.higher(samples.e0));
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptySetLast() { 
    try { 
      navigableSet.last();
      fail(); 
    } catch (NoSuchElementException e) {
    } 
  } 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:pollFirst, isEmpty
     * may cause "current time" to move backwards. 
     * 
     * @return the first event scheduled 
     */ 
    public EventMessage advanceToNextTrigger() { 
        if (scheduledEvents.isEmpty()) {
            throw new NoSuchElementException("There are no scheduled events");
        } 
        StubScheduleToken nextItem = scheduledEvents.pollFirst();
        if (nextItem.getScheduleTime().isAfter(currentDateTime)) {
            currentDateTime = nextItem.getScheduleTime();
        } 
        return nextItem.getEvent();
    } 
 
    /** 
     * Advance time to the given <code>newDateTime</code> and returns all events scheduled for publication until that 
     * time. 
     * 
     * @param newDateTime The time to advance the "current time" of the scheduler to 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:ceiling, floor, higher, lower
    assertNull(navigableSet.pollFirst());
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptySetNearby() { 
    assertNull(navigableSet.lower(samples.e0));
    assertNull(navigableSet.floor(samples.e0));
    assertNull(navigableSet.ceiling(samples.e0));
    assertNull(navigableSet.higher(samples.e0));
  } 
 
  @CollectionSize.Require(ZERO) 
  public void testEmptySetLast() { 
    try { 
      navigableSet.last();
      fail(); 
    } catch (NoSuchElementException e) {
    } 
  } 
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 NavigableSet Methods: