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

This code example shows how to use the following methods:isEmpty, removeAll
            String name2, SortedSet<String> set2) {
        Set<String> onlyInSet1 = new TreeSet<String>(set1);
 
        onlyInSet1.removeAll(set2);
 
        Set<String> onlyInSet2 = new TreeSet<String>(set2);
        onlyInSet2.removeAll(set1);
 
        if (!onlyInSet1.isEmpty() || !onlyInSet2.isEmpty()) {
            fail(String.format("in %s only: %s\nin %s only: %s", name1, onlyInSet1, name2, onlyInSet2));
        } 
 
        assertEquals(set2, set1);
    } 
 
    protected SortedSet<String> findAllPropertyNames(Class<?> clazz) throws Exception {
        SortedSet<String> names = new TreeSet<String>();
        for (PropertyDescriptor propDesc : getBeanInfo(clazz).getPropertyDescriptors()) {
            if (propDesc == null
                    || propDesc.getWriteMethod() == null) {
8
CodeRank
This code example shows how to use the following methods:
 * @since 2.3 
 */ 
public class StringsCompleter 
    implements Completer 
{ 
    private final SortedSet<String> strings = new TreeSet<String>();
 
    public StringsCompleter() { 
        // empty 
    } 
 
    public StringsCompleter(final Collection<String> strings) {
        assert strings != null;
        getStrings().addAll(strings);
    } 
 
    public StringsCompleter(final String... strings) {
        this(Arrays.asList(strings));
    } 
 
8
CodeRank
This code example shows how to use the following methods:add, iterator
        ConsoleVersion version122 = new ConsoleVersion("1.2.2");
        ConsoleVersion version200 = new ConsoleVersion("2.0.0");
        ConsoleVersion version201 = new ConsoleVersion("2.0.1");
        ConsoleVersion version210 = new ConsoleVersion("2.1.0");
 
        TreeSet<ConsoleVersion> set = new TreeSet<ConsoleVersion>();
        set.add(versionMain);
        set.add(version001);
        set.add(version002);
        set.add(version010);
        set.add(version020);
        set.add(version100);
        set.add(version101);
        set.add(version102);
        set.add(version110);
        set.add(version111);
        set.add(version120);
        set.add(version122);
        set.add(version200);
        set.add(version201);

8
CodeRank
This code example shows how to use the following methods:add
    } 
 
    public void testZipStructure() throws Exception {
        ZipStructure zipStructure = new ZipStructure();
        Map<Integer, TreeSet<String>> levelToContents = zipStructure.getLevelToContents();
        TreeSet<String> tree = new TreeSet<String>();
        tree.add("file1.py");
        tree.add("file2.py");
        tree.add("dir/");
        tree.add("dir2/");
        tree.add("zz/");
 
        levelToContents.put(0, tree);
 
        tree = new TreeSet<String>();
        tree.add("dir/dir3/");
        tree.add("dir/file1.py");
        tree.add("dir/zzz.py");
        tree.add("dir2/file2.py");
 
8
CodeRank
This code example shows how to use the following methods:add, size
        //given 
        Date today    = mock(Date.class);
        Date tomorrow = mock(Date.class);
 
        //when 
        Set<Date> set = new TreeSet<Date>();
        set.add(today);
        set.add(tomorrow);
 
        //then 
        assertEquals(2, set.size());
    } 
 
    @Test 
    public void shouldAllowStubbingAndVerifyingCompareTo() { 
        //given 
        Date mock    = mock(Date.class);
        when(mock.compareTo(any(Date.class))).thenReturn(10);
 
        //when 
7
CodeRank
This code example shows how to use the following methods:
   * The X coordinate 
   */ 
  long datum = -1L;
 
  static private Set<String> alreadySeenAnySetterAttributes =
      new TreeSet<String>();
 
  @SuppressWarnings("unused") 
  // for input parameter ignored. 
  @JsonAnySetter 
  public void setUnknownAttribute(String attributeName, Object ignored) {
    if (!alreadySeenAnySetterAttributes.contains(attributeName)) {
      alreadySeenAnySetterAttributes.add(attributeName);
      System.err.println("In LoggedJob, we saw the unknown attribute "
          + attributeName + ".");
    } 
  } 
 
  public double getRelativeRanking() { 
    return relativeRanking;
8
CodeRank
This code example shows how to use the following methods:
    } 
     
    @Test 
    public void getAttributeNames() { 
        SessionAttributes attributes = mock(SessionAttributes.class);
        Set<String> expected = new TreeSet<String>();
         
        when(this.session.getAttributes()).thenReturn(attributes);
        when(attributes.getAttributeNames()).thenReturn(expected);
         
        Enumeration<String> result = this.httpSession.getAttributeNames();
         
        assertEquals(new ArrayList<>(expected), Collections.list(result));
    } 
 
    @Test 
    public void getAttribute() { 
        SessionAttributes attributes = mock(SessionAttributes.class);
        String name = "name";
        Object expected = new Object();
7
CodeRank
This code example shows how to use the following methods:
  public static String printModifiers(Set<Modifier> allModifiers) {
    if (allModifiers.isEmpty()) {
      return ""; 
    } 
 
    SortedSet<Modifier> sorted = new TreeSet<>(allModifiers);
    return Joiner.on(" ").join(sorted) + " ";
  } 
} 
7
CodeRank
This code example shows how to use the following methods:add
  public void addRow(int indexNum, int rowNum)
  { 
    TreeSet<Integer> rowNums = comprisedRows.get(indexNum);
    if (rowNums == null) {
      rowNums = Sets.newTreeSet();
      comprisedRows.put(indexNum, rowNums);
    } 
    rowNums.add(rowNum);
  } 
 
  public Map<Integer, TreeSet<Integer>> getComprisedRows()
  { 
    return comprisedRows;
  } 
 
  public int getRowNum() 
  { 
    return rowNum;
  } 
 
7
CodeRank
This code example shows how to use the following methods:add, remove, size
     *       recently used position, but doesn't add 
     *       a duplicate entry in the queue. 
     * @param now  
     */ 
    public final synchronized void push(T value, long now) {
    	assert(elements.size() == valueToElement.size());
    	if (value == null)
    		throw new NullPointerException();
    	 
    	Element<T> e = valueToElement.get(value);
    	 
    	if(e == null) {
    		e = new Element<T>(now, value);
    		elements.add(e);
    		valueToElement.put(value, e);
    	} else { 
    		elements.remove(e);
    		e.time = now;
    		elements.add(e);
    	} 

7
CodeRank

Related Java 8 TreeSet Questions & Answers:

See Code Examples for Java 8 TreeSet Methods: