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 @@ -45,7 +45,7 @@ repositories {
}

ext {
rlibVersion = "10.0.alpha10"
rlibVersion = "10.0.alpha11"
}

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.alpha10"
rootProject.version = "10.0.alpha11"
group = 'javasabr.rlib'

allprojects {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package javasabr.rlib.classpath;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collection;
import javasabr.rlib.collections.array.Array;
import javasabr.rlib.collections.array.impl.AbstractArray;
import javasabr.rlib.logger.api.LoggerLevel;
import javasabr.rlib.logger.api.LoggerManager;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -26,10 +27,10 @@ void testSystemClasspathScanner() {

Array<Class<Collection>> implementations = scanner.findImplementations(Collection.class);

Assertions.assertFalse(implementations.isEmpty());
assertThat(implementations.isEmpty()).isFalse();

Array<Class<AbstractArray>> inherited = scanner.findInherited(AbstractArray.class);

Assertions.assertFalse(inherited.isEmpty());
assertThat(inherited.isEmpty()).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.stream.StreamSupport;
import javasabr.rlib.collections.array.Array;
import javasabr.rlib.collections.array.UnsafeMutableArray;
import javasabr.rlib.common.util.ObjectUtils;
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import org.jspecify.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ static <V> MutableIntToRefDictionary<V> ofTypes(Class<V> valueType) {
@Nullable
V put(int key, V value);

/**
* @return the existing value if the key is already present, or null if the key was absent and the new mapping was added.
*/
@Nullable
V putIfAbsent(int key, V value);

void putAll(IntToRefDictionary<? extends V> dictionary);

MutableIntToRefDictionary<V> append(IntToRefDictionary<? extends V> dictionary);
Expand All @@ -40,6 +46,11 @@ static <V> MutableIntToRefDictionary<V> ofTypes(Class<V> valueType) {
@Nullable
V remove(int key);

/**
* @return true if the expectedValue was removed
*/
boolean remove(int key, V expectedValue);

/**
* @return the optional value of the previous value for the key.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ static <V> MutableLongToRefDictionary<V> ofTypes(Class<V> valueType) {
@Nullable
V put(long key, V value);

/**
* @return the existing value if the key is already present, or null if the key was absent and the new mapping was added.
*/
@Nullable
V putIfAbsent(long key, V value);

void putAll(LongToRefDictionary<? extends V> dictionary);

MutableLongToRefDictionary<V> append(LongToRefDictionary<? extends V> dictionary);
Expand All @@ -40,6 +46,11 @@ static <V> MutableLongToRefDictionary<V> ofTypes(Class<V> valueType) {
@Nullable
V remove(long key);

/**
* @return true if the expectedValue was removed
*/
boolean remove(long key, V expectedValue);

/**
* @return the optional value of the previous value for the key.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ static <K, V> MutableRefToRefDictionary<K, V> ofTypes(
@Nullable
V put(K key, V value);

/**
* @return the existing value if the key is already present, or null if the key was absent and the new mapping was added.
*/
@Nullable
V putIfAbsent(K key, V value);

void putAll(RefToRefDictionary<? extends K, ? extends V> dictionary);

MutableRefToRefDictionary<K, V> append(RefToRefDictionary<? extends K, ? extends V> dictionary);
Expand All @@ -41,6 +47,11 @@ static <K, V> MutableRefToRefDictionary<K, V> ofTypes(
@Nullable
V remove(K key);

/**
* @return true if the expectedValue was removed
*/
boolean remove(K key, V expectedValue);

/**
* @return the optional value of the previous value for the key.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package javasabr.rlib.collections.dictionary.impl;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.IntFunction;
Expand Down Expand Up @@ -84,6 +85,23 @@ public V put(int key, V value) {
return null;
}

@Nullable
@Override
public V putIfAbsent(int key, V value) {
@Nullable E[] entries = entries();
int hash = hash(key);
int entryIndex = indexFor(hash, entries.length);

for (E entry = entries[entryIndex]; entry != null; entry = entry.next()) {
if (entry.hash() == hash && key == entry.key()) {
return entry.value();
}
}

addEntry(hash, key, value, entryIndex);
return null;
}

@Override
public Optional<V> putOptional(int key, V value) {
return Optional.ofNullable(put(key, value));
Expand Down Expand Up @@ -120,6 +138,37 @@ public V remove(int key) {
return removed.value();
}

@Override
public boolean remove(int key, V expectedValue) {
@Nullable E[] entries = entries();
int hash = hash(key);
int entryIndex = indexFor(hash, entries.length);

E previousEntry = entries[entryIndex];
E entry = previousEntry;

while (entry != null) {
E nextEntry = entry.next();
if (entry.hash() == hash && key == entry.key()) {
if (Objects.equals(entry.value(), expectedValue)) {
decrementSize();
if (previousEntry == entry) {
entries[entryIndex] = nextEntry;
} else {
previousEntry.next(nextEntry);
}
return true;
} else {
return false;
}
}
previousEntry = entry;
entry = nextEntry;
}

return false;
}

@Override
public Optional<V> removeOptional(int key) {
return Optional.ofNullable(remove(key));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package javasabr.rlib.collections.dictionary.impl;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.LongFunction;
Expand Down Expand Up @@ -83,7 +84,24 @@ public V put(long key, V value) {
addEntry(hash, key, value, entryIndex);
return null;
}

@Nullable
@Override
public V putIfAbsent(long key, V value) {
@Nullable E[] entries = entries();
int hash = hash(Long.hashCode(key));
int entryIndex = indexFor(hash, entries.length);

for (E entry = entries[entryIndex]; entry != null; entry = entry.next()) {
if (entry.hash() == hash && key == entry.key()) {
return entry.value();
}
}

addEntry(hash, key, value, entryIndex);
return null;
}

@Override
public Optional<V> putOptional(long key, V value) {
return Optional.ofNullable(put(key, value));
Expand Down Expand Up @@ -120,6 +138,37 @@ public V remove(long key) {
return removed.value();
}

@Override
public boolean remove(long key, V expectedValue) {
@Nullable E[] entries = entries();
int hash = hash(Long.hashCode(key));
int entryIndex = indexFor(hash, entries.length);

E previousEntry = entries[entryIndex];
E entry = previousEntry;

while (entry != null) {
E nextEntry = entry.next();
if (entry.hash() == hash && key == entry.key()) {
if (Objects.equals(entry.value(), expectedValue)) {
decrementSize();
if (previousEntry == entry) {
entries[entryIndex] = nextEntry;
} else {
previousEntry.next(nextEntry);
}
return true;
} else {
return false;
}
}
previousEntry = entry;
entry = nextEntry;
}

return false;
}

@Override
public Optional<V> removeOptional(long key) {
return Optional.ofNullable(remove(key));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package javasabr.rlib.collections.dictionary.impl;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -83,6 +84,23 @@ public V put(K key, V value) {
return null;
}

@Nullable
@Override
public V putIfAbsent(K key, V value) {
@Nullable E[] entries = entries();
int hash = hash(key.hashCode());
int entryIndex = indexFor(hash, entries.length);

for (E entry = entries[entryIndex]; entry != null; entry = entry.next()) {
if (entry.hash() == hash && key.equals(entry.key())) {
return entry.value();
}
}

addEntry(hash, key, value, entryIndex);
return null;
}

@Override
public Optional<V> putOptional(K key, V value) {
return Optional.ofNullable(put(key, value));
Expand Down Expand Up @@ -119,6 +137,37 @@ public V remove(K key) {
return removed.value();
}

@Override
public boolean remove(K key, V expectedValue) {
@Nullable E[] entries = entries();
int hash = hash(key.hashCode());
int entryIndex = indexFor(hash, entries.length);

E previousEntry = entries[entryIndex];
E entry = previousEntry;

while (entry != null) {
E nextEntry = entry.next();
if (entry.hash() == hash && key.equals(entry.key())) {
if (Objects.equals(entry.value(), expectedValue)) {
decrementSize();
if (previousEntry == entry) {
entries[entryIndex] = nextEntry;
} else {
previousEntry.next(nextEntry);
}
return true;
} else {
return false;
}
}
previousEntry = entry;
entry = nextEntry;
}

return false;
}

@Override
public Optional<V> removeOptional(K key) {
return Optional.ofNullable(remove(key));
Expand Down
Loading
Loading