| 1 |
package morfologik.stemming; |
| 2 |
|
| 3 |
import java.util.*; |
| 4 |
|
| 5 |
/** |
| 6 |
* A view over a range of an array. |
| 7 |
*/ |
| 8 |
@SuppressWarnings("serial") |
| 9 |
final class ArrayViewList<E> extends AbstractList<E> |
| 10 |
implements RandomAccess, java.io.Serializable |
| 11 |
{ |
| 12 |
/** Backing array. */ |
| 13 |
private E[] a; |
| 14 |
private int start; |
| 15 |
private int length; |
| 16 |
|
| 17 |
/* |
| 18 |
* |
| 19 |
*/ |
| 20 |
ArrayViewList(E[] array, int start, int length) { |
| 21 |
if (array == null) |
| 22 |
throw new IllegalArgumentException(); |
| 23 |
wrap(array, start, length); |
| 24 |
} |
| 25 |
|
| 26 |
/* |
| 27 |
* |
| 28 |
*/ |
| 29 |
public int size() { |
| 30 |
return length; |
| 31 |
} |
| 32 |
|
| 33 |
/* |
| 34 |
* |
| 35 |
*/ |
| 36 |
public E get(int index) { |
| 37 |
return a[start + index]; |
| 38 |
} |
| 39 |
|
| 40 |
/* |
| 41 |
* |
| 42 |
*/ |
| 43 |
public E set(int index, E element) { |
| 44 |
throw new UnsupportedOperationException(); |
| 45 |
} |
| 46 |
|
| 47 |
/* |
| 48 |
* |
| 49 |
*/ |
| 50 |
public void add(int index, E element) { |
| 51 |
throw new UnsupportedOperationException(); |
| 52 |
} |
| 53 |
|
| 54 |
/* |
| 55 |
* |
| 56 |
*/ |
| 57 |
public E remove(int index) { |
| 58 |
throw new UnsupportedOperationException(); |
| 59 |
} |
| 60 |
|
| 61 |
/* |
| 62 |
* |
| 63 |
*/ |
| 64 |
public boolean addAll(int index, Collection<? extends E> c) { |
| 65 |
throw new UnsupportedOperationException(); |
| 66 |
} |
| 67 |
|
| 68 |
/* |
| 69 |
* |
| 70 |
*/ |
| 71 |
public int indexOf(Object o) { |
| 72 |
if (o == null) { |
| 73 |
for (int i = start; i < start + length; i++) |
| 74 |
if (a[i] == null) |
| 75 |
return i - start; |
| 76 |
} else { |
| 77 |
for (int i = start; i < start + length; i++) |
| 78 |
if (o.equals(a[i])) |
| 79 |
return i - start; |
| 80 |
} |
| 81 |
return -1; |
| 82 |
} |
| 83 |
|
| 84 |
public ListIterator<E> listIterator() { |
| 85 |
return listIterator(0); |
| 86 |
} |
| 87 |
|
| 88 |
/* |
| 89 |
* |
| 90 |
*/ |
| 91 |
public ListIterator<E> listIterator(final int index) { |
| 92 |
return Arrays.asList(a).subList(start, start + length).listIterator( |
| 93 |
index); |
| 94 |
} |
| 95 |
|
| 96 |
/* |
| 97 |
* |
| 98 |
*/ |
| 99 |
public boolean contains(Object o) { |
| 100 |
return indexOf(o) != -1; |
| 101 |
} |
| 102 |
|
| 103 |
/* |
| 104 |
* |
| 105 |
*/ |
| 106 |
void wrap(E[] array, int start, int length) { |
| 107 |
this.a = array; |
| 108 |
this.start = start; |
| 109 |
this.length = length; |
| 110 |
} |
| 111 |
} |