/** * Copyright (C) 2007 Google Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */importjava.util.Collections;importjava.util.HashSet;importjava.util.Set; /** * Helper methods related to {@link Set}s. * * @author maxr@google.com (Max Ross) */publicclassSets {privateSets() {} /** * Construct a new {@link HashSet}, taking advantage of type inference to * avoid specifying the type on the rhs. */publicstatic<E> HashSet<E> newHashSet() {returnnewHashSet<E>(); } /** * Construct a new {@link HashSet} with the provided elements, taking advantage of type inference to * avoid specifying the type on the rhs. */publicstatic<E> HashSet<E> newHashSet(E... elements) { HashSet<E> set = newHashSet(); Collections.addAll(set, elements);returnset; } /** * Construct a new {@link HashSet} with the contents of the provided {@link Iterable}, taking advantage of type inference to * avoid specifying the type on the rhs. */publicstatic<E> HashSet<E> newHashSet(Iterable<?extendsE> elements) { HashSet<E> set = newHashSet();for(E e : elements) { set.add(e); }returnset; } }

java2s.com | Email:info at java2s.com | © Demo Source and Support. All rights reserved.