|
| 1 | +/* |
| 2 | + * |
| 3 | + * * Copyright (c) 2016. David Sowerby |
| 4 | + * * |
| 5 | + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 6 | + * * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * * |
| 8 | + * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 9 | + * * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | + * * specific language governing permissions and limitations under the License. |
| 11 | + * |
| 12 | + */ |
| 13 | + |
| 14 | +package uk.q3c.util.collection; |
| 15 | + |
| 16 | +import com.google.common.collect.ImmutableList; |
| 17 | +import org.apache.commons.collections4.ListUtils; |
| 18 | + |
| 19 | +import java.io.Serializable; |
| 20 | +import java.lang.annotation.Annotation; |
| 21 | +import java.util.List; |
| 22 | +import java.util.Set; |
| 23 | + |
| 24 | + |
| 25 | +/** |
| 26 | + * The syntax of getting the Generics right to create a list of Class<? extends Annotation> is clumsy and prone to errors - this class just makes it clearer and |
| 27 | + * simpler |
| 28 | + * <p> |
| 29 | + * Created by David Sowerby on 07/08/15. |
| 30 | + */ |
| 31 | +public class AnnotationList implements Serializable { |
| 32 | + |
| 33 | + protected final ImmutableList<Class<? extends Annotation>> list; |
| 34 | + |
| 35 | + /** |
| 36 | + * Construct with List containing required values - may be empty |
| 37 | + * |
| 38 | + * @param list containing required values - may be empty |
| 39 | + */ |
| 40 | + public AnnotationList(List<Class<? extends Annotation>> list) { |
| 41 | + super(); |
| 42 | + this.list = ImmutableList.copyOf(list); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Construct with elements containing required values - may be empty |
| 47 | + * |
| 48 | + * @param elements containing required values - may be empty |
| 49 | + */ |
| 50 | + @SafeVarargs |
| 51 | + public AnnotationList(Class<? extends Annotation>... elements) { |
| 52 | + super(); |
| 53 | + this.list = (elements == null) ? ImmutableList.of() : ImmutableList.copyOf(elements); |
| 54 | + } |
| 55 | + |
| 56 | + public AnnotationList(Set<? extends Class<? extends Annotation>> set) { |
| 57 | + this.list = ImmutableList.copyOf(set); |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + public ImmutableList<Class<? extends Annotation>> getList() { |
| 62 | + return list; |
| 63 | + } |
| 64 | + |
| 65 | + public int size() { |
| 66 | + return list.size(); |
| 67 | + } |
| 68 | + |
| 69 | + |
| 70 | + public boolean isEmpty() { |
| 71 | + return list.isEmpty(); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public boolean equals(Object o) { |
| 76 | + if (this == o) return true; |
| 77 | + if (o == null || getClass() != o.getClass()) return false; |
| 78 | + |
| 79 | + AnnotationList that = (AnnotationList) o; |
| 80 | + |
| 81 | + return ListUtils.isEqualList(this.list, that.list); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public int hashCode() { |
| 86 | + return list.hashCode(); |
| 87 | + } |
| 88 | +} |
0 commit comments