mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
11.45.2009 2bc8d15a28fafab97cefafede06d6b7e738ae0fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2009 Sun Microsystems, Inc.
 */
 
package org.opends.sdk;
 
 
 
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
 
 
 
/**
 * An attribute, comprising of an attribute description and zero or more
 * attribute values.
 * <p>
 * Any methods which perform comparisons between attribute values use
 * the equality matching rule associated with the attribute description.
 * <p>
 * Any methods which accept {@code Object} based attribute values
 * convert the attribute values to instances of {@code ByteString} as
 * follows:
 *
 * <pre>
 * Object object = ...;
 * ByteString value = null;
 * if (object instanceof ByteSequence)
 * {
 *   value = ((ByteSequence)object).toByteString();
 * }
 * else
 * {
 *   value = ByteString.valueOf(object.toString());
 * }
 * </pre>
 * <p>
 * TODO: matching against attribute value assertions.
 */
public interface Attribute extends Set<ByteString>
{
  /**
   * Adds {@code value} to this attribute if it is not already present
   * (optional operation). If this attribute already contains {@code
   * value}, the call leaves the attribute unchanged and returns {@code
   * false}.
   *
   * @param value
   *          The attribute value to be added to this attribute.
   * @return {@code true} if this attribute changed as a result of this
   *         call.
   * @throws UnsupportedOperationException
   *           If this attribute does not support addition of attribute
   *           values.
   * @throws NullPointerException
   *           If {@code value} was {@code null}.
   */
  boolean add(ByteString value) throws UnsupportedOperationException,
      NullPointerException;
 
 
 
  /**
   * Adds all of the provided attribute values to this attribute if they
   * are not already present (optional operation).
   * <p>
   * Any attribute values which are not instances of {@code ByteString}
   * will be converted using the {@link ByteString#valueOf(Object)}
   * method.
   *
   * @param firstValue
   *          The first attribute value to be added to this attribute.
   * @param remainingValues
   *          The remaining attribute values to be added to this
   *          attribute.
   * @return {@code true} if this attribute changed as a result of this
   *         call.
   * @throws UnsupportedOperationException
   *           If this attribute does not support addition of attribute
   *           values.
   * @throws NullPointerException
   *           If {@code firstValue} was {@code null}.
   */
  boolean add(Object firstValue, Object... remainingValues)
      throws UnsupportedOperationException, NullPointerException;
 
 
 
  /**
   * Adds all of the attribute values contained in {@code values} to
   * this attribute if they are not already present (optional
   * operation).
   * <p>
   * An invocation of this method is equivalent to:
   *
   * <pre>
   * attribute.addAll(values, null);
   * </pre>
   *
   * @param values
   *          The attribute values to be added to this attribute.
   * @return {@code true} if this attribute changed as a result of this
   *         call.
   * @throws UnsupportedOperationException
   *           If this attribute does not support addition of attribute
   *           values.
   * @throws NullPointerException
   *           If {@code values} was {@code null}.
   */
  boolean addAll(Collection<? extends ByteString> values)
      throws UnsupportedOperationException, NullPointerException;
 
 
 
  /**
   * Adds all of the attribute values contained in {@code values} to
   * this attribute if they are not already present (optional
   * operation). Any attribute values which are already present will be
   * added to {@code duplicateValues} if specified.
   *
   * @param values
   *          The attribute values to be added to this attribute.
   * @param duplicateValues
   *          A collection into which duplicate values will be added, or
   *          {@code null} if duplicate values should not be saved.
   * @return {@code true} if this attribute changed as a result of this
   *         call.
   * @throws UnsupportedOperationException
   *           If this attribute does not support addition of attribute
   *           values.
   * @throws NullPointerException
   *           If {@code values} was {@code null}.
   */
  boolean addAll(Collection<? extends ByteString> values,
      Collection<? super ByteString> duplicateValues)
      throws UnsupportedOperationException, NullPointerException;
 
 
 
  /**
   * Removes all of the attribute values from this attribute (optional
   * operation). This attribute will be empty after this call returns.
   */
  void clear() throws UnsupportedOperationException;
 
 
 
  /**
   * Returns {@code true} if this attribute contains {@code value}.
   * <p>
   * If {@code value} is not an instance of {@code ByteString} then it
   * will be converted using the {@link ByteString#valueOf(Object)}
   * method.
   *
   * @param value
   *          The attribute value whose presence in this attribute is to
   *          be tested.
   * @return {@code true} if this attribute contains {@code value}, or
   *         {@code false} if not.
   * @throws NullPointerException
   *           If {@code value} was {@code null}.
   */
  boolean contains(Object value) throws NullPointerException;
 
 
 
