001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.internal;
014
015import java.util.*;
016
017/**
018 * Combination of a {@link LinkedList} and <code>IdentitySet</code>.
019 *
020 * <ul class='spaced-list'>
021 *    <li>
022 *       Duplicate objects (by identity) will be skipped during insertion.
023 *    <li>
024 *       Order of insertion maintained.
025 * </ul>
026 *
027 * <h5 class='section'>Notes:</h5>
028 * <ul class='spaced-list'>
029 *    <li>
030 *       This class is NOT thread safe, and is intended for use on small lists.
031 * </ul>
032 *
033 * @param <T> Entry type.
034 */
035public class IdentityList<T> extends LinkedList<T> {
036
037   private static final long serialVersionUID = 1L;
038
039   @Override /* List */
040   public boolean add(T t) {
041      for (T t2 : this)
042         if (t2 == t)
043            return false;
044      super.add(t);
045      return true;
046   }
047
048   @Override /* List */
049   public boolean contains(Object t) {
050      for (T t2 : this)
051         if (t2 == t)
052            return true;
053      return false;
054   }
055}