@author zsombor
| 15 | * |
| 16 | */ |
| 17 | public abstract class AbstractCollection<T> implements Collection<T> { |
| 18 | public boolean add(T element) { |
| 19 | throw new UnsupportedOperationException("adding to " |
| 20 | + this.getClass().getName()); |
| 21 | } |
| 22 | |
| 23 | public boolean addAll(Collection<? extends T> collection) { |
| 24 | boolean result = false; |
| 25 | for (T obj : collection) { |
| 26 | result |= add(obj); |
| 27 | } |
| 28 | return result; |
| 29 | } |
| 30 | |
| 31 | public void clear() { |
| 32 | throw new UnsupportedOperationException("clear() in " |
| 33 | + this.getClass().getName()); |
| 34 | } |
| 35 | |
| 36 | public boolean contains(Object element) { |
| 37 | if (element != null) { |
| 38 | for (Iterator<T> iter = iterator(); iter.hasNext();) { |
| 39 | if (element.equals(iter.next())) { |
| 40 | return true; |
| 41 | } |
| 42 | } |
| 43 | } else { |
| 44 | for (Iterator<T> iter = iterator(); iter.hasNext();) { |
| 45 | if (iter.next()==null) { |
| 46 | return true; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | } |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | public boolean containsAll(Collection<?> c) { |
| 55 | if (c == null) { |
| 56 | throw new NullPointerException("Collection is null"); |
| 57 | } |
| 58 | |
| 59 | Iterator<?> it = c.iterator(); |
| 60 | while (it.hasNext()) { |
| 61 | if (! contains(it.next())) { |
| 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | public boolean isEmpty() { |
| 70 | return size() == 0; |
| 71 | } |
| 72 | |
| 73 | public boolean remove(Object element) { |
| 74 | throw new UnsupportedOperationException("remove(T) in " |
nothing calls this directly
no outgoing calls
no test coverage detected