  /**
   * Returns {@code true} if this attribute contains all of the
   * attribute values contained in {@code values}.
   * <p>
   * Any attribute values which are not instances of {@code ByteString}
   * will be converted using the {@link ByteString#valueOf(Object)}
   * method.
   *
   * @param values
   *          The attribute values whose presence in this attribute is
   *          to be tested.
   * @return {@code true} if this attribute contains all of the
   *         attribute values contained in {@code values}, or {@code
   *         false} if not.
   * @throws NullPointerException
   *           If {@code values} was {@code null}.
   */
  boolean containsAll(Collection<?> values) throws NullPointerException;
 
 
 
  /**
   * Returns {@code true} if {@code object} is an attribute which is
   * equal to this attribute. Two attributes are considered equal if
   * their attribute descriptions are equal, they both have the same
   * number of attribute values, and every attribute value contained in
   * the first attribute is also contained in the second attribute.
   *
   * @param object
   *          The object to be tested for equality with this attribute.
   * @return {@code true} if {@code object} is an attribute which is
   *         equal to this attribute, or {@code false} if not.
   */
  boolean equals(Object object);
 
 
 
  /**
   * Returns the first attribute value in this attribute.
   *
   * @return The first attribute value in this attribute.
   * @throws NoSuchElementException
   *           If this attribute is empty.
   */
  ByteString firstValue() throws NoSuchElementException;
 
 
 
  /**
   * Returns the first attribute value in this attribute decoded as a
   * UTF-8 string.
   *
   * @return The first attribute value in this attribute decoded as a
   *         UTF-8 string.
   * @throws NoSuchElementException
   *           If this attribute is empty.
   */
  String firstValueAsString() throws NoSuchElementException;
 
 
 
  /**
   * Returns the attribute description of this attribute, which includes
   * its attribute type and any options.
   *
   * @return The attribute description.
   */
  AttributeDescription getAttributeDescription();
 
 
 
  /**
   * Returns the string representation of the attribute description of
   * this attribute, which includes its attribute type and any options.
   *
   * @return The string representation of the attribute description.
   */
  String getAttributeDescriptionAsString();
 
 
 
  /**
   * Returns the hash code for this attribute. It will be calculated as
   * the sum of the hash codes of the attribute description and all of
   * the attribute values.
   *
   * @return The hash code for this attribute.
   */
  int hashCode();
 
 
 
  /**
   * Returns {@code true} if this attribute contains no attribute
   * values.
   *
   * @return {@code true} if this attribute contains no attribute
   *         values.
   */
  boolean isEmpty();
 
 
 
  /**
   * Returns an iterator over the attribute values in this attribute.
   * The attribute values are returned in no particular order, unless
   * the implementation of this attribute provides such a guarantee.
   *
   * @return An iterator over the attribute values in this attribute.
   */
  Iterator<ByteString> iterator();
 
 
 
  /**
   * Removes {@code value} from this attribute if it is present
   * (optional operation). If this attribute does not contain {@code
   * value}, the call leaves the attribute unchanged and returns {@code
   * false}.
   * <p>
   * If {@code value} is not an instance of {@code ByteString} then it
   * will be converted using the {@link ByteString#valueOf(Object)}
   * method.
   *
   * @param value
   *          The attribute value to be removed from this attribute.
   * @return {@code true} if this attribute changed as a result of this
   *         call.
   * @throws UnsupportedOperationException
   *           If this attribute does not support removal of attribute
   *           values.
   * @throws NullPointerException
   *           If {@code value} was {@code null}.
   */
  boolean remove(Object value) throws UnsupportedOperationException,
      NullPointerException;
 
 
 
  /**
   * Removes all of the attribute values contained in {@code values}
   * from this attribute if they are present (optional operation).
   * <p>
   * Any attribute values which are not instances of {@code ByteString}
   * will be converted using the {@link ByteString#valueOf(Object)}
   * method.
   * <p>
   * An invocation of this method is equivalent to:
   *
   * <pre>
   * attribute.removeAll(values, null);
   * </pre>
   *
   * @param values
   *          The attribute values to be removed from this attribute.
   * @return {@code true} if this attribute changed as a result of this
   *         call.
   * @throws UnsupportedOperationException
   *           If this attribute does not support removal of attribute
   *           values.
   * @throws NullPointerException
   *           If {@code values} was {@code null}.
   */
  boolean removeAll(Collection<?> values)
      throws UnsupportedOperationException, NullPointerException;
 
 
 
