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