Java Collection Copy copy(final Collection in)

Here you can find the source of copy(final Collection in)

Description

copy

License

Apache License

Declaration

private static List<String> copy(final Collection<String> in) 

Method Source Code


//package com.java2s;
/*//from ww  w . j  ava  2  s.c  om
Copyright 2012 Mikael Gueck
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
  http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import static java.util.Collections.*;
import java.util.*;

public class Main {
    private static List<String> copy(final Collection<String> in) {
        return unmodifiableList(new ArrayList<String>(in));
    }

    /** Deep copy, with immutable values. */
    static Map<String, List<String>> copy(final Map<String, List<String>> in) {
        final Map<String, List<String>> ret = newMap();
        for (final Map.Entry<String, List<String>> e : in.entrySet()) {
            ret.put(e.getKey(), unmodifiableList(new ArrayList<String>(e.getValue())));
        }
        return unmodifiableMap(ret);
    }

    private static Map<String, List<String>> newMap() {
        return new HashMap<String, List<String>>();
    }
}

Related

  1. copy(Collection args)
  2. copy(Collection collection)
  3. copy(final Collection collection)
  4. copy(final Collection collection)
  5. copy2Collection(Object[] strs)
  6. copyColl(Collection out, Iterable set)