Skip to content

Commit bbdbcd1

Browse files
authored
Merge pull request #39 from JavaSaBr/improve-modules-v6
Improve modules part 6
2 parents 7c23b20 + 1ca886a commit bbdbcd1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2449
-1888
lines changed

rlib-collections/src/main/java/javasabr/rlib/collections/array/ArrayFactory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import javasabr.rlib.collections.array.impl.CopyOnWriteMutableArray;
44
import javasabr.rlib.collections.array.impl.DefaultMutableArray;
5+
import javasabr.rlib.collections.array.impl.DefaultMutableIntArray;
6+
import javasabr.rlib.collections.array.impl.DefaultMutableLongArray;
57
import javasabr.rlib.collections.array.impl.StampedLockBasedArray;
68
import javasabr.rlib.common.util.ClassUtils;
79
import lombok.experimental.UtilityClass;
@@ -13,10 +15,19 @@ public static <E> MutableArray<E> mutableArray(Class<? super E> type) {
1315
return new DefaultMutableArray<>(ClassUtils.unsafeCast(type));
1416
}
1517

18+
public static MutableIntArray mutableIntArray() {
19+
return new DefaultMutableIntArray();
20+
}
21+
22+
public static MutableLongArray mutableLongArray() {
23+
return new DefaultMutableLongArray();
24+
}
25+
1626
public static <E> MutableArray<E> mutableArray(Class<? super E> type, int capacity) {
1727
return new DefaultMutableArray<>(ClassUtils.unsafeCast(type), capacity);
1828
}
1929

30+
2031
public static <E> MutableArray<E> copyOnModifyArray(Class<? super E> type) {
2132
return new CopyOnWriteMutableArray<>(type);
2233
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package javasabr.rlib.collections.array;
2+
3+
import java.io.Serializable;
4+
import java.util.RandomAccess;
5+
import java.util.stream.IntStream;
6+
import javasabr.rlib.collections.array.impl.ImmutableIntArray;
7+
8+
/**
9+
* @author JavaSaBr
10+
*/
11+
public interface IntArray extends Iterable<Integer>, Serializable, Cloneable, RandomAccess {
12+
13+
static IntArray empty() {
14+
return new ImmutableIntArray();
15+
}
16+
17+
static IntArray of(int e1) {
18+
return new ImmutableIntArray(e1);
19+
}
20+
21+
static IntArray of(int e1, int e2) {
22+
return new ImmutableIntArray(e1, e2);
23+
}
24+
25+
static IntArray of(int e1, int e2, int e3) {
26+
return new ImmutableIntArray(e1, e2, e3);
27+
}
28+
29+
static IntArray of(int e1, int e2, int e3, int e4) {
30+
return new ImmutableIntArray(e1, e2, e3, e4);
31+
}
32+
33+
static IntArray of(int... elements) {
34+
return new ImmutableIntArray(elements);
35+
}
36+
37+
int size();
38+
39+
boolean contains(int value);
40+
41+
boolean containsAll(IntArray array);
42+
43+
/**
44+
* @return the first element or {@link java.util.NoSuchElementException}
45+
*/
46+
int first();
47+
48+
int get(int index);
49+
50+
/**
51+
* @return the last element or {@link java.util.NoSuchElementException}
52+
*/
53+
int last();
54+
55+
/**
56+
* @return the index of the value or -1.
57+
*/
58+
int indexOf(int value);
59+
60+
int lastIndexOf(int value);
61+
62+
boolean isEmpty();
63+
64+
int[] toArray();
65+
66+
IntStream stream();
67+
68+
UnsafeIntArray asUnsafe();
69+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package javasabr.rlib.collections.array;
2+
3+
import java.io.Serializable;
4+
import java.util.RandomAccess;
5+
import java.util.stream.LongStream;
6+
import javasabr.rlib.collections.array.impl.ImmutableLongArray;
7+
8+
/**
9+
* @author JavaSaBr
10+
*/
11+
public interface LongArray extends Iterable<Long>, Serializable, Cloneable, RandomAccess {
12+
13+
static LongArray empty() {
14+
return new ImmutableLongArray();
15+
}
16+
17+
static LongArray of(long e1) {
18+
return new ImmutableLongArray(e1);
19+
}
20+
21+
static LongArray of(long e1, long e2) {
22+
return new ImmutableLongArray(e1, e2);
23+
}
24+
25+
static LongArray of(long e1, long e2, long e3) {
26+
return new ImmutableLongArray(e1, e2, e3);
27+
}
28+
29+
static LongArray of(long e1, long e2, long e3, long e4) {
30+
return new ImmutableLongArray(e1, e2, e3, e4);
31+
}
32+
33+
static LongArray of(long... elements) {
34+
return new ImmutableLongArray(elements);
35+
}
36+
37+
int size();
38+
39+
boolean contains(long value);
40+
41+
boolean containsAll(LongArray array);
42+
43+
/**
44+
* @return the first element or {@link java.util.NoSuchElementException}
45+
*/
46+
long first();
47+
48+
long get(int index);
49+
50+
/**
51+
* @return the last element or {@link java.util.NoSuchElementException}
52+
*/
53+
long last();
54+
55+
/**
56+
* @return the index of the value or -1.
57+
*/
58+
int indexOf(long value);
59+
60+
int lastIndexOf(long value);
61+
62+
boolean isEmpty();
63+
64+
long[] toArray();
65+
66+
LongStream stream();
67+
68+
UnsafeLongArray asUnsafe();
69+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package javasabr.rlib.collections.array;
2+
3+
public interface MutableIntArray extends IntArray {
4+
5+
boolean add(int value);
6+
7+
boolean addAll(IntArray array);
8+
9+
boolean addAll(int[] array);
10+
11+
/**
12+
* @return the element previously at the specified position
13+
*/
14+
int removeByInex(int index);
15+
16+
boolean remove(int value);
17+
18+
void replace(int index, int value);
19+
20+
void clear();
21+
22+
@Override
23+
UnsafeMutableIntArray asUnsafe();
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package javasabr.rlib.collections.array;
2+
3+
public interface MutableLongArray extends LongArray {
4+
5+
boolean add(long value);
6+
7+
boolean addAll(LongArray array);
8+
9+
boolean addAll(long[] array);
10+
11+
/**
12+
* @return the element previously at the specified position
13+
*/
14+
long removeByInex(int index);
15+
16+
boolean remove(long value);
17+
18+
void replace(int index, long value);
19+
20+
void clear();
21+
22+
@Override
23+
UnsafeMutableLongArray asUnsafe();
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package javasabr.rlib.collections.array;
2+
3+
public interface UnsafeIntArray extends IntArray {
4+
int[] wrapped();
5+
int unsafeGet(int index);
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package javasabr.rlib.collections.array;
2+
3+
public interface UnsafeLongArray extends LongArray {
4+
long[] wrapped();
5+
long unsafeGet(int index);
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package javasabr.rlib.collections.array;
2+
3+
public interface UnsafeMutableIntArray extends UnsafeIntArray, MutableIntArray {
4+
5+
UnsafeMutableIntArray prepareForSize(int expectedSize);
6+
7+
UnsafeMutableIntArray unsafeAdd(int value);
8+
9+
int unsafeRemoveByInex(int index);
10+
11+
UnsafeMutableIntArray unsafeSet(int index, int value);
12+
13+
UnsafeMutableIntArray trimToSize();
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package javasabr.rlib.collections.array;
2+
3+
public interface UnsafeMutableLongArray extends UnsafeLongArray, MutableLongArray {
4+
5+
UnsafeMutableLongArray prepareForSize(int expectedSize);
6+
7+
UnsafeMutableLongArray unsafeAdd(long value);
8+
9+
long unsafeRemoveByInex(int index);
10+
11+
UnsafeMutableLongArray unsafeSet(int index, long value);
12+
13+
UnsafeMutableLongArray trimToSize();
14+
}

0 commit comments

Comments
 (0)