|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractCollection java.util.AbstractList org.xins.common.collections.ProtectedList
Modifiable List
implementaton that can be protected from
unauthorized changes.
A secret key must be passed when constructing a
ProtectedPropertyReader
instance. All modification methods on
this object then require this same secret key to be passed, otherwise they
fail with an IncorrectSecretKeyException
.
Note that the secret key equality is always checked before the other
preconditions. This means that if the secret key is incorrect, then the
other preconditions will not even be checked. For example, if
is called, then an
remove
(null, -1)IncorrectSecretKeyException
is thrown for the mismatching secret
key, and not an IndexOutOfBoundsException
, for the negative index.
Field Summary |
Fields inherited from class java.util.AbstractList |
modCount |
Constructor Summary | |
ProtectedList(Object secretKey)
Constructs an empty ProtectedList . |
|
ProtectedList(Object secretKey,
Collection c)
Constructs a new ProtectedList containing the elements of
the specified collection, in the order they are returned by the
collection's iterator. |
|
ProtectedList(Object secretKey,
int initialCapacity)
Constructs an empty ProtectedList with the specified
initial capacity. |
Method Summary | |
void |
add(Object secretKey,
Object element)
Adds the specified element to the list. |
Object |
clone()
Clones this object. |
Object |
get(int index)
Returns the element at the specified position in this list. |
void |
remove(Object secretKey,
int index)
Removes the specified element. |
int |
size()
Returns the number of elements in this list. |
Methods inherited from class java.util.AbstractList |
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList |
Methods inherited from class java.util.AbstractCollection |
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray |
Constructor Detail |
public ProtectedList(Object secretKey, int initialCapacity) throws IllegalArgumentException
ProtectedList
with the specified
initial capacity.
secretKey
- the secret key that must be passed to the modification methods in
order to be authorized to modify this collection.initialCapacity
- the initial capacity, cannot be a negative number.
IllegalArgumentException
- if secretKey == null || initialCapacity < 0
.public ProtectedList(Object secretKey) throws IllegalArgumentException
ProtectedList
.
secretKey
- the secret key that must be passed to the modification methods in
order to be authorized to modify this collection, cannot be
null
.
IllegalArgumentException
- if secretKey == null
.public ProtectedList(Object secretKey, Collection c) throws IllegalArgumentException
ProtectedList
containing the elements of
the specified collection, in the order they are returned by the
collection's iterator.
secretKey
- the secret key that must be passed to the modification methods in
order to be authorized to modify this collection, cannot be
null
.c
- the collection whose elements are to be placed into this list, cannot
be null
.
IllegalArgumentException
- if secretKey == null || c == null
.Method Detail |
public Object get(int index) throws IndexOutOfBoundsException
get
in interface List
index
- the index of the element to return, must be >= 0 and <
size()
.
null
.
IndexOutOfBoundsException
- if index < 0
|| index >= size()
.public int size()
Integer.MAX_VALUE
elements, then Integer.MAX_VALUE
is returned.
size
in interface List
Integer.MAX_VALUE
.public void add(Object secretKey, Object element) throws IncorrectSecretKeyException
The correct secret key must be passed. If it is incorrect, then an
IncorrectSecretKeyException
is thrown. Note that an identity
check is done, not an equality check. So
the Object.equals(Object)
method is not used, but the
==
operator is.
secretKey
- the secret key, must be identity-equal to the secret key passed to
the constructor, cannot be null
.element
- the element to add to the list, can be null
.
IncorrectSecretKeyException
- if secretKey
does not match the secret key passed to the
constructor.public void remove(Object secretKey, int index) throws IncorrectSecretKeyException, IndexOutOfBoundsException
The correct secret key must be passed. If it is incorrect, then an
IncorrectSecretKeyException
is thrown. Note that an identity
check is done, not an equality check. So
the Object.equals(Object)
method is not used, but the
==
operator is.
secretKey
- the secret key, must be identity-equal to the secret key passed to
the constructor, cannot be null
.index
- the position of the element to remove, must be >= 0 and <
size()
.
IncorrectSecretKeyException
- if secretKey
does not match the secret key passed to the
constructor.
IndexOutOfBoundsException
- if index < 0
|| index >= size()
.public Object clone()
ProtectedList
instance with the same secret key and the
same elements.
null
.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |