Initial code drop
[bgpcep.git] / util / src / main / java / org / opendaylight / protocol / util / RemoveOnlySet.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.util;
9
10 import java.util.Collection;
11 import java.util.Iterator;
12 import java.util.Set;
13
14 public class RemoveOnlySet<E> implements Set<E> {
15         private final Set<E> set;
16
17         public RemoveOnlySet(final Set<E> set) {
18                 this.set = set;
19         }
20
21         public static <T> RemoveOnlySet<T> wrap(final Set<T> set) {
22                 return new RemoveOnlySet<T>(set);
23         }
24
25         @Override
26         public boolean add(final E e) {
27                 throw new UnsupportedOperationException("Set does not accept additions");
28         }
29
30         @Override
31         public boolean addAll(final Collection<? extends E> c) {
32                 throw new UnsupportedOperationException("Set does not accept additions");
33         }
34
35         @Override
36         public void clear() {
37                 set.clear();
38         }
39
40         @Override
41         public boolean contains(final Object o) {
42                 return set.contains(o);
43         }
44
45         @Override
46         public boolean containsAll(final Collection<?> c) {
47                 return set.containsAll(c);
48         }
49
50         @Override
51         public boolean isEmpty() {
52                 return set.isEmpty();
53         }
54
55         @Override
56         public Iterator<E> iterator() {
57                 return set.iterator();
58         }
59
60         @Override
61         public boolean remove(final Object o) {
62                 return set.remove(o);
63         }
64
65         @Override
66         public boolean removeAll(final Collection<?> c) {
67                 return set.removeAll(c);
68         }
69
70         @Override
71         public boolean retainAll(final Collection<?> c) {
72                 return set.retainAll(c);
73         }
74
75         @Override
76         public int size() {
77                 return set.size();
78         }
79
80         @Override
81         public Object[] toArray() {
82                 return set.toArray();
83         }
84
85         @Override
86         public <T> T[] toArray(final T[] a) {
87                 return set.toArray(a);
88         }
89 }