Java SortedSet copyAndClearSet(SortedSet sourceSet)

Here you can find the source of copyAndClearSet(SortedSet sourceSet)

Description

Copy items from source to target set; then clear source set and set it to null

License

Open Source License

Parameter

Parameter Description
sourceSet set to be copied

Return

deep copy of set

Declaration

public static SortedSet<String> copyAndClearSet(SortedSet<String> sourceSet) 

Method Source Code

//package com.java2s;

import java.util.Iterator;

import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
    /**//from  ww  w .  j ava 2s  .c  o m
     *  Copy items from source to target set; then clear source set and set it to null
     * @param sourceSet set to be copied
     * @return deep copy of set
     */
    public static SortedSet<String> copyAndClearSet(SortedSet<String> sourceSet) {
        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);
                oldKey = null;
            }
            for (String copyKey : newSet) {
                sourceSet.remove(copyKey);
            }
        }
        return newSet;
    }
}

Related

  1. arrayToSortedStringSet(Collection strings)
  2. asSortedSet(T... args)
  3. asSortedSet(T... elements)
  4. computeGraphCauselessFromGraphLmms( List>>> causesByDepByNameList)
  5. computeGraphCauselessFromGraphMms( SortedMap>> causesByDepByName)
  6. doubleForDescreteStartAndEnds(SortedSet hours)
  7. entriesSortedByValues( Map map)
  8. fillOutHourly(SortedSet hours)
  9. getEntryOrEmptySet(K key, Map> map)