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
This code example shows how to use the following methods:addAll, iterator, size
  public static synchronized void clear() { 
    warnings.clear();
  } 
 
  public static String asString() {
    TreeSet<Warning> T = new TreeSet<Warning>();
    T.addAll(warnings);
    Iterator<Warning> it = T.iterator();
    StringBuffer result = new StringBuffer();
    for (int i = 1; i <= T.size(); i++) {
      result.append(i).append(". ");
      result.append(it.next());
      result.append("\n");
    } 
    return result.toString();
  } 
 
  public static Iterator<Warning> iterator() {
    return warnings.iterator();
  } 
7
CodeRank
This code example shows how to use the following methods:size
 
        stopwatch.reset("Read excludes");
 
        List<File> jarFiles = new ArrayList<File>(500);
        SortedSet<File> excludedDirs = new TreeSet<File>();
        SortedSet<File> sourceRoots = new TreeSet<File>();
 
        traverse(new File("."), sourceRoots, jarFiles, excludedDirs, excludes);
 
        stopwatch.reset("Traversed tree");
 
        Log.debug(sourceRoots.size() + " source roots");
        Log.debug(jarFiles.size() + " jar files");
        Log.debug(excludedDirs.size() + " excluded dirs");
 
        this.sourceRoots = Collections.unmodifiableSortedSet(sourceRoots);
        this.jarFiles = Collections.unmodifiableList(jarFiles);
        this.excludedDirs = Collections.unmodifiableSortedSet(excludedDirs);
    } 
 
7
CodeRank
This code example shows how to use the following methods:
import java.util.TreeSet; 
 
public class MavenProjectsManagerState { 
  public List<String> originalFiles = new ArrayList<String>(); 
 
  public Set<String> ignoredFiles = new TreeSet<String>(); 
  public List<String> ignoredPathMasks = new ArrayList<String>(); 
} 
8
CodeRank
This code example shows how to use the following methods:
		assertThat(sharedPref.getLong("lastUpdated", 0)).isEqualTo(now);
	} 
 
	@Test
	public void putStringSet() { 
		Set<String> values = new TreeSet<String>(Arrays.asList("1", "2", "3"));
		somePrefs.types().put(values);
		assertThat(sharedPref.getStringSet("types", null)).isEqualTo(values);
	} 
 
	@Test
	public void editLong() { 
		long now = System.currentTimeMillis();
 
		somePrefs.edit().lastUpdated().put(now).apply();
 
		assertThat(sharedPref.getLong("lastUpdated", 0)).isEqualTo(now);
	} 
 
	@Test
7
CodeRank
This code example shows how to use the following methods:add, addAll, contains, containsAll
import java.util.Arrays; 
import java.util.Collections; 
import java.util.Set; 
import java.util.TreeSet; 
 
