Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import javasabr.rlib.collections.array.impl.CopyOnWriteMutableArray;
import javasabr.rlib.collections.array.impl.DefaultMutableArray;
import javasabr.rlib.collections.array.impl.DefaultMutableIntArray;
import javasabr.rlib.collections.array.impl.DefaultMutableLongArray;
import javasabr.rlib.collections.array.impl.StampedLockBasedArray;
import javasabr.rlib.common.util.ClassUtils;
import lombok.experimental.UtilityClass;
Expand All @@ -13,10 +15,19 @@ public static <E> MutableArray<E> mutableArray(Class<? super E> type) {
return new DefaultMutableArray<>(ClassUtils.unsafeCast(type));
}

public static MutableIntArray mutableIntArray() {
return new DefaultMutableIntArray();
}

public static MutableLongArray mutableLongArray() {
return new DefaultMutableLongArray();
}

public static <E> MutableArray<E> mutableArray(Class<? super E> type, int capacity) {
return new DefaultMutableArray<>(ClassUtils.unsafeCast(type), capacity);
}


public static <E> MutableArray<E> copyOnModifyArray(Class<? super E> type) {
return new CopyOnWriteMutableArray<>(type);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package javasabr.rlib.collections.array;

import java.io.Serializable;
import java.util.RandomAccess;
import java.util.stream.IntStream;
import javasabr.rlib.collections.array.impl.ImmutableIntArray;

/**
* @author JavaSaBr
*/
public interface IntArray extends Iterable<Integer>, Serializable, Cloneable, RandomAccess {

static IntArray empty() {
return new ImmutableIntArray();
}

static IntArray of(int e1) {
return new ImmutableIntArray(e1);
}

static IntArray of(int e1, int e2) {
return new ImmutableIntArray(e1, e2);
}

static IntArray of(int e1, int e2, int e3) {
return new ImmutableIntArray(e1, e2, e3);
}

static IntArray of(int e1, int e2, int e3, int e4) {
return new ImmutableIntArray(e1, e2, e3, e4);
}

static IntArray of(int... elements) {
return new ImmutableIntArray(elements);
}

int size();

boolean contains(int value);

boolean containsAll(IntArray array);

/**
* @return the first element or {@link java.util.NoSuchElementException}
*/
int first();

int get(int index);

/**
* @return the last element or {@link java.util.NoSuchElementException}
*/
int last();

/**
* @return the index of the value or -1.
*/
int indexOf(int value);

int lastIndexOf(int value);

boolean isEmpty();

int[] toArray();

IntStream stream();

UnsafeIntArray asUnsafe();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package javasabr.rlib.collections.array;

import java.io.Serializable;
import java.util.RandomAccess;
import java.util.stream.LongStream;
import javasabr.rlib.collections.array.impl.ImmutableLongArray;

/**
* @author JavaSaBr
*/
public interface LongArray extends Iterable<Long>, Serializable, Cloneable, RandomAccess {

static LongArray empty() {
return new ImmutableLongArray();
}

static LongArray of(long e1) {
return new ImmutableLongArray(e1);
}

static LongArray of(long e1, long e2) {
return new ImmutableLongArray(e1, e2);
}

static LongArray of(long e1, long e2, long e3) {
return new ImmutableLongArray(e1, e2, e3);
}

static LongArray of(long e1, long e2, long e3, long e4) {
return new ImmutableLongArray(e1, e2, e3, e4);
}

static LongArray of(long... elements) {
return new ImmutableLongArray(elements);
}

int size();

boolean contains(long value);

boolean containsAll(LongArray array);

/**
* @return the first element or {@link java.util.NoSuchElementException}
*/
long first();

long get(int index);

/**
* @return the last element or {@link java.util.NoSuchElementException}
*/
long last();

/**
* @return the index of the value or -1.
*/
int indexOf(long value);

int lastIndexOf(long value);

boolean isEmpty();

long[] toArray();

LongStream stream();

UnsafeLongArray asUnsafe();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package javasabr.rlib.collections.array;

public interface MutableIntArray extends IntArray {

boolean add(int value);

boolean addAll(IntArray array);

boolean addAll(int[] array);

/**
* @return the element previously at the specified position
*/
int removeByInex(int index);

boolean remove(int value);

void replace(int index, int value);

void clear();

@Override
UnsafeMutableIntArray asUnsafe();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package javasabr.rlib.collections.array;

public interface MutableLongArray extends LongArray {

boolean add(long value);

boolean addAll(LongArray array);

boolean addAll(long[] array);

/**
* @return the element previously at the specified position
*/
long removeByInex(int index);

boolean remove(long value);

void replace(int index, long value);

void clear();

@Override
UnsafeMutableLongArray asUnsafe();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package javasabr.rlib.collections.array;

public interface UnsafeIntArray extends IntArray {
int[] wrapped();
int unsafeGet(int index);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package javasabr.rlib.collections.array;

public interface UnsafeLongArray extends LongArray {
long[] wrapped();
long unsafeGet(int index);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package javasabr.rlib.collections.array;

public interface UnsafeMutableIntArray extends UnsafeIntArray, MutableIntArray {

UnsafeMutableIntArray prepareForSize(int expectedSize);

UnsafeMutableIntArray unsafeAdd(int value);

int unsafeRemoveByInex(int index);

UnsafeMutableIntArray unsafeSet(int index, int value);

UnsafeMutableIntArray trimToSize();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package javasabr.rlib.collections.array;

public interface UnsafeMutableLongArray extends UnsafeLongArray, MutableLongArray {

UnsafeMutableLongArray prepareForSize(int expectedSize);

UnsafeMutableLongArray unsafeAdd(long value);

long unsafeRemoveByInex(int index);

UnsafeMutableLongArray unsafeSet(int index, long value);

UnsafeMutableLongArray trimToSize();
}
Loading
Loading