-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMutableSubArray.java
More file actions
30 lines (25 loc) · 969 Bytes
/
MutableSubArray.java
File metadata and controls
30 lines (25 loc) · 969 Bytes
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
package org.psjava.ds.array;
import org.psjava.ds.MutableArrayFromItemSetter;
import org.psjava.util.Assertion;
import org.psjava.util.GetterByIndex;
import org.psjava.util.SetterByIndex;
public class MutableSubArray {
public static <T> MutableArray<T> wrap(final MutableArray<T> superArray, final int start, final int end) {
final int size = end - start;
return MutableArrayFromItemSetter.create(size, new GetterByIndex<T>() {
@Override
public T get(int index) {
Assertion.ensure(0 <= index && index < size);
return superArray.get(start + index);
}
}, new SetterByIndex<T>() {
@Override
public void set(int index, T value) {
Assertion.ensure(0 <= index && index < size);
superArray.set(start + index, value);
}
});
}
private MutableSubArray() {
}
}