  /**
   * Removes all of the attribute values contained in {@code values}
   * from this attribute if they are present (optional operation). Any
   * attribute values which are not already present will be added to
   * {@code missingValues} if specified.
   * <p>
   * Any attribute values which are not instances of {@code ByteString}
   * will be converted using the {@link ByteString#valueOf(Object)}
   * method.
   *
   * @param <T>
   *          The type of the attribute value objects being removed.
   * @param values
   *          The attribute values to be removed from this attribute.
   * @param missingValues
   *          A collection into which missing values will be added, or
   *          {@code null} if missing values should not be saved.
   * @return {@code true} if this attribute changed as a result of this
   *         call.
   * @throws UnsupportedOperationException
   *           If this attribute does not support removal of attribute
   *           values.
   * @throws NullPointerException
   *           If {@code values} was {@code null}.
   */
  <T> boolean removeAll(Collection<T> values,
      Collection<? super T> missingValues)
      throws UnsupportedOperationException, NullPointerException;
 
 
 
  /**
   * Retains only the attribute values in this attribute which are
   * contained in {@code values} (optional operation).
   * <p>
   * Any attribute values which are not instances of {@code ByteString}
   * will be converted using the {@link ByteString#valueOf(Object)}
   * method.
   * <p>
   * An invocation of this method is equivalent to:
   *
   * <pre>
   * attribute.retainAll(values, null);
   * </pre>
   *
   * @param values
   *          The attribute values to be retained in this attribute.
   * @return {@code true} if this attribute changed as a result of this
   *         call.
   * @throws UnsupportedOperationException
   *           If this attribute does not support removal of attribute
   *           values.
   * @throws NullPointerException
   *           If {@code values} was {@code null}.
   */
  boolean retainAll(Collection<?> values)
      throws UnsupportedOperationException, NullPointerException;
 
 
 
  /**
   * Retains only the attribute values in this attribute which are
   * contained in {@code values} (optional operation). Any attribute
   * values which are not already present will be added to {@code
   * missingValues} if specified.
   * <p>
   * Any attribute values which are not instances of {@code ByteString}
   * will be converted using the {@link ByteString#valueOf(Object)}
   * method.
   *
   * @param <T>
   *          The type of the attribute value objects being retained.
   * @param values
   *          The attribute values to be retained in this attribute.
   * @param missingValues
   *          A collection into which missing values will be added, or
   *          {@code null} if missing values should not be saved.
   * @return {@code true} if this attribute changed as a result of this
   *         call.
   * @throws UnsupportedOperationException
   *           If this attribute does not support removal of attribute
   *           values.
   * @throws NullPointerException
   *           If {@code values} was {@code null}.
   */
  <T> boolean retainAll(Collection<T> values,
      Collection<? super T> missingValues)
      throws UnsupportedOperationException, NullPointerException;
 
 
 
  /**
   * Returns the number of attribute values in this attribute.
   *
   * @return The number of attribute values in this attribute.
   */
  int size();
 
 
 
  /**
   * Returns an array containing all of the attribute values contained
   * in this attribute.
   * <p>
   * If this attribute makes any guarantees as to what order its
   * attribute values are returned by its iterator, this method must
   * return the attribute values in the same order.
   * <p>
   * The returned array will be "safe" in that no references to it are
   * maintained by this attribute. The caller is thus free to modify the
   * returned array.
   */
  ByteString[] toArray();
 
 
 
  /**
   * Returns an array containing all of the attribute values in this
   * attribute; the runtime type of the returned array is that of the
   * specified array.
   * <p>
   * If the set fits in the specified array, it is returned therein.
   * Otherwise, a new array is allocated with the runtime type of the
   * specified array and the size of this attribute. If this attribute
   * fits in the specified array with room to spare (i.e., the array has
   * more elements than this attribute), the elements in the array
   * immediately following the end of the set is set to {@code null}.
   * <p>
   * If this attribute makes any guarantees as to what order its
   * attribute values are returned by its iterator, this method must
   * return the attribute values in the same order.
   *
   * @throws ArrayStoreException
   *           If the runtime type of {@code array} is not a supertype
   *           of {@code ByteString}.
   * @throws NullPointerException
   *           If {@code array} was {@code null}.
   */
  <T> T[] toArray(T[] array) throws ArrayStoreException,
      NullPointerException;
 
 
 
  /**
   * Returns a string representation of this attribute.
   *
   * @return The string representation of this attribute.
   */
  String toString();
}