View Javadoc
1   /**
2    * Copyright 2014-2024 Bloomreach B.V. (<a href="http://www.bloomreach.com">http://www.bloomreach.com</a>)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Tree item expansion state data set.
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 }