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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {
}

ext {
rlibVersion = "10.0.alpha6"
rlibVersion = "10.0.alpha7"
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.version = "10.0.alpha6"
rootProject.version = "10.0.alpha7"
group = 'javasabr.rlib'

allprojects {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package javasabr.rlib.collections.array;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
Expand All @@ -9,6 +10,7 @@
import java.util.stream.Stream;
import javasabr.rlib.collections.array.impl.DefaultArrayIterator;
import javasabr.rlib.collections.array.impl.ImmutableArray;
import javasabr.rlib.common.util.ArrayUtils;
import javasabr.rlib.common.util.ClassUtils;
import org.jspecify.annotations.Nullable;

Expand All @@ -21,20 +23,44 @@ static <E> Array<E> empty(Class<? super E> type) {
return new ImmutableArray<>(ClassUtils.unsafeCast(type));
}

static <E> Array<E> of(E e1) {
return new ImmutableArray<>(Object.class, e1);
static <E> Array<E> of(E single) {
@SuppressWarnings("unchecked")
Class<E> type = (Class<E>) single.getClass();
return new ImmutableArray<>(type, single);
}

static <E> Array<E> of(E e1, E e2) {
return new ImmutableArray<>(Object.class, e1, e2);
Class<E> commonType = ClassUtils.commonType(e1, e2);
return new ImmutableArray<>(commonType, e1, e2);
}

static <E> Array<E> of(E e1, E e2, E e3) {
return new ImmutableArray<>(Object.class, e1, e2, e3);
Class<E> commonType = ClassUtils.commonType(e1, e2, e3);
return new ImmutableArray<>(commonType, e1, e2, e3);
}

static <E> Array<E> of(E e1, E e2, E e3, E e4) {
return new ImmutableArray<>(Object.class, e1, e2, e3, e4);
Class<E> commonType = ClassUtils.commonType(e1, e2, e3, e4);
return new ImmutableArray<>(commonType, e1, e2, e3, e4);
}

static <E> Array<E> of(E e1, E e2, E e3, E e4, E e5) {
Class<E> commonType = ClassUtils.commonType(e1, e2, e3, e4, e5);
return new ImmutableArray<>(commonType, e1, e2, e3, e4, e5);
}

static <E> Array<E> of(E e1, E e2, E e3, E e4, E e5, E e6) {
Class<E> commonType = ClassUtils.commonType(e1, e2, e3, e4, e5, e6);
return new ImmutableArray<>(commonType, e1, e2, e3, e4, e5, e6);
}

@SafeVarargs
static <E> Array<E> of(E... elements) {
//noinspection unchecked
Class<E> type = (Class<E>) elements
.getClass()
.getComponentType();
return new ImmutableArray<>(type, elements);
}

@SafeVarargs
Expand All @@ -51,7 +77,21 @@ static <E> Array<E> optionals(Class<? super E> type, Optional<E>... elements) {
.collect(ArrayCollectors.toArray(type));
}

static <E> Array<E> copyOf(MutableArray<E> array) {
/**
* Creates array with the same element repeated 'count' times
*/
static <E> Array<E> repeated(E element, int count) {
@SuppressWarnings("unchecked")
Class<E> type = (Class<E>) element.getClass();
E[] array = ArrayUtils.create(type, count);
Arrays.fill(array, element);
return ImmutableArray.trustWrap(array);
}

static <E> Array<E> copyOf(Array<E> array) {
if (array instanceof ImmutableArray<E>) {
return array;
}
return new ImmutableArray<>(array.type(), array.toArray());
}

Expand Down Expand Up @@ -203,8 +243,6 @@ default Iterator<E> iterator() {
*/
Stream<E> stream();

ReversedArrayIterationFunctions<E> reversedIterations();

ArrayIterationFunctions<E> iterations();

UnsafeArray<E> asUnsafe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

public interface ArrayIterationFunctions<E> {

ReversedArgsArrayIterationFunctions<E> reversedArgs();

@Nullable
<A> E findAny(A arg1, BiPredicate<? super E, A> filter);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package javasabr.rlib.collections.array;

import java.io.Serializable;
import java.util.Arrays;
import java.util.RandomAccess;
import java.util.stream.IntStream;
import javasabr.rlib.collections.array.impl.ImmutableIntArray;
Expand Down Expand Up @@ -40,12 +41,20 @@ static IntArray copyOf(IntArray intArray) {
return new ImmutableIntArray(intArray.toArray());
}

static IntArray repeated(int value, int count) {
int[] values = new int[count];
Arrays.fill(values, value);
return new ImmutableIntArray(values);
}

int size();

boolean contains(int value);

boolean containsAll(IntArray array);

boolean containsAll(int[] array);

/**
* @return the first element or {@link java.util.NoSuchElementException}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package javasabr.rlib.collections.array;

import java.io.Serializable;
import java.util.Arrays;
import java.util.RandomAccess;
import java.util.stream.LongStream;
import javasabr.rlib.collections.array.impl.ImmutableLongArray;
Expand Down Expand Up @@ -40,12 +41,20 @@ static LongArray copyOf(LongArray intArray) {
return new ImmutableLongArray(intArray.toArray());
}

static LongArray repeated(long value, int count) {
long[] values = new long[count];
Arrays.fill(values, value);
return new ImmutableLongArray(values);
}

int size();

boolean contains(long value);

boolean containsAll(LongArray array);

boolean containsAll(long[] array);

/**
* @return the first element or {@link java.util.NoSuchElementException}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ public interface MutableIntArray extends IntArray {
/**
* @return the element previously at the specified position
*/
int removeByInex(int index);
int removeByIndex(int index);

boolean remove(int value);

boolean removeAll(IntArray array);

boolean removeAll(int[] array);

void replace(int index, int value);

void clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ public interface MutableLongArray extends LongArray {
/**
* @return the element previously at the specified position
*/
long removeByInex(int index);
long removeByIndex(int index);

boolean remove(long value);

boolean removeAll(LongArray array);

boolean removeAll(long[] array);

void replace(int index, long value);

void clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import javasabr.rlib.functions.TriConsumer;
import org.jspecify.annotations.Nullable;

public interface ReversedArrayIterationFunctions<E> {
public interface ReversedArgsArrayIterationFunctions<E> {

@Nullable
<A> E findAny(A arg1, BiPredicate<A, ? super E> filter);

<A> ReversedArrayIterationFunctions<E> forEach(A arg1, BiConsumer<A, ? super E> consumer);
<A> ReversedArgsArrayIterationFunctions<E> forEach(A arg1, BiConsumer<A, ? super E> consumer);

<A, B> ReversedArrayIterationFunctions<E> forEach(A arg1, B arg2, TriConsumer<A, B, ? super E> consumer);
<A, B> ReversedArgsArrayIterationFunctions<E> forEach(A arg1, B arg2, TriConsumer<A, B, ? super E> consumer);

<A> boolean anyMatch(A arg1, BiPredicate<A, ? super E> filter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.function.Function;
import javasabr.rlib.collections.array.Array;
import javasabr.rlib.collections.array.ArrayIterationFunctions;
import javasabr.rlib.collections.array.ReversedArrayIterationFunctions;
import javasabr.rlib.collections.array.UnsafeArray;
import javasabr.rlib.common.util.ArrayUtils;
import javasabr.rlib.common.util.ClassUtils;
Expand Down Expand Up @@ -174,13 +173,13 @@ public void forEach(Consumer<? super E> action) {
}

@Override
public ReversedArrayIterationFunctions<E> reversedIterations() {
return new DefaultReversedArrayIterationFunctions<>(this);
public ArrayIterationFunctions<E> iterations() {
return createIterations();
}

@Override
public ArrayIterationFunctions<E> iterations() {
return new DefaultArrayIterationFunctions<>(this);
protected ArrayIterationFunctions<E> createIterations() {
return new DefaultArrayIterationFunctions<>(this,
new DefaultReversedArgsArrayIterationFunctions<>(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.NoSuchElementException;
import javasabr.rlib.collections.array.IntArray;
import javasabr.rlib.collections.array.UnsafeIntArray;
import javasabr.rlib.common.util.ArrayUtils;
import lombok.AccessLevel;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
Expand Down Expand Up @@ -63,10 +64,7 @@ public boolean containsAll(IntArray array) {
return false;
}

int[] wrapped = array
.asUnsafe()
.wrapped();

int[] wrapped = array.asUnsafe().wrapped();
for (int i = 0, length = array.size(); i < length; i++) {
if (!contains(wrapped[i])) {
return false;
Expand All @@ -76,6 +74,19 @@ public boolean containsAll(IntArray array) {
return true;
}

@Override
public boolean containsAll(int[] array) {
if (array.length < 1) {
return false;
}
for (int value : array) {
if (!contains(value)) {
return false;
}
}
return true;
}

@Override
public int indexOf(int value) {
int[] wrapped = wrapped();
Expand Down Expand Up @@ -110,32 +121,28 @@ public int[] toArray() {

@Override
public boolean equals(Object another) {

if (!(another instanceof IntArray array)) {
return false;
}

int[] wrapped = array
.asUnsafe()
.wrapped();

int[] wrapped = array.asUnsafe().wrapped();
return Arrays.equals(wrapped(), 0, size(), wrapped, 0, array.size());
}

@Override
public int hashCode() {

int[] wrapped = wrapped();

int result = 1;

for (int i = 0, wrappedLength = size(); i < wrappedLength; i++) {
result = 31 * result + wrapped[i];
}

return result;
}

@Override
public String toString() {
return ArrayUtils.toString(wrapped(), 0, size(), ",", false, true);
}

@Override
public UnsafeIntArray asUnsafe() {
return this;
Expand Down
Loading
Loading