Java TreeSet createTreeSet(Iterable c)

Here you can find the source of createTreeSet(Iterable c)

Description

create Tree Set

License

Open Source License

Declaration

public static <T> TreeSet<T> createTreeSet(Iterable<? extends T> c) 

Method Source Code

//package com.java2s;

import java.util.Collection;

import java.util.Comparator;

import java.util.SortedSet;

import java.util.TreeSet;

public class Main {

    public static <T> TreeSet<T> createTreeSet() {
        return new TreeSet<T>();
    }//from   w  w w.j a va  2 s  . com

    @SuppressWarnings("unchecked")
    public static <T, V extends T> TreeSet<T> createTreeSet(V... args) {
        return (TreeSet<T>) createTreeSet(null, args);
    }

    public static <T> TreeSet<T> createTreeSet(Iterable<? extends T> c) {
        return createTreeSet(null, c);
    }

    public static <T> TreeSet<T> createTreeSet(Comparator<? super T> comparator) {
        return new TreeSet<T>(comparator);
    }

    public static <T, V extends T> TreeSet<T> createTreeSet(Comparator<? super T> comparator, V... args) {
        TreeSet<T> set = new TreeSet<T>(comparator);

        if (args != null) {
            for (V v : args) {
                set.add(v);
            }
        }

        return set;
    }

    public static <T> TreeSet<T> createTreeSet(Comparator<? super T> comparator, Iterable<? extends T> c) {
        TreeSet<T> set = new TreeSet<T>(comparator);

        iterableToCollection(c, set);

        return set;
    }

    public static <E> TreeSet<E> createTreeSet(SortedSet<E> set) {
        if (set == null) {
            return new TreeSet<E>();
        }

        return new TreeSet<E>(set);
    }

    private static <E> void iterableToCollection(Iterable<? extends E> iter, Collection<E> list) {
        if (iter == null) {
            return;
        }

        for (E element : iter) {
            list.add(element);
        }
    }
}

Related

  1. addSplits(TreeSet splitKeys, byte[] prefix, int splitBits)
  2. buildTreeSet(Collection elements)
  3. changeComparator(TreeSet set, Comparator cmp)
  4. concatenate(TreeSet in)
  5. convertSpanToSparseGrid(final int curIx, final int span, final TreeSet indexes)
  6. cvtListToTreeSet(List list)
  7. findSizedSubdirs(final String size, final TreeSet themeSubdirs)
  8. getDockInsets(final TreeSet set)
  9. getTreeSet(Collection collection)