mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-31 12:24:10 -08:00
Fix behaviour of collections created with Set.of and Map.of (#534)
This commit is contained in:
parent
605628d6df
commit
b718e7852f
|
@ -201,7 +201,7 @@ class TTemplateCollections {
|
||||||
for (T element : data) {
|
for (T element : data) {
|
||||||
Objects.requireNonNull(element);
|
Objects.requireNonNull(element);
|
||||||
|
|
||||||
int suggestedIndex = element.hashCode() % data.length;
|
int suggestedIndex = Math.abs(element.hashCode()) % data.length;
|
||||||
int index = suggestedIndex;
|
int index = suggestedIndex;
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
while (index < data.length) {
|
while (index < data.length) {
|
||||||
|
@ -268,7 +268,7 @@ class TTemplateCollections {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int suggestedIndex = o.hashCode() % data.length;
|
int suggestedIndex = Math.abs(o.hashCode()) % data.length;
|
||||||
for (int i = suggestedIndex; i < data.length; ++i) {
|
for (int i = suggestedIndex; i < data.length; ++i) {
|
||||||
if (data[i].equals(o)) {
|
if (data[i].equals(o)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -413,16 +413,17 @@ class TTemplateCollections {
|
||||||
private Entry<K, V>[] data;
|
private Entry<K, V>[] data;
|
||||||
private AbstractImmutableSet<Entry<K, V>> entrySet;
|
private AbstractImmutableSet<Entry<K, V>> entrySet;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
NEtriesMap(Entry<K, V>... data) {
|
NEtriesMap(Entry<K, V>... data) {
|
||||||
Entry<K, V>[] table = data.clone();
|
Entry<K, V>[] table = new Entry[data.length];
|
||||||
Arrays.fill(table, null);
|
Arrays.fill(table, null);
|
||||||
|
|
||||||
for (Entry<K, V> entry : data) {
|
for (Entry<K, V> entry : data) {
|
||||||
Objects.requireNonNull(entry.getKey());
|
Objects.requireNonNull(entry.getKey());
|
||||||
Objects.requireNonNull(entry.getValue());
|
Objects.requireNonNull(entry.getValue());
|
||||||
|
|
||||||
int suggestedIndex = entry == null ? 0 : entry.getKey().hashCode() % data.length;
|
int suggestedIndex = Math.abs(entry.getKey().hashCode()) % data.length;
|
||||||
int index = suggestedIndex;
|
int index = suggestedIndex;
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
while (index < data.length) {
|
while (index < data.length) {
|
||||||
|
@ -481,7 +482,7 @@ class TTemplateCollections {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int suggestedIndex = key.hashCode() % data.length;
|
int suggestedIndex = Math.abs(key.hashCode()) % data.length;
|
||||||
for (int i = suggestedIndex; i < data.length; ++i) {
|
for (int i = suggestedIndex; i < data.length; ++i) {
|
||||||
if (data[i].getKey().equals(key)) {
|
if (data[i].getKey().equals(key)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -500,7 +501,7 @@ class TTemplateCollections {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int suggestedIndex = key.hashCode() % data.length;
|
int suggestedIndex = Math.abs(key.hashCode()) % data.length;
|
||||||
for (int i = suggestedIndex; i < data.length; ++i) {
|
for (int i = suggestedIndex; i < data.length; ++i) {
|
||||||
Entry<K, V> entry = data[i];
|
Entry<K, V> entry = data[i];
|
||||||
if (entry.getKey().equals(key)) {
|
if (entry.getKey().equals(key)) {
|
||||||
|
@ -561,7 +562,7 @@ class TTemplateCollections {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int suggestedIndex = key.hashCode() % data.length;
|
int suggestedIndex = Math.abs(key.hashCode()) % data.length;
|
||||||
for (int i = suggestedIndex; i < data.length; ++i) {
|
for (int i = suggestedIndex; i < data.length; ++i) {
|
||||||
Entry<K, V> entry = data[i];
|
Entry<K, V> entry = data[i];
|
||||||
if (entry.getKey().equals(key)) {
|
if (entry.getKey().equals(key)) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user