1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.avltree;
21
22
23 import org.apache.directory.server.i18n.I18n;
24
25
26
27
28
29
30
31 public class SingletonOrOrderedSet<V>
32 {
33 private V singleton;
34 private AvlTree<V> orderedSet;
35
36
37
38
39
40
41
42 public SingletonOrOrderedSet( V singleton )
43 {
44 if ( singleton == null )
45 {
46 throw new IllegalArgumentException( I18n.err( I18n.ERR_447 ) );
47 }
48
49 this.singleton = singleton;
50 }
51
52
53
54
55
56
57
58
59 public SingletonOrOrderedSet( AvlTree<V> orderedSet )
60 {
61 if ( orderedSet == null )
62 {
63 throw new IllegalArgumentException( I18n.err( I18n.ERR_448 ) );
64 }
65
66 this.orderedSet = orderedSet;
67 }
68
69
70
71
72
73
74
75 public boolean isSingleton()
76 {
77 return singleton != null;
78 }
79
80
81
82
83
84
85
86 public boolean isOrderedSet()
87 {
88 return orderedSet != null;
89 }
90
91
92
93
94
95
96
97
98 public V getSingleton()
99 {
100 if ( singleton != null )
101 {
102 return singleton;
103 }
104
105 throw new RuntimeException( I18n.err( I18n.ERR_449 ) );
106 }
107
108
109
110
111
112
113
114
115 public V setSingleton( V singleton )
116 {
117 if ( singleton == null )
118 {
119 throw new IllegalArgumentException( I18n.err( I18n.ERR_447 ) );
120 }
121
122 if ( this.orderedSet != null )
123 {
124 throw new RuntimeException( I18n.err( I18n.ERR_450 ) );
125 }
126
127 V retval = this.singleton;
128 this.singleton = singleton;
129 return retval;
130 }
131
132
133
134
135
136
137
138
139
140
141 public AvlTree<V> switchToSingleton( V singleton )
142 {
143 if ( singleton == null )
144 {
145 throw new IllegalArgumentException( I18n.err( I18n.ERR_447 ) );
146 }
147
148 if ( this.singleton != null )
149 {
150 throw new RuntimeException( I18n.err( I18n.ERR_451 ) );
151 }
152
153 AvlTree<V> retval = this.orderedSet;
154 this.orderedSet = null;
155 this.singleton = singleton;
156 return retval;
157 }
158
159
160
161
162
163
164
165
166 public AvlTree<V> getOrderedSet()
167 {
168 if ( orderedSet != null )
169 {
170 return orderedSet;
171 }
172
173 throw new RuntimeException( I18n.err( I18n.ERR_452 ) );
174 }
175
176
177
178
179
180
181
182
183
184 public AvlTree<V> setOrderedSet( AvlTree<V> orderedSet )
185 {
186 if ( orderedSet == null )
187 {
188 throw new IllegalArgumentException( I18n.err( I18n.ERR_448 ) );
189 }
190
191 if ( this.singleton != null )
192 {
193 throw new RuntimeException( I18n.err( I18n.ERR_453 ) );
194 }
195
196 AvlTree<V> retval = this.orderedSet;
197 this.orderedSet = orderedSet;
198 return retval;
199 }
200
201
202
203
204
205
206
207
208
209
210 public V switchToOrderedSet( AvlTree<V> orderedSet )
211 {
212 if ( orderedSet == null )
213 {
214 throw new IllegalArgumentException( I18n.err( I18n.ERR_448 ) );
215 }
216
217 if ( this.orderedSet != null )
218 {
219 throw new RuntimeException( I18n.err( I18n.ERR_454 ) );
220 }
221
222 V retval = this.singleton;
223 this.orderedSet = orderedSet;
224 this.singleton = null;
225 return retval;
226 }
227 }