1 | protected boolean useEquals()↵ | | 1 | protected boolean useEquals()↵
|
2 | {↵ | | 2 | {↵
|
3 | return true;↵ | | 3 | return true;↵
|
4 | }↵ | | 4 | }↵
|
|
5 | /**↵ | | 5 | /**↵
|
6 | * Returns whether two objects are equal using the {@link #useEquals appropriate} comparison mechanism.↵ | | 6 | * Returns whether two objects are equal using the {@link #useEquals appropriate} comparison mechanism.↵
|
7 | * @return whether two objects are equal.↵ | | 7 | * @return whether two objects are equal.↵
|
8 | */↵ | | 8 | */↵
|
9 | protected boolean equalObjects(Object firstObject, Object secondObject)↵ | | 9 | protected boolean equalObjects(Object firstObject, Object secondObject)↵
|
10 | {↵ | | 10 | {↵
|
11 | return↵ | | 11 | return↵
|
12 | useEquals() && firstObject != null ?↵ | | 12 | useEquals() && firstObject != null ?↵
|
13 | firstObject.equals(secondObject) :↵ | | 13 | firstObject.equals(secondObject) :↵
|
14 | firstObject == secondObject;↵ | | 14 | firstObject == secondObject;↵
|
15 | }↵ | | 15 | }↵
|
|
16 | /**↵ | | 16 | /**↵
|
17 | * Returns whether <code>null</code> is a valid object for the list.↵ | | 17 | * Returns whether <code>null</code> is a valid object for the list.↵
|
18 | * The default is to return <code>true</code>, but clients can override this to exclude <code>null</code>.↵ | | 18 | * The default is to return <code>true</code>, but clients can override this to exclude <code>null</code>.↵
|
19 | * @return whether <code>null</code> is a valid object for the list.↵ | | 19 | * @return whether <code>null</code> is a valid object for the list.↵
|
20 | */↵ | | 20 | */↵
|
21 | protected boolean canContainNull()↵ | | 21 | protected boolean canContainNull()↵
|
22 | {↵ | | 22 | {↵
|
23 | return true;↵ | | 23 | return true;↵
|
24 | }↵ | | 24 | }↵
|
|
25 | /**↵ | | 25 | /**↵
|
26 | * Returns whether objects are constrained to appear at most once in the list.↵ | | 26 | * Returns whether objects are constrained to appear at most once in the list.↵
|
27 | * The default is to return <code>false</code>, but clients can override this to ensure uniqueness of contents.↵ | | 27 | * The default is to return <code>false</code>, but clients can override this to ensure uniqueness of contents.↵
|
28 | * The performance impact is significant: operations such as <code>add</code> are O(n) as a result requiring uniqueness.↵ | | 28 | * The performance impact is significant: operations such as <code>add</code> are O(n) as a result requiring uniqueness.↵
|
29 | * @return whether objects are constrained to appear at most once in the list.↵ | | 29 | * @return whether objects are constrained to appear at most once in the list.↵
|
30 | */↵ | | 30 | */↵
|
31 | protected boolean isUnique()↵ | | 31 | protected boolean isUnique()↵
|
32 | {↵ | | 32 | {↵
|
33 | return false;↵ | | 33 | return false;↵
|
34 | }↵ | | 34 | }↵
|
|
35 | /**↵ | | 35 | /**↵
|
36 | * Validates a new content object and returns the validated object.↵ | | 36 | * Validates a new content object and returns the validated object.↵
|
37 | * This implementation checks for null, if {@link #canContainNull necessary} and returns the argument object.↵ | | 37 | * This implementation checks for null, if {@link #canContainNull necessary} and returns the argument object.↵
|
38 | * Clients may throw additional types of runtime exceptions ↵ | | 38 | * Clients may throw additional types of runtime exceptions ↵
|
39 | * in order to handle constraint violations.↵ | | 39 | * in order to handle constraint violations.↵
|
40 | * @param index the position of the new content.↵ | | 40 | * @param index the position of the new content.↵
|
41 | * @param object the new content.↵ | | 41 | * @param object the new content.↵
|
42 | * @return the validated content.↵ | | 42 | * @return the validated content.↵
|
43 | * @exception IllegalArgumentException if a constraint prevents the object from being added.↵ | | 43 | * @exception IllegalArgumentException if a constraint prevents the object from being added.↵
|
44 | */↵ | | 44 | */↵
|
45 | protected E validate(int index, E object)↵ | | 45 | protected E validate(int index, E object)↵
|
46 | {↵ | | 46 | {↵
|
47 | if (!canContainNull() && object == null)↵ | | 47 | if (!canContainNull() && object == null)↵
|
48 | {↵ | | 48 | {↵
|
49 | throw new IllegalArgumentException("The 'no null' constraint is violated");↵ | | 49 | throw new IllegalArgumentException("The 'no null' constraint is violated");↵
|
50 | }↵ | | 50 | }↵
|
|
51 | return object; | | 51 | return object;
|