public class Sets { 
    public static void main(String[] args){
        Set<Integer> a = new TreeSet<>();
        //TreeSet sorts on natural ordering (or an optional comparator) 
        //other options: HashSet (hashcode) 
        //               LinkedHashSet (insertion order) 
        //               EnumSet (optimized for enum values) 
        //others at: http://download.oracle.com/javase/7/docs/api/java/util/Set.html 
        Set<Integer> b = new TreeSet<>();
        Set<Integer> c = new TreeSet<>();
        Set<Integer> d = new TreeSet<>();
 
        a.addAll(Arrays.asList(1, 2, 3, 4, 5));
        b.addAll(Arrays.asList(2, 3, 4, 5, 6, 8));
        c.addAll(Arrays.asList(2, 3, 4));

7
CodeRank
This code example shows how to use the following methods:
    @EJB 
    private Registry<String, String> registry; 
 
    @Override 
    public Collection<String> getNodes() { 
        return new TreeSet<>(this.registry.getEntries().keySet()); 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:
		TestBean tbY = new TestBean("nameY", 0);
		this.array = new TestBean[] {tb0, tb1};
		this.list = new ArrayList<Object>();
		this.list.add(tb2);
		this.list.add(tb3);
		this.set = new TreeSet<Object>();
		this.set.add(tb6);
		this.set.add(tb7);
		this.map = new HashMap<Object, Object>();
		this.map.put("key1", tb4);
		this.map.put("key2", tb5);
		this.map.put("key.3", tb5);
		List list = new ArrayList();
		list.add(tbX);
		list.add(tbY);
		this.map.put("key4", list);
	} 
 
 
	public TestBean[] getArray() { 
7
CodeRank
This code example shows how to use the following methods:add
 
	public void testFindCommonEPSGs() { 
		List layers = new ArrayList();
		 
		Layer layer1 = new Layer();
		TreeSet set1 = new TreeSet();
		set1.add("EPSG:4326");
		set1.add("EPSG:3005");
		set1.add("EPSG:42101");
		layer1.setSrs(set1);
		 
		Layer layer2 = new Layer();
		TreeSet set2 = new TreeSet();
		set2.add("EPSG:3005");
		set2.add("EPSG:42101");
		layer2.setSrs(set2);
		 
		Layer layer3 = new Layer();
		TreeSet set3 = new TreeSet();
		set3.add("EPSG:42111");
7
CodeRank
This code example shows how to use the following methods:addAll, isEmpty, remove
   * the servcie. 
   */ 
  public void testEPCISService() throws Exception {
    EPCISServicePortTypeImpl service = new EPCISServicePortTypeImpl();
    ArrayOfString queryNames = service.getQueryNames(new EmptyParms());
    TreeSet<String> names = new TreeSet<String>();
    assertNotNull(queryNames.getString());
    names.addAll(queryNames.getString());
    assertTrue(names.remove("hello"));
    assertTrue(names.remove("how"));
    assertTrue(names.remove("are"));
    assertTrue(names.remove("you?"));
    assertTrue(names.isEmpty());
  } 
 
} 
7
CodeRank
This code example shows how to use the following methods:
 * {@link Node} represents a node in the cluster topology. A node can be a 
 * {@link MachineNode}, or a {@link RackNode}, etc. 
 */ 
public class Node implements Comparable<Node> {
  private static final SortedSet<Node> EMPTY_SET = 
    Collections.unmodifiableSortedSet(new TreeSet<Node>());
  private Node parent;
  private final String name;
  private final int level;
  private SortedSet<Node> children;
 
  /** 
   * @param name 
   *          A unique name to identify a node in the cluster. 
   * @param level 
   *          The level of the node in the cluster 
   */ 
  public Node(String name, int level) {
    if (name == null) {
      throw new IllegalArgumentException("Node name cannot be null");
8
CodeRank
This code example shows how to use the following methods:toString, isEmpty, removeAll
        // this one "seems to mess up offsets". probably shouldn't be a tokenizer... 
        put("wikipedia",     Void.class); 
    }}; 
     
    public void testTokenizers() { 
        Set<String> missing = new TreeSet<String>(org.apache.lucene.analysis.util.TokenizerFactory.availableTokenizers());
        missing.removeAll(KNOWN_TOKENIZERS.keySet());
        assertTrue("new tokenizers found, please update KNOWN_TOKENIZERS: " + missing.toString(), missing.isEmpty());
    } 
     
    static final Map<String,Class<?>> KNOWN_TOKENFILTERS = new HashMap<String,Class<?>>() {{
        // deprecated ones, we dont care about these 
        put("chinese",                Deprecated.class); 
        put("collationkey",           Deprecated.class); 
        put("position",               Deprecated.class); 
        put("thaiword",               Deprecated.class); 
         
         
        // exposed in ES 
        put("apostrophe",                ApostropheFilterFactory.class); 
8
CodeRank
This code example shows how to use the following methods:
    } 
 
    @Test
    public void sortedSetConstructor() 
    { 
        SortedSet<String> setA = new TreeSet<String>(FastList.newListWith("a", "c", "b", "d"));
        Verify.assertSortedSetsEqual(setA, TreeSortedSet.newSet(setA));
        Verify.assertSortedSetsEqual(setA, new TreeSortedSet<String>(setA));
    } 
 
    @Test
    public void iterableConstructor() 
    { 
        LazyIterable<Integer> integerLazyIterable = FastList.newListWith(2, 4, 1, 3).asLazy();
        TreeSortedSet<Integer> sortedSet = TreeSortedSet.newSet(integerLazyIterable);
        Verify.assertSortedSetsEqual(TreeSortedSet.newSetWith(1, 2, 3, 4), sortedSet);
    } 
 
    @Test
    public void serialization() 
7
CodeRank
This code example shows how to use the following methods:
		} 
		else if (List.class.equals(collectionType)) {
			return new ArrayList<Object>(initialCapacity);
		} 
		else if (SortedSet.class.equals(collectionType)) {
			return new TreeSet<Object>();
		} 
		else { 
			return new LinkedHashSet<Object>(initialCapacity);
		} 
	} 
 
	/** 
	 * Return whether to always create a new Collection, 
	 * even if the type of the passed-in Collection already matches. 
	 * <p>Default is "false"; can be overridden to enforce creation of a 
	 * new Collection, for example to convert elements in any case. 
	 * @see #convertElement 
	 */ 
	protected boolean alwaysCreateNewCollection() { 
7
CodeRank
This code example shows how to use the following methods:add
  public void testSimpleQuery5() { 
    LineageInfo lep = new LineageInfo();
    try { 
      lep.getLineageInfo("insert overwrite table x select a.y, b.y " 
          + "from a a full outer join b b on (a.x = b.y)"); 
      TreeSet<String> i = new TreeSet<String>();
      TreeSet<String> o = new TreeSet<String>();
      i.add("a");
      i.add("b");
      o.add("x");
      checkOutput(lep, i, o);
    } catch (Exception e) {
      e.printStackTrace();
      fail("Failed");
    } 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:add
    /** 
     * Test of setFiles method, of class HistoryEntry. 
     */ 
    @Test
    public void setFiles() { 
        TreeSet<String> files = new TreeSet<String>();
        files.add("file1.file");
        files.add("file2.file");
        instance.setFiles(files);
        assertEquals(2, instance.getFiles().size());
    } 
 
    /** 
     * Test of toString method, of class HistoryEntry. 
     */ 
    @Test
    public void testToString() { 
        assertTrue(instance.toString().contains(historyRevision));
        assertTrue(instance.toString().contains(historyAuthor));
    } 
7
CodeRank
This code example shows how to use the following methods:
		if (collectionType.isInterface()) {
			if (List.class.equals(collectionType)) {
				return new ArrayList<E>(initialCapacity);
			} 
			else if (SortedSet.class.equals(collectionType) || NavigableSet.class.equals(collectionType)) {
				return new TreeSet<E>();
			} 
			else if (Set.class.equals(collectionType) || Collection.class.equals(collectionType)) {
				return new LinkedHashSet<E>(initialCapacity);
			} 
			else { 
				throw new IllegalArgumentException("Unsupported Collection interface: " + collectionType.getName());
			} 
		} 
		else { 
			if (!Collection.class.isAssignableFrom(collectionType)) {
				throw new IllegalArgumentException("Unsupported Collection type: " + collectionType.getName());
			} 
			try { 
				return (Collection<E>) collectionType.newInstance();
7
CodeRank
This code example shows how to use the following methods:
  /** 
   * 
   */ 
  void addChild(Queue child) {
    if(children == null) {
      children = new TreeSet<Queue>();
    } 
 
    children.add(child);
  } 
 
  /** 
   * 
   * @return 
   */ 
  Set<Queue> getChildren() {
    return children;
  } 
 
  /** 
7
CodeRank
This code example shows how to use the following methods:add
 
	public void testFindCommonEPSGs() { 
		List layers = new ArrayList();
		 
		Layer layer1 = new Layer();
		TreeSet set1 = new TreeSet();
		set1.add("EPSG:4326");
		set1.add("EPSG:3005");
		set1.add("EPSG:42101");
		layer1.setSrs(set1);
		 
		Layer layer2 = new Layer();
		TreeSet set2 = new TreeSet();
		set2.add("EPSG:3005");
		set2.add("EPSG:42101");
		layer2.setSrs(set2);
		 
		Layer layer3 = new Layer();
		TreeSet set3 = new TreeSet();
		set3.add("EPSG:42111");
7
CodeRank
This code example shows how to use the following methods:add
    @Override 
    public void runTest() { 
        new Support_UnmodifiableCollectionTest("", col).runTest();
 
        // setup 
        Collection<Integer> myCollection = new TreeSet<Integer>();
        myCollection.add(new Integer(101));
        myCollection.add(new Integer(102));
        myCollection.add(new Integer(103));
 
        // add 
        assertTrue("CollectionTest - a) add did not work", col.add(new Integer(
                101))); 
        assertTrue("CollectionTest - b) add did not work", col
                .contains(new Integer(101)));
 
        // remove 
        assertTrue("CollectionTest - a) remove did not work", col
                .remove(new Integer(101)));
        assertTrue("CollectionTest - b) remove did not work", !col

7
CodeRank
This code example shows how to use the following methods:
		} 
		else if (List.class.equals(collectionClass)) {
			return (T) new ArrayList();
		} 
		else if (SortedSet.class.equals(collectionClass)) {
			return (T) new TreeSet();
		} 
		else { 
			return (T) new LinkedHashSet();
		} 
	} 
 
	private int moveToFirstChildOfRootElement(XMLStreamReader streamReader) throws XMLStreamException {
		// root 
		int event = streamReader.next();
		while (event != XMLStreamReader.START_ELEMENT) {
			event = streamReader.next();
		} 
 
		// first child 
7
CodeRank

Related Java 8 TreeSet Questions & Answers:

See Code Examples for Java 8 TreeSet Methods: