Example usage for java.util SortedSet addAll

List of usage examples for java.util SortedSet addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:Main.java

public static void main(String[] args) {
    Comparator<String> ipComparator = new Comparator<String>() {
        @Override//from   w  ww. j a  va  2  s  .c om
        public int compare(String ip1, String ip2) {
            return toNumeric(ip1).compareTo(toNumeric(ip2));
        }
    };
    SortedSet<String> ips = new TreeSet<String>(ipComparator);
    ips.addAll(Arrays.asList("192.168.0.1", "192.168.0.2", "192.168.0.9", "9.9.9.9", "127.0.0.1"));
    System.out.println(ips);
}

From source file:TreeSetTest.java

public static void main(String[] args) {
    SortedSet<Item> parts = new TreeSet<Item>();
    parts.add(new Item("Toaster", 1234));
    parts.add(new Item("Widget", 4562));
    parts.add(new Item("Modem", 9912));
    System.out.println(parts);//from   www.j a v  a2  s . c o  m

    SortedSet<Item> sortByDescription = new TreeSet<Item>(new Comparator<Item>() {
        public int compare(Item a, Item b) {
            String descrA = a.getDescription();
            String descrB = b.getDescription();
            return descrA.compareTo(descrB);
        }
    });

    sortByDescription.addAll(parts);
    System.out.println(sortByDescription);
}

From source file:Main.java

/**
 * Constructs the sorted union of two sets
 * @param a//from   w w w  . jav  a  2 s .c  om
 * @param b
 * @return the sorted union
 */
public static <T> SortedSet<T> sortedUnion(Set<T> a, Set<T> b) {
    SortedSet<T> retVal = new TreeSet<T>(a);
    retVal.addAll(b);
    return retVal;
}

From source file:Main.java

public static List sortedUnion(List args1, List args2) {
    SortedSet set = new TreeSet();
    set.addAll(args1);
    set.addAll(args2);//from   w ww .j a  v  a2  s .c  om

    List lst = new ArrayList(set.size());
    for (Iterator it = set.iterator(); it.hasNext();) {
        Object o = it.next();
        lst.add(o);
    }

    return lst;
}

From source file:Main.java

public static <T> SortedSet<T> unionSortedSet(Set<T>... sets) {
    SortedSet<T> unionSet = new TreeSet<T>();
    for (Set<T> set : sets) {
        unionSet.addAll(set);
    }// w ww.  ja v  a  2s. c o m
    return unionSet;
}

From source file:Main.java

/**
 * Converts the given array of elements to a sortedset.
 *
 * @param elements The elements/*  ww w  . java  2  s .c  o m*/
 * @return The elements as a set, empty if elements was null
 */
public static <T> SortedSet<T> asSortedSet(T... elements) {
    SortedSet<T> result = new TreeSet<T>();
    if (elements == null) {
        return result;
    }
    result.addAll(asList(elements));
    return result;
}

From source file:Main.java

public static <T> SortedSet<T> updateMovieListIfNeeded(SortedSet<T> queryResult, SortedSet<T> orderedMovies,
        int nbResultsMax) {
    // add incoming to existing list - order ensure by TreeSet
    queryResult.addAll(orderedMovies);
    // keep only the "top of list", cap by the query spec
    return queryResult;
}

From source file:com.incapture.rapgen.output.OutputWriter.java

/**
 * Some files are composed of multiple templates. So the map passed in here is filename to template order to template.
 * E.g. "file.txt"->1->"some code" "file.txt"->2->"other code" and so on.
 *
 * @param rootFolder//  ww w  .  j  ava 2  s  .  c  o m
 * @param pathToTemplate
 */
public static void writeMultiPartTemplates(String rootFolder,
        Map<String, Map<String, StringTemplate>> pathToTemplate) {
    // For each file, dump the templates
    for (Map.Entry<String, Map<String, StringTemplate>> entry : pathToTemplate.entrySet()) {
        File file = new File(rootFolder, entry.getKey());
        file.getParentFile().mkdirs();

        BufferedWriter bow = null;
        try {
            bow = new BufferedWriter(new FileWriter(file));
            Set<String> sections = entry.getValue().keySet();
            SortedSet<String> sorted = new TreeSet<String>();
            sorted.addAll(sections);
            for (String sec : sorted) {
                bow.write(entry.getValue().get(sec).toString());
                bow.newLine();
            }
            bow.close();
        } catch (IOException e) {
            System.err.println(e.getMessage());
        } finally {
            if (bow != null) {
                try {
                    bow.close();
                } catch (IOException e) {
                    System.err.println("Error closing output stream: " + ExceptionToString.format(e));
                }
            }
        }
    }
}

From source file:Main.java

public static <K, V extends Comparable<? super V>> SortedSet<Map.Entry<K, V>> sortByValues(Map<K, V> map) {
    SortedSet<Map.Entry<K, V>> sortedEntries = new TreeSet<>((e1, e2) -> {
        int res = e1.getValue().compareTo(e2.getValue());
        return res != 0 ? res : 1;
    });//from   w ww .java2s .c  o m
    sortedEntries.addAll(map.entrySet());
    return sortedEntries;
}

From source file:com.rapleaf.hank.coordinator.Domains.java

public static DomainVersion getLatestVersionNotOpenNotDefunct(Domain domain) throws IOException {
    Set<DomainVersion> originalVersions = domain.getVersions();
    if (originalVersions == null || originalVersions.size() == 0) {
        return null;
    }/*w w  w  . j  av a2  s  .  c om*/
    SortedSet<DomainVersion> versions = new TreeSet<DomainVersion>(new ReverseComparator<DomainVersion>());
    versions.addAll(originalVersions);
    for (DomainVersion version : versions) {
        if (DomainVersions.isClosed(version) && !version.isDefunct()) {
            return version;
        }
    }
    return null;
}