Fixed Unit Test and Added putIfAbsentTest

This commit is contained in:
Speiger 2022-12-08 10:40:21 +01:00
parent 4c52636c23
commit e30d011273
3 changed files with 35 additions and 2 deletions

View File

@ -131,7 +131,8 @@ public class IMMUTABLE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_T
@Override
public KEY_TYPE[] getElements(int from, KEY_TYPE[] a, int offset, int length) {
SanityChecks.checkArrayCapacity(data.length, offset, length);
SanityChecks.checkArrayCapacity(a.length, offset, length);
SanityChecks.checkArrayCapacity(data.length, from, length);
System.arraycopy(data, from, a, offset, length);
return a;
}

View File

@ -5,6 +5,7 @@ import java.util.Collection;
#if !TYPE_BOOLEAN
import java.util.ConcurrentModificationException;
#endif
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
#if TYPE_OBJECT
@ -635,6 +636,27 @@ public class COLLECTIONS
}
};
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Collection))
return false;
Collection<?> l = (Collection<?>)o;
if(l.size() != size()) return false;
Iterator<?> iter = l.iterator();
if (iter.hasNext() && !Objects.equals(element, iter.next())) {
return false;
}
return !iter.hasNext();
}
@Override
public int hashCode() {
return KEY_TO_HASH(element);
}
@Override
public int size() { return 1; }

View File

@ -33,6 +33,16 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapPutIfAbsentTester KEY_VALUE_GENERIC
expectUnchanged();
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
#endignore
public void testPutIfAbsent_replaceableDefaultValue() {
getMap().putIfAbsent(k3(), getMap().getDefaultReturnValue());
assertEquals("get(present) should return defaultValue value", getMap().getDefaultReturnValue(), get(k3()));
getMap().putIfAbsent(k3(), v3());
assertEquals("get(present) value should have been replaced", v3(), get(k3()));
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
#endignore