Example usage for java.util TreeSet TreeSet

List of usage examples for java.util TreeSet TreeSet

Introduction

In this page you can find the example usage for java.util TreeSet TreeSet.

Prototype

public TreeSet() 

Source Link

Document

Constructs a new, empty tree set, sorted according to the natural ordering of its elements.

Usage

From source file:Main.java

public static <E> Set<E> treeSet(E... add) {
    Set<E> result = new TreeSet<>();
    if (add != null) {
        result.addAll(Arrays.asList(add));
    }//  w w w  . j av  a2  s.c om
    return result;
}

From source file:org.openmrs.module.pagecheck.Pages.java

/**
 * Gets all URLs which have been mapped to controllers in Spring
 * @return the URLs/*from   w w  w  . j  a va2s .  c o m*/
 */
@SuppressWarnings("unchecked")
public static Set<String> getMappedURLs() {
    Set<String> urls = new TreeSet<String>();

    Map<String, SimpleUrlHandlerMapping> simpleHandlers = ContextProvider.getApplicationContext()
            .getBeansOfType(SimpleUrlHandlerMapping.class);
    Map<String, DefaultAnnotationHandlerMapping> annotationBeans = ContextProvider.getApplicationContext()
            .getBeansOfType(DefaultAnnotationHandlerMapping.class);

    for (SimpleUrlHandlerMapping handler : simpleHandlers.values())
        urls.addAll(handler.getHandlerMap().keySet());

    for (DefaultAnnotationHandlerMapping handler : annotationBeans.values())
        urls.addAll(handler.getHandlerMap().keySet());

    return urls;
}

From source file:Main.java

/**
 * Create and answer a collection that is the same type, or the closest
 * equivalent of col.//from  ww w.  jav a 2  s  .c om
 * 
 * @param col
 * @return
 */
public static Collection createCollection(Collection col) {
    Collection answer;
    try {
        answer = (Collection) col.getClass().newInstance();
    } catch (Exception e) {
        if (col instanceof List) {
            answer = new ArrayList();
        } else if (col instanceof SortedSet) {
            answer = new TreeSet();
        } else if (col instanceof Set) {
            answer = new HashSet();
        } else {
            answer = new ArrayList(); // should this throw an exception?
        }
    }
    return answer;
}

From source file:Main.java

public static <E> Set<E> treeSet(Set<E> base, E... add) {
    Set<E> result = new TreeSet<>();
    result.addAll(base);//from  w ww .j a  va 2  s .c  om
    if (add != null) {
        result.addAll(Arrays.asList(add));
    }
    return result;
}

From source file:org.springmodules.util.Strings.java

/**
 * Removes duplicates from the given String array.
 * /*from w w  w  .  j ava2 s  .c o m*/
 * @param array
 *          the given array
 * @return a new String array without duplicated entries
 */
public static String[] removeDuplicates(String[] array) {
    if (ObjectUtils.isEmpty(array)) {
        return array;
    }
    Set set = new TreeSet();

    int arraySize = array.length;
    for (int i = 0; i < arraySize; i++) {
        set.add(array[i]);
    }
    return (String[]) set.toArray(new String[set.size()]);
}

From source file:Main.java

public static <K, V> SortedSet<V> getEntryOrEmptySet(K key, Map<K, SortedSet<V>> map) {
    return (map.containsKey(key) ? map.get(key) : new TreeSet<V>());
}

From source file:Main.java

public static <E> TreeSet<E> createTreeSet(SortedSet<E> set) {
    if (set == null) {
        return new TreeSet<E>();
    }//w  w w  .  j a  v  a 2  s.com

    return new TreeSet<E>(set);
}

From source file:edu.temple.cis3238.wiki.utils.CollectionsUtilities.java

/**
 * Creates a Set of value for Tag Column
 * @param voList//from  w  w  w. ja va2s .co  m
 * @param column
 * @return 
 */
public static Set<String> pluckList(ArrayList<TagsVO> voList, String column) {
    Set<String> result = new TreeSet<String>();
    for (TagsVO element : voList) {
        TagsVO vo = (TagsVO) element;
        String v;
        IPluck<TagsVO, String> transformer;
        transformer = new TagColumnPredicate(vo, column, true);
        v = transformer.pluck(vo, column);

        if (v != null) {
            result.add(v);
        }
    }
    return result;
}

From source file:de.vandermeer.skb.interfaces.application.CliOptionList.java

/**
 * Returns all required options, taking short or long CLI argument.
 * @param list input option list/*from www.j  a  v  a  2s.c o  m*/
 * @return all required options
 */
static Set<String> getRequired(Set<ApoBaseC> list) {
    Set<String> ret = new TreeSet<>();
    if (list != null) {
        for (ApoBaseC opt : list) {
            if (opt.cliIsRequired()) {
                String required = (opt.getCliShortLong() == null) ? "--" + opt.getCliLong()
                        : "-" + opt.getCliShort();
                if (ClassUtils.isAssignable(opt.getClass(), Apo_TypedC.class)) {
                    required += " <" + ((Apo_TypedC<?>) opt).getCliArgumentName() + ">";
                }
                ret.add(required);
            }
        }
    }
    return ret;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static Collection<Object> newCollection(Class<?> targetClass, int length)
        throws InstantiationException, IllegalAccessException {

    if (targetClass.isInterface()) {

        if (Set.class.isAssignableFrom(targetClass)) {
            if (SortedSet.class.isAssignableFrom(targetClass))
                return new TreeSet<Object>();
            return new HashSet<Object>(length);
        }//from   w  ww .j  a va 2s.  co m

        if (targetClass.isAssignableFrom(ArrayList.class))
            return new ArrayList<Object>(length);

        throw new IllegalArgumentException("Unsupported collection interface: " + targetClass);
    }

    return (Collection<Object>) targetClass.newInstance();
}