Skip to content

Commit f32c618

Browse files
committed
fix code review comments
1 parent 5689570 commit f32c618

9 files changed

Lines changed: 27 additions & 27 deletions

rlib-collections/src/main/java/javasabr/rlib/collections/dictionary/MutableIntToRefDictionary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static <V> MutableIntToRefDictionary<V> ofTypes(Class<V> valueType) {
2626
V put(int key, V value);
2727

2828
/**
29-
* @return the previous value associated with the specified key, or null if there was no mapping for the key.
29+
* @return the existing value if the key is already present, or null if the key was absent and the new mapping was added.
3030
*/
3131
@Nullable
3232
V putIfAbsent(int key, V value);

rlib-collections/src/main/java/javasabr/rlib/collections/dictionary/MutableLongToRefDictionary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static <V> MutableLongToRefDictionary<V> ofTypes(Class<V> valueType) {
2626
V put(long key, V value);
2727

2828
/**
29-
* @return the previous value associated with the specified key, or null if there was no mapping for the key.
29+
* @return the existing value if the key is already present, or null if the key was absent and the new mapping was added.
3030
*/
3131
@Nullable
3232
V putIfAbsent(long key, V value);

rlib-collections/src/main/java/javasabr/rlib/collections/dictionary/MutableRefToRefDictionary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static <K, V> MutableRefToRefDictionary<K, V> ofTypes(
2727
V put(K key, V value);
2828

2929
/**
30-
* @return the previous value associated with the specified key, or null if there was no mapping for the key.
30+
* @return the existing value if the key is already present, or null if the key was absent and the new mapping was added.
3131
*/
3232
@Nullable
3333
V putIfAbsent(K key, V value);

rlib-collections/src/main/java/javasabr/rlib/collections/dictionary/impl/AbstractMutableHashBasedIntToRefDictionary.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public V putIfAbsent(int key, V value) {
9494

9595
for (E entry = entries[entryIndex]; entry != null; entry = entry.next()) {
9696
if (entry.hash() == hash && key == entry.key()) {
97-
return null;
97+
return entry.value();
9898
}
9999
}
100100

@@ -144,25 +144,25 @@ public boolean remove(int key, V expectedValue) {
144144
int hash = hash(key);
145145
int entryIndex = indexFor(hash, entries.length);
146146

147-
E previosEntry = entries[entryIndex];
148-
E entry = previosEntry;
147+
E previousEntry = entries[entryIndex];
148+
E entry = previousEntry;
149149

150150
while (entry != null) {
151151
E nextEntry = entry.next();
152152
if (entry.hash() == hash && key == entry.key()) {
153153
if (Objects.equals(entry.value(), expectedValue)) {
154154
decrementSize();
155-
if (previosEntry == entry) {
155+
if (previousEntry == entry) {
156156
entries[entryIndex] = nextEntry;
157157
} else {
158-
previosEntry.next(nextEntry);
158+
previousEntry.next(nextEntry);
159159
}
160160
return true;
161161
} else {
162162
return false;
163163
}
164164
}
165-
previosEntry = entry;
165+
previousEntry = entry;
166166
entry = nextEntry;
167167
}
168168

rlib-collections/src/main/java/javasabr/rlib/collections/dictionary/impl/AbstractMutableHashBasedLongToRefDictionary.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public V putIfAbsent(long key, V value) {
9494

9595
for (E entry = entries[entryIndex]; entry != null; entry = entry.next()) {
9696
if (entry.hash() == hash && key == entry.key()) {
97-
return null;
97+
return entry.value();
9898
}
9999
}
100100

@@ -144,25 +144,25 @@ public boolean remove(long key, V expectedValue) {
144144
int hash = hash(Long.hashCode(key));
145145
int entryIndex = indexFor(hash, entries.length);
146146

147-
E previosEntry = entries[entryIndex];
148-
E entry = previosEntry;
147+
E previousEntry = entries[entryIndex];
148+
E entry = previousEntry;
149149

150150
while (entry != null) {
151151
E nextEntry = entry.next();
152152
if (entry.hash() == hash && key == entry.key()) {
153153
if (Objects.equals(entry.value(), expectedValue)) {
154154
decrementSize();
155-
if (previosEntry == entry) {
155+
if (previousEntry == entry) {
156156
entries[entryIndex] = nextEntry;
157157
} else {
158-
previosEntry.next(nextEntry);
158+
previousEntry.next(nextEntry);
159159
}
160160
return true;
161161
} else {
162162
return false;
163163
}
164164
}
165-
previosEntry = entry;
165+
previousEntry = entry;
166166
entry = nextEntry;
167167
}
168168

rlib-collections/src/main/java/javasabr/rlib/collections/dictionary/impl/AbstractMutableHashBasedRefToRefDictionary.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public V putIfAbsent(K key, V value) {
9393

9494
for (E entry = entries[entryIndex]; entry != null; entry = entry.next()) {
9595
if (entry.hash() == hash && key.equals(entry.key())) {
96-
return null;
96+
return entry.value();
9797
}
9898
}
9999

@@ -143,25 +143,25 @@ public boolean remove(K key, V expectedValue) {
143143
int hash = hash(key.hashCode());
144144
int entryIndex = indexFor(hash, entries.length);
145145

146-
E previosEntry = entries[entryIndex];
147-
E entry = previosEntry;
146+
E previousEntry = entries[entryIndex];
147+
E entry = previousEntry;
148148

149149
while (entry != null) {
150150
E nextEntry = entry.next();
151151
if (entry.hash() == hash && key.equals(entry.key())) {
152152
if (Objects.equals(entry.value(), expectedValue)) {
153153
decrementSize();
154-
if (previosEntry == entry) {
154+
if (previousEntry == entry) {
155155
entries[entryIndex] = nextEntry;
156156
} else {
157-
previosEntry.next(nextEntry);
157+
previousEntry.next(nextEntry);
158158
}
159159
return true;
160160
} else {
161161
return false;
162162
}
163163
}
164-
previosEntry = entry;
164+
previousEntry = entry;
165165
entry = nextEntry;
166166
}
167167

rlib-collections/src/test/java/javasabr/rlib/collections/dictionary/MutableIntToRefDictionaryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ void shouldPutIfAbsentNewPairs(MutableIntToRefDictionary<String> dictionary) {
4343
String result2 = dictionary.putIfAbsent(4, "val4_1");
4444
String result3 = dictionary.putIfAbsent(44, "val44");
4545
// then:
46-
assertThat(result1).isNull();
47-
assertThat(result2).isNull();
46+
assertThat(result1).isEqualTo("val1");
47+
assertThat(result2).isEqualTo("val4");
4848
assertThat(result3).isNull();
4949
assertThat(dictionary.get(1)).isEqualTo("val1");
5050
assertThat(dictionary.get(4)).isEqualTo("val4");

rlib-collections/src/test/java/javasabr/rlib/collections/dictionary/MutableLongToRefDictionaryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ void shouldPutIfAbsentNewPairs(MutableLongToRefDictionary<String> dictionary) {
4343
String result2 = dictionary.putIfAbsent(4, "val4_1");
4444
String result3 = dictionary.putIfAbsent(44, "val44");
4545
// then:
46-
assertThat(result1).isNull();
47-
assertThat(result2).isNull();
46+
assertThat(result1).isEqualTo("val1");
47+
assertThat(result2).isEqualTo("val4");
4848
assertThat(result3).isNull();
4949
assertThat(dictionary.get(1)).isEqualTo("val1");
5050
assertThat(dictionary.get(4)).isEqualTo("val4");

rlib-collections/src/test/java/javasabr/rlib/collections/dictionary/MutableRefToRefDictionaryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ void shouldPutIfAbsentNewPairs(MutableRefToRefDictionary<String, String> diction
4343
String result2 = dictionary.putIfAbsent("key4", "val4_1");
4444
String result3 = dictionary.putIfAbsent("key44", "val44");
4545
// then:
46-
assertThat(result1).isNull();
47-
assertThat(result2).isNull();
46+
assertThat(result1).isEqualTo("val1");
47+
assertThat(result2).isEqualTo("val4");
4848
assertThat(result3).isNull();
4949
assertThat(dictionary.get("key1")).isEqualTo("val1");
5050
assertThat(dictionary.get("key4")).isEqualTo("val4");

0 commit comments

Comments
 (0)