1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.onehippo.forge.exdocpicker.impl.field.tree;
17
18 import java.io.Serializable;
19 import java.util.Collection;
20 import java.util.HashSet;
21 import java.util.Iterator;
22 import java.util.Set;
23
24
25
26
27 class TreeItemExpansionSet implements Set<Serializable>, Serializable {
28
29 private static final long serialVersionUID = 1L;
30
31 private Set<Serializable> items = new HashSet<>();
32 private boolean inversed;
33
34 public void expandAll() {
35 items.clear();
36 inversed = true;
37 }
38
39 public void collapseAll() {
40 items.clear();
41 inversed = false;
42 }
43
44 @Override
45 public boolean add(Serializable item) {
46 if (inversed) {
47 return items.remove(item);
48 } else {
49 return items.add(item);
50 }
51 }
52
53 @Override
54 public boolean remove(Object o) {
55 if (inversed) {
56 return items.add((Serializable) o);
57 } else {
58 return items.remove(o);
59 }
60 }
61
62 @Override
63 public boolean contains(Object o) {
64 if (inversed) {
65 return !items.contains(o);
66 } else {
67 return items.contains(o);
68 }
69 }
70
71 @Override
72 public void clear() {
73 throw new UnsupportedOperationException();
74 }
75
76 @Override
77 public int size() {
78 throw new UnsupportedOperationException();
79 }
80
81 @Override
82 public boolean isEmpty() {
83 throw new UnsupportedOperationException();
84 }
85
86 @Override
87 public <A> A[] toArray(A[] a) {
88 throw new UnsupportedOperationException();
89 }
90
91 @Override
92 public Iterator<Serializable> iterator() {
93 throw new UnsupportedOperationException();
94 }
95
96 @Override
97 public Object[] toArray() {
98 throw new UnsupportedOperationException();
99 }
100
101 @Override
102 public boolean containsAll(Collection<?> c) {
103 throw new UnsupportedOperationException();
104 }
105
106 @Override
107 public boolean addAll(Collection<? extends Serializable> c) {
108 throw new UnsupportedOperationException();
109 }
110
111 @Override
112 public boolean retainAll(Collection<?> c) {
113 throw new UnsupportedOperationException();
114 }
115
116 @Override
117 public boolean removeAll(Collection<?> c) {
118 throw new UnsupportedOperationException();
119 }
120 }