Java Set Create asSet(final T t, final T... ts)

Here you can find the source of asSet(final T t, final T... ts)

Description

as Set

License

Open Source License

Declaration

public static <T> Set<T> asSet(final T t, final T... ts) 

Method Source Code

//package com.java2s;
/*/*from w w  w  . j  a  va 2 s  . c om*/
 * Copyright (C) 2013
 *
 * 52?North Initiative for Geospatial Open Source Software GmbH
 * Contact: Andreas Wytzisk
 * Martin-Luther-King-Weg 24
 * 48155 Muenster, Germany
 * info@52north.org
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.Collection;
import java.util.Collections;

import java.util.HashSet;

import java.util.Set;

public class Main {
    public static <T> Set<T> asSet(final Iterable<? extends T> iterable) {
        return (iterable instanceof Collection) ? new HashSet<T>((Collection<? extends T>) iterable)
                : new HashSet<T>() {
                    private static final long serialVersionUID = 3109256773218160485L;
                    {
                        if (iterable != null) {
                            for (final T t : iterable) {
                                add(t);
                            }
                        }
                    }
                };
    }

    public static <T> Set<T> asSet(final T t, final T... ts) {
        final Set<T> set = new HashSet<T>(ts.length + 1);
        set.add(t);
        Collections.addAll(set, ts);
        return set;
    }
}

Related

  1. asSet(Collection c)
  2. asSet(Collection c)
  3. asSet(E... elements)
  4. asSet(E... pEntities)
  5. asSet(final E... elements)
  6. asSet(final T... array)
  7. asSet(int... values)
  8. asSet(Iterable iteratable)
  9. asSet(K... values)