Skip to content
Open

#1 #2

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
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ final class BasicMapN<K, V> extends BasicConstMap<K, V> {
if (Objects.equals(value, values[index])) {
return this;
}
return new BasicMapN<>(keys, replace(values, index, value));
return new BasicMapN<>(keys, BasicTools.replace(values, index, value));
}
final int length = keys.length;
return new BasicMapN<>(insert(keys, length, key), insert(values, length, value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private int indexOf(Object o) {
if (Objects.equals(value, values[index])) {
return this;
}
return new BasicSortedMapN<>(comparator, keys, replace(values, index, value));
return new BasicSortedMapN<>(comparator, keys, BasicTools.replace(values, index, value));
}
index = flip(index);
return new BasicSortedMapN<>(comparator, insert(keys, index, key), insert(values, index, value));
Expand Down
21 changes: 21 additions & 0 deletions core/src/main/java/net/nullschool/reflect/LateTypeVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import net.nullschool.util.ArrayTools;

import java.lang.annotation.Annotation;
import java.lang.reflect.*;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -152,4 +153,24 @@ private boolean equals(TypeVariable<?> that) {
@Override public String toString() {
return name;
}

@Override
public AnnotatedType[] getAnnotatedBounds() {
throw new UnsupportedOperationException("not yet implemented");
}

@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
throw new UnsupportedOperationException("not yet implemented");
}

@Override
public Annotation[] getAnnotations() {
throw new UnsupportedOperationException("not yet implemented");
}

@Override
public Annotation[] getDeclaredAnnotations() {
throw new UnsupportedOperationException("not yet implemented");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.*;

import static java.util.Collections.reverseOrder;
import static org.junit.Assert.*;


Expand All @@ -44,7 +43,7 @@ public static final class NullSafeReverseComparator<T> implements Comparator<T>
if (left == null) {
return right == null ? 0 : 1;
}
return right == null ? -1 : reverseOrder().compare(left, right);
return right == null ? -1 : Collections.reverseOrder().compare(left, right);
}
@Override public boolean equals(Object obj) { return obj instanceof NullSafeReverseComparator; }
@Override public int hashCode() { return 1; }
Expand Down Expand Up @@ -402,8 +401,8 @@ private static <E> void compare_ranges(SortedSet<E> expected, SortedSet<E> actua
}

@SafeVarargs
public static <X, E> void compare_sorted_sets(SortedSet<X> expectedSet, SortedSet<E> actual, E... rangePoints) {
@SuppressWarnings("unchecked") SortedSet<E> expected = (SortedSet<E>)expectedSet;
public static <X> void compare_sorted_sets(SortedSet<X> expectedSet, SortedSet<X> actual, X... rangePoints) {
SortedSet<X> expected = expectedSet;
compare_sets(expected, actual);
assertEquals(expected.comparator(), actual.comparator());

Expand All @@ -422,7 +421,7 @@ public static <X, E> void compare_sorted_sets(SortedSet<X> expectedSet, SortedSe

if (expected.size() > 1) {
// Compare the tail sets of everything from the second item onwards.
E from = nth(expected, 1);
X from = nth(expected, 1);
compare_sorted_sets(expected.tailSet(from), actual.tailSet(from));
}
}
Expand Down Expand Up @@ -548,9 +547,8 @@ private static <K, V> void compare_ranges(SortedMap<K, V> expected, SortedMap<K,
}
}

@SafeVarargs
public static <XK, XV, K, V> void compare_sorted_maps(
SortedMap<XK, XV> expectedMap,
public static <K, V> void compare_sorted_maps(
SortedMap<K, V> expectedMap,
SortedMap<K, V> actual,
K... rangePoints) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package net.nullschool.collect.basic;

import net.nullschool.collect.CollectionTestingTools;
import net.nullschool.collect.ConstSortedMap;
import net.nullschool.reflect.PublicInterfaceRef;
import org.junit.Test;
Expand Down Expand Up @@ -126,27 +127,27 @@ public void test_construction_permutations_reverse() {

@Test
public void test_sortedMapOf() {
compare_sorted_maps(newSortedMap(null, "a", 1), sortedMapOf(null, "a", 1));
compare_sorted_maps(newSortedMap(null, "a", 1, "b", 2), sortedMapOf(null, "a", 1, "b", 2));
compare_sorted_maps(newSortedMap(null, "a", 1, "b", 2, "c", 3), sortedMapOf(null, "a", 1, "b", 2, "c", 3));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<String, Integer>newSortedMap(null, "a", 1), BasicCollections.sortedMapOf(null, "a", 1));
compare_sorted_maps(CollectionTestingTools.<String, Integer>newSortedMap(null, "a", 1, "b", 2), sortedMapOf(null, "a", 1, "b", 2));
compare_sorted_maps(CollectionTestingTools.<String, Integer>newSortedMap(null, "a", 1, "b", 2, "c", 3), sortedMapOf(null, "a", 1, "b", 2, "c", 3));
compare_sorted_maps(CollectionTestingTools.<String, Integer>
newSortedMap(null, "a", 1, "b", 2, "c", 3, "d", 4),
sortedMapOf(null, "a", 1, "b", 2, "c", 3, "d", 4));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<String, Integer>
newSortedMap(null, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5),
sortedMapOf(null, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5));

Comparator<Object> reverse = new NullSafeReverseComparator<>();

compare_sorted_maps(newSortedMap(reverse, "a", 1), sortedMapOf(reverse, "a", 1));
compare_sorted_maps(newSortedMap(reverse, "a", 1, "b", 2), sortedMapOf(reverse, "a", 1, "b", 2));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<String, Integer>newSortedMap(reverse, "a", 1), sortedMapOf(reverse, "a", 1));
compare_sorted_maps(CollectionTestingTools.<String, Integer>newSortedMap(reverse, "a", 1, "b", 2), sortedMapOf(reverse, "a", 1, "b", 2));
compare_sorted_maps(CollectionTestingTools.<String, Integer>
newSortedMap(reverse, "a", 1, "b", 2, "c", 3),
sortedMapOf(reverse, "a", 1, "b", 2, "c", 3));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<String, Integer>
newSortedMap(reverse, "a", 1, "b", 2, "c", 3, "d", 4),
sortedMapOf(reverse, "a", 1, "b", 2, "c", 3, "d", 4));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<String, Integer>
newSortedMap(reverse, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5),
sortedMapOf(reverse, "a", 1, "b", 2, "c", 3, "d", 4, "e", 5));

Expand Down Expand Up @@ -178,48 +179,48 @@ public void test_sortedMapOf_types() {
public void test_asSortedMap_array() {
Integer[] a;
assertSame(emptySortedMap(null), asSortedMap(null, a = new Integer[] {}, a));
compare_sorted_maps(newSortedMap(null, 1, 1), asSortedMap(null, a = new Integer[] {1}, a));
compare_sorted_maps(newSortedMap(null, 1, 1, 2, 2), asSortedMap(null, a = new Integer[] {1, 2}, a));
compare_sorted_maps(newSortedMap(null, 1, 1, 2, 2, 3, 3), asSortedMap(null, a = new Integer[] {1, 2, 3}, a));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>newSortedMap(null, 1, 1), asSortedMap(null, a = new Integer[] {1}, a));
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>newSortedMap(null, 1, 1, 2, 2), asSortedMap(null, a = new Integer[] {1, 2}, a));
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>newSortedMap(null, 1, 1, 2, 2, 3, 3), asSortedMap(null, a = new Integer[] {1, 2, 3}, a));
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(null, 1, 1, 2, 2, 3, 3, 4, 4),
asSortedMap(null, a = new Integer[] {1, 2, 3, 4}, a));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(null, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5),
asSortedMap(null, a = new Integer[] {1, 2, 3, 4, 5}, a));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(null, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6),
asSortedMap(null, a = new Integer[] {1, 2, 3, 4, 5, 6}, a));

compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(null, 1, 1, 2, 2),
asSortedMap(null, new Integer[] {1, 2}, new Integer[] {1, 2, 3}));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(null, 1, 1, 2, 2),
asSortedMap(null, new Integer[] {1, 2, 3}, new Integer[] {1, 2}));

Comparator<Object> reverse = reverseOrder();

compare_sorted_maps(emptySortedMap(reverse), asSortedMap(reverse, a = new Integer[] {}, a));
compare_sorted_maps(newSortedMap(reverse, 1, 1), asSortedMap(reverse, a = new Integer[] {1}, a));
compare_sorted_maps(newSortedMap(reverse, 1, 1, 2, 2), asSortedMap(reverse, a = new Integer[] {1, 2}, a));
compare_sorted_maps(
compare_sorted_maps(BasicCollections.<Integer, Integer>emptySortedMap(reverse), BasicCollections.asSortedMap(reverse, a = new Integer[]{}, a));
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>newSortedMap(reverse, 1, 1), asSortedMap(reverse, a = new Integer[] {1}, a));
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>newSortedMap(reverse, 1, 1, 2, 2), asSortedMap(reverse, a = new Integer[] {1, 2}, a));
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(reverse, 1, 1, 2, 2, 3, 3),
asSortedMap(reverse, a = new Integer[] {1, 2, 3}, a));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(reverse, 1, 1, 2, 2, 3, 3, 4, 4),
asSortedMap(reverse, a = new Integer[] {1, 2, 3, 4}, a));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(reverse, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5),
asSortedMap(reverse, a = new Integer[] {1, 2, 3, 4, 5}, a));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(reverse, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6),
asSortedMap(reverse, a = new Integer[] {1, 2, 3, 4, 5, 6}, a));

compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(reverse, 1, 1, 2, 2),
asSortedMap(reverse, new Integer[] {1, 2}, new Integer[] {1, 2, 3}));
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<Integer, Integer>
newSortedMap(reverse, 1, 1, 2, 2),
asSortedMap(reverse, new Integer[] {1, 2, 3}, new Integer[] {1, 2}));
}
Expand Down Expand Up @@ -326,10 +327,10 @@ public void test_asSortedMap_comparator_map() {

// Calling asSortedMap with a sorted map but different comparator should change the order, and even the size.
ConstSortedMap<String, Integer> names = sortedMapOf(reverse, "a", 1, "B", 2, "b", 3, "c", 4, "C", 5);
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<String, Integer>
newSortedMap(reverse, "c", 4, "b", 3, "a", 1, "C", 5, "B", 2), // before
names);
compare_sorted_maps(
compare_sorted_maps(CollectionTestingTools.<String, Integer>
newSortedMap(CASE_INSENSITIVE_ORDER, "a", 1, "b", 2, "c", 5), // after
asSortedMap(CASE_INSENSITIVE_ORDER, names));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void test_asSortedSet_array() {

Comparator<Object> reverse = reverseOrder();

compare_sorted_sets(emptySortedSet(reverse), asSortedSet(reverse, new Integer[] {}));
compare_sorted_sets(BasicCollections.<Integer>emptySortedSet(reverse), asSortedSet(reverse, new Integer[] {}));
compare_sorted_sets(newSortedSet(reverse, 1), asSortedSet(reverse, new Integer[] {1}));
compare_sorted_sets(newSortedSet(reverse, 1, 2), asSortedSet(reverse, new Integer[] {1, 2}));
compare_sorted_sets(newSortedSet(reverse, 1, 2, 3), asSortedSet(reverse, new Integer[] {1, 2, 3}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void test_serialization_with_comparator() throws Exception {

ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));

ConstSortedMap<?, ?> read = (ConstSortedMap)in.readObject();
ConstSortedMap<Object, Object> read = (ConstSortedMap)in.readObject();
compare_sorted_maps(map, read);
assertSame(map.getClass(), read.getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void test_serialization() throws Exception {

ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));

ConstSortedMap<?, ?> read = (ConstSortedMap)in.readObject();
ConstSortedMap<Object, Object> read = (ConstSortedMap)in.readObject();
compare_sorted_maps(map, read);
assertSame(map.getClass(), read.getClass());
}
Expand All @@ -159,7 +159,7 @@ public void test_serialization_with_comparator() throws Exception {

ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));

ConstSortedMap<?, ?> read = (ConstSortedMap)in.readObject();
ConstSortedMap<Object, Object> read = (ConstSortedMap)in.readObject();
compare_sorted_maps(map, read);
assertSame(map.getClass(), read.getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void test_serialization() throws Exception {

ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));

ConstSortedMap<?, ?> read = (ConstSortedMap)in.readObject();
ConstSortedMap<Object, Object> read = (ConstSortedMap)in.readObject();
compare_sorted_maps(map, read);
assertSame(map.getClass(), read.getClass());
}
Expand All @@ -189,7 +189,7 @@ public void test_serialization_with_comparator() throws Exception {

ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));

