IdentityList is an implementation of the List Interface that uses Identity (==) rather than equality (.equals() ) to establish behavior for remove. This is useful to maintain an input ordered identity list (not possible with IdentityHashMap because it does not maintain input order). @param
| 36 | * The type of object stored in this IdentityList |
| 37 | */ |
| 38 | @SuppressWarnings("PMD.TooManyMethods") |
| 39 | public class IdentityList<T> implements List<T> |
| 40 | { |
| 41 | /** |
| 42 | * The underlying map providing storage of Identity structures. |
| 43 | */ |
| 44 | private final List<Identity<T>> embeddedList = |
| 45 | new LinkedList<>(); |
| 46 | |
| 47 | /** |
| 48 | * Creates a new (empty) IdentityList. |
| 49 | */ |
| 50 | public IdentityList() |
| 51 | { |
| 52 | super(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Creates a new IdentityList which will be initialized with the contents |
| 57 | * of the given List. |
| 58 | * |
| 59 | * @param list |
| 60 | * The list of objects used to initialize the contents of this |
| 61 | * IdentityList |
| 62 | */ |
| 63 | public IdentityList(List<T> list) |
| 64 | { |
| 65 | addAll(list); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void add(int index, T element) |
| 70 | { |
| 71 | embeddedList.add(index, Identity.valueOf(element)); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public final boolean add(T element) |
| 76 | { |
| 77 | return embeddedList.add(Identity.valueOf(element)); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public final boolean addAll(Collection<? extends T> collection) |
| 82 | { |
| 83 | collection.forEach(this::add); |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public boolean addAll(int index, Collection<? extends T> collection) |
| 89 | { |
| 90 | int location = index; |
| 91 | for (T element : collection) |
| 92 | { |
| 93 | add(location++, element); |
| 94 | } |
| 95 | return true; |
nothing calls this directly
no outgoing calls
no test coverage detected