Java Utililty Methods SortedSet

List of utility methods to do SortedSet

Description

The list of methods to do SortedSet are organized into topic(s).

Method

voidaddMapEntry(Map> map, T1 keyEntry, T2 setEntry)
add Map Entry
if (map.containsKey(keyEntry)) {
    map.get(keyEntry).add(setEntry);
} else {
    SortedSet<T2> newSet = new TreeSet<T2>();
    newSet.add(setEntry);
    map.put(keyEntry, newSet);
StringarrayToSortedStringSet(Collection strings)
array To Sorted String Set
Set<String> sorter = new TreeSet<String>();
sorter.addAll(strings);
return arrayToString(sorter);
SortedSetasSortedSet(T... args)
as Sorted Set
SortedSet<T> result = new TreeSet<T>();
if (args != null) {
    for (T arg : args) {
        if (arg != null) {
            result.add(arg);
return result;
SortedSetasSortedSet(T... elements)
Converts the given array of elements to a sortedset.
SortedSet<T> result = new TreeSet<T>();
if (elements == null) {
    return result;
result.addAll(asList(elements));
return result;
List>>computeGraphCauselessFromGraphLmms( List>>> causesByDepByNameList)
Removes the causes.
final List<SortedMap<String, SortedSet<String>>> reduced = new ArrayList<SortedMap<String, SortedSet<String>>>();
for (SortedMap<String, SortedMap<String, SortedSet<String>>> causesByDepByName : causesByDepByNameList) {
    final SortedMap<String, SortedSet<String>> withoutCausesMap = computeGraphCauselessFromGraphMms(
            causesByDepByName);
    reduced.add(withoutCausesMap);
return reduced;
SortedMap>computeGraphCauselessFromGraphMms( SortedMap>> causesByDepByName)
Removes the causes.
final SortedMap<String, SortedSet<String>> reduced = new TreeMap<String, SortedSet<String>>();
for (Map.Entry<String, SortedMap<String, SortedSet<String>>> entry : causesByDepByName.entrySet()) {
    final String name = entry.getKey();
    final SortedMap<String, SortedSet<String>> causesByDep = entry.getValue();
    final SortedSet<String> deps = new TreeSet<String>(causesByDep.keySet());
    final Object forCheck = reduced.put(name, deps);
    if (forCheck != null) {
        throw new AssertionError();
...
SortedSetcopyAndClearSet(SortedSet sourceSet)
Copy items from source to target set; then clear source set and set it to null
TreeSet<String> newSet = null;
if (sourceSet != null) {
    newSet = new TreeSet<String>();
    Iterator<String> iter = sourceSet.iterator();
    while (iter.hasNext()) {
        String oldKey = iter.next();
        String key = new String(oldKey);
        newSet.add(key);
...
SortedSetdoubleForDescreteStartAndEnds(SortedSet hours)
Do a doubling that creates a set of times where start and end times become distinct even/odd entities in the set.
TreeSet retval = new TreeSet();
if (hours.isEmpty()) {
    return (retval);
Iterator vit = hours.iterator();
while (vit.hasNext()) {
    Integer time = (Integer) vit.next();
    int start = time.intValue() * 2;
...
SortedSet>entriesSortedByValues( Map map)
entries Sorted By Values
SortedSet<Map.Entry<K, V>> sortedEntries = new TreeSet<Map.Entry<K, V>>(new Comparator<Map.Entry<K, V>>() {
    @Override
    public int compare(Map.Entry<K, V> e1, Map.Entry<K, V> e2) {
        return e1.getValue().compareTo(e2.getValue());
});
sortedEntries.addAll(map.entrySet());
return sortedEntries;
...
SortedSetfillOutHourly(SortedSet hours)
Fill the set of hours to be hourly
TreeSet retval = new TreeSet(hours);
if (hours.isEmpty() || (hours.size() == 1)) {
    return (retval);
int minTime = ((Integer) hours.first()).intValue() + 1;
int maxTime = ((Integer) hours.last()).intValue() - 1;
for (int i = minTime; i <= maxTime; i++) {
    retval.add(new Integer(i));
...