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
|
/* Glazed Lists (c) 2003-2006 */
/* http://publicobject.com/glazedlists/ publicobject.com,*/
/* O'Dell Engineering Ltd.*/
package ca.odell.glazedlists.impl;
// standard collections
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.TransformedList;
import ca.odell.glazedlists.event.ListEvent;
import java.util.Collection;
import java.util.List;
/**
* An {@link EventList} that does not allow writing operations.
*
* <p>The {@link ReadOnlyList} is useful for programming defensively. A
* {@link ReadOnlyList} is useful to supply an unknown class read-only access
* to your {@link EventList}.
*
* <p>The {@link ReadOnlyList} provides an up-to-date view of its source
* {@link EventList} so changes to the source {@link EventList} will still be
* reflected. For a static copy of any {@link EventList} it is necessary to copy
* the contents of that {@link EventList} into any {@link List}.
*
* <p>{@link ReadOnlyList} does not alter the runtime performance
* characteristics of the source {@link EventList}.
*
* <p><strong><font color="#FF0000">Warning:</font></strong> This class is
* thread ready but not thread safe. See {@link EventList} for an example
* of thread safe code.
*
* @see TransformedList
*
* @author <a href="mailto:jesse@swank.ca">Jesse Wilson</a>
*/
public final class ReadOnlyList<E> extends TransformedList<E, E> {
/**
* Creates a {@link ReadOnlyList} to provide a view of an {@link EventList}
* that does not allow write operations.
*/
public ReadOnlyList(EventList<E> source) {
super(source);
source.addListEventListener(this);
}
/**
* @return <tt>false</tt>; ReadOnlyList is... ahem... readonly
*/
@Override
protected boolean isWritable() {
return false;
}
/** {@inheritDoc} */
@Override
public void listChanged(ListEvent<E> listChanges) {
// just pass on the changes
updates.forwardEvent(listChanges);
}
//
// All accessor methods must call to the source list so as not to
// disturb the performance characteristics of the source list algorithms.
//
/** {@inheritDoc} */
@Override
public boolean contains(Object object) {
return source.contains(object);
}
/** {@inheritDoc} */
@Override
public Object[] toArray() {
return source.toArray();
}
/** {@inheritDoc} */
@Override
public <T>T[] toArray(T[] array) {
return source.toArray(array);
}
/** {@inheritDoc} */
@Override
public boolean containsAll(Collection<?> values) {
return source.containsAll(values);
}
/** {@inheritDoc} */
@Override
public int indexOf(Object object) {
return source.indexOf(object);
}
/** {@inheritDoc} */
@Override
public int lastIndexOf(Object object) {
return source.lastIndexOf(object);
}
/** {@inheritDoc} */
@Override
public boolean equals(Object object) {
return source.equals(object);
}
/** {@inheritDoc} */
@Override
public int hashCode() {
return source.hashCode();
}
//
// All mutator methods should throw an UnsupportedOperationException with
// a descriptive message explaining why mutations are disallowed.
//
/** @throws UnsupportedOperationException since ReadOnlyList cannot be modified */
@Override
public boolean add(E value) {
throw new UnsupportedOperationException("ReadOnlyList cannot be modified");
}
/** @throws UnsupportedOperationException since ReadOnlyList cannot be modified */
@Override
public void add(int index, E value) {
throw new UnsupportedOperationException("ReadOnlyList cannot be modified");
}
/** @throws UnsupportedOperationException since ReadOnlyList cannot be modified */
@Override
public boolean addAll(Collection<? extends E> values) {
throw new UnsupportedOperationException("ReadOnlyList cannot be modified");
}
/** @throws UnsupportedOperationException since ReadOnlyList cannot be modified */
@Override
public boolean addAll(int index, Collection<? extends E> values) {
throw new UnsupportedOperationException("ReadOnlyList cannot be modified");
}
/** @throws UnsupportedOperationException since ReadOnlyList cannot be modified */
@Override
public void clear() {
throw new UnsupportedOperationException("ReadOnlyList cannot be modified");
}
/** @throws UnsupportedOperationException since ReadOnlyList cannot be modified */
@Override
public boolean remove(Object toRemove) {
throw new UnsupportedOperationException("ReadOnlyList cannot be modified");
}
/** @throws UnsupportedOperationException since ReadOnlyList cannot be modified */
@Override
public E remove(int index) {
throw new UnsupportedOperationException("ReadOnlyList cannot be modified");
}
/** @throws UnsupportedOperationException since ReadOnlyList cannot be modified */
@Override
public boolean removeAll(Collection<?> collection) {
throw new UnsupportedOperationException("ReadOnlyList cannot be modified");
}
/** @throws UnsupportedOperationException since ReadOnlyList cannot be modified */
@Override
public boolean retainAll(Collection<?> values) {
throw new UnsupportedOperationException("ReadOnlyList cannot be modified");
}
/** @throws UnsupportedOperationException since ReadOnlyList cannot be modified */
@Override
public E set(int index, E value) {
throw new UnsupportedOperationException("ReadOnlyList cannot be modified");
}
}
|