ConstSortedMap<?, ?> read = (ConstSortedMap)in.readObject();
ConstSortedMap<Object, Object> read = (ConstSortedMap)in.readObject();
compare_sorted_maps(map, read);
assertSame(map.getClass(), read.getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package net.nullschool.collect.basic;

import net.nullschool.collect.CollectionTestingTools;
import net.nullschool.collect.ConstSortedSet;
import org.junit.Test;

Expand All @@ -39,7 +40,7 @@ public class BasicSortedSet0Test {

@Test
public void test_comparison() {
compare_sorted_sets(newSortedSet(null), BasicSortedSet0.instance(null), -1, 0, 1, 0);
compare_sorted_sets(CollectionTestingTools.<Integer>newSortedSet(null), BasicSortedSet0.<Integer>instance(null), -1, 0, 1, 0);
compare_sorted_sets(newSortedSet(reverseOrder()), BasicSortedSet0.instance(reverseOrder()), 1, 0, -1, 0);
}

Expand All @@ -50,8 +51,8 @@ public void test_immutable() {

@Test
public void test_with() {
compare_sorted_sets(newSortedSet(null, 1), BasicSortedSet0.instance(null).with(1));
compare_sorted_sets(newSortedSet(reverseOrder(), 1), BasicSortedSet0.instance(reverseOrder()).with(1));
compare_sorted_sets(newSortedSet(null, 1), BasicSortedSet0.<Integer>instance(null).with(1));
compare_sorted_sets(newSortedSet(reverseOrder(), 1), BasicSortedSet0.<Integer>instance(reverseOrder()).with(1));
}

@Test
Expand Down Expand Up @@ -128,7 +129,7 @@ public void test_serialization_with_comparator() throws Exception {

ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));

ConstSortedSet<?> read = (ConstSortedSet)in.readObject();
ConstSortedSet<Object> read = (ConstSortedSet)in.readObject();
compare_sorted_sets(set, read);
assertSame(set.getClass(), read.getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.util.Arrays;
import java.util.Collections;

import static org.junit.Assert.*;
import static java.util.Collections.reverseOrder;
import static net.nullschool.collect.CollectionTestingTools.*;
import static java.util.Collections.*;
import static org.junit.Assert.*;

/**
* 2013-04-25<p/>
Expand All @@ -39,8 +39,8 @@ public class BasicSortedSet1Test {

@Test
public void test_comparison() {
compare_sorted_sets(newSortedSet(null, 1), new BasicSortedSet1<>(null, 1), 0, 1, 1, 2, 0);
compare_sorted_sets(newSortedSet(reverseOrder(), 1), new BasicSortedSet1<>(reverseOrder(), 1), 2, 1, 1, 0, 2);
compare_sorted_sets(newSortedSet(null, 1), new BasicSortedSet1<Integer>(null, 1), 0, 1, 1, 2, 0);
compare_sorted_sets(newSortedSet(reverseOrder(), 1), new BasicSortedSet1<Integer>(reverseOrder(), 1), 2, 1, 1, 0, 2);
}

@Test
Expand Down Expand Up @@ -86,11 +86,11 @@ public void test_without() {
ConstSortedSet<Integer> set;

set = new BasicSortedSet1<>(null, 1);
compare_sorted_sets(BasicSortedSet0.instance(null), set.without(1));
compare_sorted_sets(BasicSortedSet0.<Integer>instance(null), set.without(1));
assertSame(set, set.without(2));

set = new BasicSortedSet1<>(reverseOrder(), 1);
compare_sorted_sets(BasicSortedSet0.instance(reverseOrder()), set.without(1));
compare_sorted_sets(BasicSortedSet0.<Integer>instance(reverseOrder()), set.without(1));
assertSame(set, set.without(2));
}

Expand All @@ -99,14 +99,14 @@ public void test_withoutAll() {
ConstSortedSet<Integer> set;

set = new BasicSortedSet1<>(null, 1);
compare_sorted_sets(BasicSortedSet0.instance(null), set.withoutAll(Arrays.asList(1)));
compare_sorted_sets(BasicSortedSet0.instance(null), set.withoutAll(Arrays.asList(2, 1)));
compare_sorted_sets(BasicSortedSet0.<Integer>instance(null), set.withoutAll(Arrays.asList(1)));
compare_sorted_sets(BasicSortedSet0.<Integer>instance(null), set.withoutAll(Arrays.asList(2, 1)));
assertSame(set, set.withoutAll(Arrays.asList(2)));
assertSame(set, set.withoutAll(Arrays.asList()));

set = new BasicSortedSet1<>(reverseOrder(), 1);
compare_sorted_sets(BasicSortedSet0.instance(reverseOrder()), set.withoutAll(Arrays.asList(1)));
compare_sorted_sets(BasicSortedSet0.instance(reverseOrder()), set.withoutAll(Arrays.asList(2, 1)));
compare_sorted_sets(BasicSortedSet0.<Integer>instance(reverseOrder()), set.withoutAll(Arrays.asList(1)));
compare_sorted_sets(BasicSortedSet0.<Integer>instance(reverseOrder()), set.withoutAll(Arrays.asList(2, 1)));
assertSame(set, set.withoutAll(Arrays.asList(2)));
assertSame(set, set.withoutAll(Arrays.asList()));
}
Expand All @@ -131,7 +131,7 @@ public void test_serialization() throws Exception {

ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));

ConstSortedSet<?> read = (ConstSortedSet)in.readObject();
ConstSortedSet<Integer> read = (ConstSortedSet)in.readObject();
compare_sorted_sets(set, read);
assertSame(set.getClass(), read.getClass());
}
Expand All @@ -152,7 +152,7 @@ public void test_serialization_with_comparator() throws Exception {

ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data));

ConstSortedSet<?> read = (ConstSortedSet)in.readObject();
ConstSortedSet<Integer> read = (ConstSortedSet)in.readObject();
compare_sorted_sets(set, read);
assertSame(set.getClass(), read.getClass());
}
Expand Down
Loading