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
24 changes: 19 additions & 5 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ on:

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read

contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand All @@ -30,14 +30,28 @@ jobs:
- name: Run tests for all modules
run: ./gradlew test

dependency-submission:
- name: Generate jacoco reports
run: ./gradlew jacocoTestReport

- name: Generate aggregated jacoco report
run: ./gradlew test-coverage:testCodeCoverageReport

- name: Add coverage to PR
id: jacoco
uses: madrapps/jacoco-report@v1.7.2
with:
paths: ${{ github.workspace }}/test-coverage/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60

dependency-submission:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand Down
13 changes: 12 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.version = "9.10.0"
rootProject.version = "10.0.alpha"
group = 'javasabr.rlib'

subprojects {
Expand All @@ -8,6 +8,8 @@ subprojects {
}

apply plugin: "java-library"
apply plugin: "jacoco"
apply plugin: "jacoco-report-aggregation"
apply plugin: "java-test-fixtures"
apply plugin: 'maven-publish'

Expand Down Expand Up @@ -119,6 +121,15 @@ subprojects {
tasks.withType(Test).configureEach {
maxParallelForks = Runtime.runtime.availableProcessors()
}

jacocoTestReport {
dependsOn test
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
}
}

wrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import javasabr.rlib.collections.array.Array;
import javasabr.rlib.collections.array.ArrayFactory;
import javasabr.rlib.collections.array.MutableArray;
import javasabr.rlib.common.util.ArrayUtils;
import javasabr.rlib.io.impl.ReuseBytesInputStream;
import javasabr.rlib.io.impl.ReuseBytesOutputStream;
import javasabr.rlib.common.util.ArrayUtils;
import javasabr.rlib.io.util.IoUtils;
import javasabr.rlib.logger.api.Logger;
import javasabr.rlib.logger.api.LoggerManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.RandomAccess;
import java.util.function.Function;
Expand Down Expand Up @@ -203,4 +204,6 @@ default Iterator<E> iterator() {
ArrayIterationFunctions<E> iterations();

UnsafeArray<E> asUnsafe();

List<E> toList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ static IntArray of(int... elements) {
return new ImmutableIntArray(elements);
}

static IntArray copyOf(IntArray intArray) {
return new ImmutableIntArray(intArray.toArray());
}

int size();

boolean contains(int value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package javasabr.rlib.collections.array;

import javasabr.rlib.collections.operation.LockableSource;
import javasabr.rlib.common.util.ThreadSafe;
import javasabr.rlib.common.ThreadSafe;

public interface LockableArray<E> extends MutableArray<E>, LockableSource, ThreadSafe {
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ static LongArray of(long... elements) {
return new ImmutableLongArray(elements);
}

static LongArray copyOf(LongArray intArray) {
return new ImmutableLongArray(intArray.toArray());
}

int size();

boolean contains(long value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import javasabr.rlib.collections.array.Array;
Expand Down Expand Up @@ -246,4 +247,12 @@ public int hashCode() {
public UnsafeArray<E> asUnsafe() {
return this;
}

@Override
public List<E> toList() {
if (isEmpty()) {
return List.of();
}
return List.of(Arrays.copyOf(wrapped(), size()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.concurrent.atomic.AtomicReference;
import javasabr.rlib.collections.array.Array;
import javasabr.rlib.collections.array.UnsafeMutableArray;
import javasabr.rlib.common.ThreadSafe;
import javasabr.rlib.common.util.ArrayUtils;
import javasabr.rlib.common.util.ThreadSafe;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import org.jspecify.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package javasabr.rlib.collections.dictionary;

import java.util.Collection;
import java.util.Optional;
import javasabr.rlib.collections.array.Array;
import javasabr.rlib.collections.array.MutableArray;
Expand All @@ -26,10 +27,14 @@ public interface Dictionary<K, V> extends Iterable<V> {
@Nullable
V getOrDefault(K key, V def);

<C extends Collection<K>> C keys(C container);

MutableArray<K> keys(MutableArray<K> container);

Array<K> keys(Class<K> type);

<C extends Collection<V>> C values(C container);

MutableArray<V> values(MutableArray<V> container);

Array<V> values(Class<V> type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ static class CollectorImpl<T, A, R> implements Collector<T, A, R> {
}
}

public static <T, K, U> Collector<T, MutableRefDictionary<K, T>, RefDictionary<K, T>> toRefDictionary(
public static <T, K, U> Collector<T, MutableRefToRefDictionary<K, T>, RefToRefDictionary<K, T>> toRefToRefDictionary(
Function<? super T, ? extends K> keyMapper) {
return new CollectorImpl<>(
DictionaryFactory::mutableRefDictionary,
DictionaryFactory::mutableRefToRefDictionary,
uniqKeysAccumulator(keyMapper, Function.identity()),
MutableRefDictionary::append,
MutableRefDictionary::toReadOnly,
MutableRefToRefDictionary::append,
MutableRefToRefDictionary::toReadOnly,
CH_ID);
}

public static <T, K, U> Collector<T, MutableRefDictionary<K, U>, RefDictionary<K, U>> toRefDictionary(
public static <T, K, U> Collector<T, MutableRefToRefDictionary<K, U>, RefToRefDictionary<K, U>> toRefToRefDictionary(
Function<? super T, ? extends K> keyMapper,
Function<? super T, ? extends U> valueMapper) {
return new CollectorImpl<>(
DictionaryFactory::mutableRefDictionary,
DictionaryFactory::mutableRefToRefDictionary,
uniqKeysAccumulator(keyMapper, valueMapper),
MutableRefDictionary::append,
MutableRefDictionary::toReadOnly,
MutableRefToRefDictionary::append,
MutableRefToRefDictionary::toReadOnly,
CH_ID);
}

private static <T, K, V> BiConsumer<MutableRefDictionary<K, V>, T> uniqKeysAccumulator(
private static <T, K, V> BiConsumer<MutableRefToRefDictionary<K, V>, T> uniqKeysAccumulator(
Function<? super T, ? extends K> keyMapper,
Function<? super T, ? extends V> valueMapper) {
return (map, element) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
package javasabr.rlib.collections.dictionary;

import javasabr.rlib.collections.dictionary.impl.DefaultMutableHashBasedRefDictionary;
import javasabr.rlib.collections.dictionary.impl.StampedLockBasedHashBasedRefDictionary;
import javasabr.rlib.collections.dictionary.impl.DefaultMutableHashBasedIntToRefDictionary;
import javasabr.rlib.collections.dictionary.impl.DefaultMutableHashBasedLongToRefDictionary;
import javasabr.rlib.collections.dictionary.impl.DefaultMutableHashBasedRefToRefDictionary;
import javasabr.rlib.collections.dictionary.impl.StampedLockBasedHashBasedRefToRefDictionary;
import lombok.experimental.UtilityClass;

@UtilityClass
public class DictionaryFactory {
public static <K, V> MutableRefDictionary<K, V> mutableRefDictionary() {
return new DefaultMutableHashBasedRefDictionary<>();
public static <K, V> MutableRefToRefDictionary<K, V> mutableRefToRefDictionary() {
return new DefaultMutableHashBasedRefToRefDictionary<>();
}

public static <K, V> MutableRefDictionary<K, V> mutableRefDictionary(
public static <V> MutableIntToRefDictionary<V> mutableIntToRefDictionary() {
return new DefaultMutableHashBasedIntToRefDictionary<>();
}

public static <V> MutableLongToRefDictionary<V> mutableLongToRefDictionary() {
return new DefaultMutableHashBasedLongToRefDictionary<>();
}

public static <K, V> MutableRefToRefDictionary<K, V> mutableRefToRefDictionary(
Class<? super K> keyType,
Class<? super V> valueType) {
return new DefaultMutableHashBasedRefDictionary<>();
return new DefaultMutableHashBasedRefToRefDictionary<>();
}

public static <K, V> LockableRefDictionary<K, V> stampedLockBasedRefDictionary() {
return new StampedLockBasedHashBasedRefDictionary<>();
public static <K, V> LockableRefToRefDictionary<K, V> stampedLockBasedRefToRefDictionary() {
return new StampedLockBasedHashBasedRefToRefDictionary<>();
}

public static <K, V> LockableRefDictionary<K, V> stampedLockBasedRefDictionary(
public static <K, V> LockableRefToRefDictionary<K, V> stampedLockBasedRefToRefDictionary(
Class<? super K> keyType,
Class<? super V> valueType) {
return new StampedLockBasedHashBasedRefDictionary<>();
return new StampedLockBasedHashBasedRefToRefDictionary<>();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package javasabr.rlib.collections.dictionary;

public interface HashEntry<K, V> extends Entry<K, V> {
public interface HashEntry {
int hash();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package javasabr.rlib.collections.dictionary;

import java.util.Optional;
import javasabr.rlib.collections.array.IntArray;
import javasabr.rlib.collections.array.MutableIntArray;
import javasabr.rlib.collections.dictionary.impl.ImmutableHashBasedIntToRefDictionary;
import javasabr.rlib.collections.dictionary.impl.SimpleIntToRefEntry;
import javasabr.rlib.functions.IntObjConsumer;
import org.jspecify.annotations.Nullable;

public interface IntToRefDictionary<V> extends Dictionary<Integer, V> {

static <V> IntToRefEntry<V> entry(int key, @Nullable V value) {
return new SimpleIntToRefEntry<>(key, value);
}

static <V> IntToRefDictionary<V> empty() {
return ImmutableHashBasedIntToRefDictionary.empty();
}

static <K, V> IntToRefDictionary<V> of(int key, @Nullable V value) {
return ofEntries(entry(key, value));
}

static <K, V> IntToRefDictionary<V> of(int k1, @Nullable V v1, int k2, @Nullable V v2) {
return ofEntries(entry(k1, v1), entry(k2, v2));
}

@SafeVarargs
static <K, V> IntToRefDictionary<V> ofEntries(IntToRefEntry<V>... entries) {
MutableIntToRefDictionary<V> mutable = DictionaryFactory.mutableIntToRefDictionary();
for (var entry : entries) {
mutable.put(entry.key(), entry.value());
}
return mutable.toReadOnly();
}

boolean containsKey(int key);

@Nullable
V get(int key);

Optional<V> getOptional(int key);

@Nullable
V getOrDefault(int key, V def);

MutableIntArray keys(MutableIntArray container);

IntArray keys();

void forEach(IntObjConsumer<V> consumer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package javasabr.rlib.collections.dictionary;

public interface IntToRefEntry<V> extends RefEntry<V> {

int key();
void key(int key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.jspecify.annotations.Nullable;

public interface LinkedEntry<K, V, N> extends Entry<K, V> {
public interface LinkedEntry<N> {
@Nullable
N next();
void next(@Nullable N next);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package javasabr.rlib.collections.dictionary;

public interface LinkedHashEntry<K, V, N extends LinkedHashEntry<K, V, N>>
extends LinkedEntry<K, V, N>, HashEntry<K, V> {
extends LinkedEntry<N>, HashEntry, RefToRefEntry<K, V> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package javasabr.rlib.collections.dictionary;

public interface LinkedHashIntToRefEntry<V, N extends LinkedHashIntToRefEntry<V, N>>
extends LinkedEntry<N>, HashEntry, IntToRefEntry<V> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package javasabr.rlib.collections.dictionary;

public interface LinkedHashLongToRefEntry<V, N extends LinkedHashLongToRefEntry<V, N>>
extends LinkedEntry<N>, HashEntry, LongToRefEntry<V> {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package javasabr.rlib.collections.dictionary;

import javasabr.rlib.collections.operation.LockableOperations;
import javasabr.rlib.collections.operation.LockableSource;
import javasabr.rlib.common.ThreadSafe;

public interface LockableRefToRefDictionary<K, V> extends MutableRefToRefDictionary<K, V>,
LockableSource, ThreadSafe {

LockableOperations<LockableRefToRefDictionary<K, V>> operations();
}
Loading
Loading