001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2014-2015 ForgeRock AS.
015 */
016package org.opends.server.util;
017
018import java.util.*;
019
020/**
021 * Utility class for {@link Collection}s.
022 */
023public final class CollectionUtils
024{
025
026  private CollectionUtils()
027  {
028    // private for utility classes
029  }
030
031  /**
032   * Creates a new {@link ArrayList} with the provided elements.
033   *
034   * @param <E>
035   *          the elements' type
036   * @param elements
037   *          the elements to add to the new ArrayList
038   * @return a new ArrayList with the provided elements
039   */
040  public static <E> ArrayList<E> newArrayList(E... elements)
041  {
042    return new ArrayList<>(Arrays.asList(elements));
043  }
044
045  /**
046   * Creates a new {@link LinkedList} with the provided elements.
047   *
048   * @param <E>
049   *          the elements' type
050   * @param elements
051   *          the elements to add to the new LinkedList
052   * @return a new LinkedList with the provided elements
053   */
054  public static <E> LinkedList<E> newLinkedList(E... elements)
055  {
056    return new LinkedList<>(Arrays.asList(elements));
057  }
058
059  /**
060   * Creates a new {@link HashSet} with the provided elements.
061   *
062   * @param <E>
063   *          the elements' type
064   * @param elements
065   *          the elements to add to the new HashSet
066   * @return a new HashSet with the provided elements
067   */
068  public static <E> HashSet<E> newHashSet(E... elements)
069  {
070    return new HashSet<>(Arrays.asList(elements));
071  }
072
073  /**
074   * Creates a new {@link LinkedHashSet} with the provided elements.
075   *
076   * @param <E>
077   *          the elements' type
078   * @param elements
079   *          the elements to add to the new LinkedHashSet
080   * @return a new LinkedHashSet with the provided elements
081   */
082  public static <E> LinkedHashSet<E> newLinkedHashSet(E... elements)
083  {
084    return new LinkedHashSet<>(Arrays.asList(elements));
085  }
086
087  /**
088   * Creates a new {@link TreeSet} with the provided elements.
089   *
090   * @param <E>
091   *          the elements' type
092   * @param elements
093   *          the elements to add to the new TreeSet
094   * @return a new TreeSet with the provided elements
095   */
096  public static <E> TreeSet<E> newTreeSet(E... elements)
097  {
098    return new TreeSet<>(Arrays.asList(elements));
099  }
100}