Skip to content

Commit

Permalink
Merge branch 'master' into chore/build-jdk21
Browse files Browse the repository at this point in the history
  • Loading branch information
sgammon authored Mar 8, 2024
2 parents 29b0b6c + 0b1c477 commit 90cb46e
Show file tree
Hide file tree
Showing 97 changed files with 777 additions and 478 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ jobs:
steps:
# Cancel any previous runs for the same branch that are still running.
- name: 'Cancel previous runs'
uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa
uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # 0.12.1
with:
access_token: ${{ github.token }}
- name: 'Check out repository'
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: 'Set up JDK ${{ matrix.java }}'
uses: actions/setup-java@9704b39bf258b59bc04b50fa2dd55e9ed76b47a8
uses: actions/setup-java@9704b39bf258b59bc04b50fa2dd55e9ed76b47a8 # v4.1.0

with:
java-version: ${{ matrix.java }}
Expand Down Expand Up @@ -67,9 +67,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Check out repository'
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: 'Set up JDK 21'
uses: actions/setup-java@9704b39bf258b59bc04b50fa2dd55e9ed76b47a8
uses: actions/setup-java@9704b39bf258b59bc04b50fa2dd55e9ed76b47a8 # v4.1.0

with:
java-version: 21
Expand All @@ -93,9 +93,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Check out repository'
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: 'Set up JDK 21'
uses: actions/setup-java@9704b39bf258b59bc04b50fa2dd55e9ed76b47a8
uses: actions/setup-java@9704b39bf258b59bc04b50fa2dd55e9ed76b47a8 # v4.1.0

with:
java-version: 21
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: gradle/wrapper-validation-action@699bb18358f12c5b78b37bb0111d3a0e2276e0e2
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: gradle/wrapper-validation-action@699bb18358f12c5b78b37bb0111d3a0e2276e0e2 # v2.1.1
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected abstract <E extends Comparable<? super E>> Set<E> copyOf(
public void testCreation_noArgs() {
Set<String> set = of();
assertEquals(Collections.<String>emptySet(), set);
assertSame(of(), set);
assertSame(this.<String>of(), set);
}

public void testCreation_oneElement() {
Expand Down Expand Up @@ -122,7 +122,7 @@ public void testCopyOf_emptyArray() {
String[] array = new String[0];
Set<String> set = copyOf(array);
assertEquals(Collections.<String>emptySet(), set);
assertSame(of(), set);
assertSame(this.<String>of(), set);
}

public void testCopyOf_arrayOfOneElement() {
Expand Down Expand Up @@ -153,7 +153,7 @@ public void testCopyOf_collection_empty() {
Collection<String> c = MinimalCollection.<String>of();
Set<String> set = copyOf(c);
assertEquals(Collections.<String>emptySet(), set);
assertSame(of(), set);
assertSame(this.<String>of(), set);
}

public void testCopyOf_collection_oneElement() {
Expand Down Expand Up @@ -203,7 +203,7 @@ public void testCopyOf_iterator_empty() {
Iterator<String> iterator = Iterators.emptyIterator();
Set<String> set = copyOf(iterator);
assertEquals(Collections.<String>emptySet(), set);
assertSame(of(), set);
assertSame(this.<String>of(), set);
}

public void testCopyOf_iterator_oneElement() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,12 @@ public void testTransformEntrySetContains() {

Set<Entry<@Nullable String, @Nullable Boolean>> entries = map.entrySet();
assertTrue(entries.contains(Maps.immutableEntry("a", true)));
assertTrue(entries.contains(Maps.immutableEntry("b", (Boolean) null)));
assertTrue(entries.contains(Maps.immutableEntry((String) null, (Boolean) null)));
assertTrue(entries.contains(Maps.<String, @Nullable Boolean>immutableEntry("b", null)));
assertTrue(
entries.contains(Maps.<@Nullable String, @Nullable Boolean>immutableEntry(null, null)));

assertFalse(entries.contains(Maps.immutableEntry("c", (Boolean) null)));
assertFalse(entries.contains(Maps.immutableEntry((String) null, true)));
assertFalse(entries.contains(Maps.<String, @Nullable Boolean>immutableEntry("c", null)));
assertFalse(entries.contains(Maps.<@Nullable String, Boolean>immutableEntry(null, true)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.testing.EqualsTester;
import com.google.common.testing.NullPointerTester;
import junit.framework.TestCase;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Test cases for {@link Table} read operations.
Expand All @@ -33,8 +34,8 @@
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public abstract class AbstractTableReadTest extends TestCase {
protected Table<String, Integer, Character> table;
public abstract class AbstractTableReadTest<C extends @Nullable Character> extends TestCase {
protected Table<String, Integer, C> table;

/**
* Creates a table with the specified data.
Expand All @@ -43,7 +44,7 @@ public abstract class AbstractTableReadTest extends TestCase {
* @throws IllegalArgumentException if the size of {@code data} isn't a multiple of 3
* @throws ClassCastException if a data element has the wrong type
*/
protected abstract Table<String, Integer, Character> create(Object... data);
protected abstract Table<String, Integer, C> create(@Nullable Object... data);

protected void assertSize(int expectedSize) {
assertEquals(expectedSize, table.size());
Expand Down Expand Up @@ -120,14 +121,13 @@ public void testSize() {

public void testEquals() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
Table<String, Integer, Character> hashCopy = HashBasedTable.create(table);
Table<String, Integer, Character> reordered =
create("foo", 3, 'c', "foo", 1, 'a', "bar", 1, 'b');
Table<String, Integer, Character> smaller = create("foo", 1, 'a', "bar", 1, 'b');
Table<String, Integer, Character> swapOuter =
create("bar", 1, 'a', "foo", 1, 'b', "bar", 3, 'c');
Table<String, Integer, Character> swapValues =
create("foo", 1, 'c', "bar", 1, 'b', "foo", 3, 'a');
// We know that we have only added non-null Characters.
Table<String, Integer, Character> hashCopy =
HashBasedTable.create((Table<String, Integer, ? extends Character>) table);
Table<String, Integer, C> reordered = create("foo", 3, 'c', "foo", 1, 'a', "bar", 1, 'b');
Table<String, Integer, C> smaller = create("foo", 1, 'a', "bar", 1, 'b');
Table<String, Integer, C> swapOuter = create("bar", 1, 'a', "foo", 1, 'b', "bar", 3, 'c');
Table<String, Integer, C> swapValues = create("foo", 1, 'c', "bar", 1, 'b', "foo", 3, 'a');

new EqualsTester()
.addEqualityGroup(table, hashCopy, reordered)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.google.common.annotations.GwtCompatible;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Test cases for a {@link Table} implementation supporting reads and writes.
Expand All @@ -29,12 +31,14 @@
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class AbstractTableTest extends AbstractTableReadTest {
public abstract class AbstractTableTest<C extends @Nullable Character>
extends AbstractTableReadTest<C> {

protected void populate(Table<String, Integer, Character> table, Object... data) {
protected void populate(Table<String, Integer, C> table, @Nullable Object... data) {
checkArgument(data.length % 3 == 0);
for (int i = 0; i < data.length; i += 3) {
table.put((String) data[i], (Integer) data[i + 1], (Character) data[i + 2]);
table.put(
(String) data[i], (Integer) data[i + 1], nullableCellValue((Character) data[i + 2]));
}
}

Expand Down Expand Up @@ -62,29 +66,28 @@ public void testClear() {
}

public void testPut() {
assertNull(table.put("foo", 1, 'a'));
assertNull(table.put("bar", 1, 'b'));
assertNull(table.put("foo", 3, 'c'));
assertEquals((Character) 'a', table.put("foo", 1, 'd'));
assertNull(table.put("foo", 1, cellValue('a')));
assertNull(table.put("bar", 1, cellValue('b')));
assertNull(table.put("foo", 3, cellValue('c')));
assertEquals((Character) 'a', table.put("foo", 1, cellValue('d')));
assertEquals((Character) 'd', table.get("foo", 1));
assertEquals((Character) 'b', table.get("bar", 1));
assertSize(3);
assertEquals((Character) 'd', table.put("foo", 1, 'd'));
assertEquals((Character) 'd', table.put("foo", 1, cellValue('d')));
assertEquals((Character) 'd', table.get("foo", 1));
assertSize(3);
}

// This test assumes that the implementation does not support nulls.
public void testPutNull() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
assertSize(3);
try {
table.put(null, 2, 'd');
table.put(null, 2, cellValue('d'));
fail();
} catch (NullPointerException expected) {
}
try {
table.put("cat", null, 'd');
table.put("cat", null, cellValue('d'));
fail();
} catch (NullPointerException expected) {
}
Expand All @@ -105,11 +108,11 @@ public void testPutNullReplace() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');

if (supportsNullValues()) {
assertEquals((Character) 'b', table.put("bar", 1, null));
assertEquals((Character) 'b', table.put("bar", 1, nullableCellValue(null)));
assertNull(table.get("bar", 1));
} else {
try {
table.put("bar", 1, null);
table.put("bar", 1, nullableCellValue(null));
fail();
} catch (NullPointerException expected) {
}
Expand All @@ -118,10 +121,10 @@ public void testPutNullReplace() {

public void testPutAllTable() {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
Table<String, Integer, Character> other = HashBasedTable.create();
other.put("foo", 1, 'd');
other.put("bar", 2, 'e');
other.put("cat", 2, 'f');
Table<String, Integer, @NonNull C> other = HashBasedTable.create();
other.put("foo", 1, cellValue('d'));
other.put("bar", 2, cellValue('e'));
other.put("cat", 2, cellValue('f'));
table.putAll(other);
assertEquals((Character) 'd', table.get("foo", 1));
assertEquals((Character) 'b', table.get("bar", 1));
Expand Down Expand Up @@ -159,18 +162,29 @@ public void testRemove() {
public void testRowClearAndPut() {
if (supportsRemove()) {
table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
Map<Integer, Character> row = table.row("foo");
Map<Integer, C> row = table.row("foo");
assertEquals(ImmutableMap.of(1, 'a', 3, 'c'), row);
table.remove("foo", 3);
assertEquals(ImmutableMap.of(1, 'a'), row);
table.remove("foo", 1);
assertEquals(ImmutableMap.of(), row);
table.put("foo", 2, 'b');
table.put("foo", 2, cellValue('b'));
assertEquals(ImmutableMap.of(2, 'b'), row);
row.clear();
assertEquals(ImmutableMap.of(), row);
table.put("foo", 5, 'x');
table.put("foo", 5, cellValue('x'));
assertEquals(ImmutableMap.of(5, 'x'), row);
}
}

@SuppressWarnings("unchecked") // C can only be @Nullable Character or Character
protected @NonNull C cellValue(Character character) {
return (C) character;
}

// Only safe wrt. ClassCastException. Not null-safe (can be used to test expected Table NPEs)
@SuppressWarnings("unchecked")
protected C nullableCellValue(@Nullable Character character) {
return (C) character;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public class ArrayTableTest extends AbstractTableTest {
public class ArrayTableTest extends AbstractTableTest<@Nullable Character> {

@Override
protected ArrayTable<String, Integer, Character> create(Object... data) {
protected ArrayTable<String, Integer, Character> create(@Nullable Object... data) {
// TODO: Specify different numbers of rows and columns, to detect problems
// that arise when the wrong size is used.
ArrayTable<String, Integer, Character> table =
Expand Down Expand Up @@ -128,12 +128,12 @@ public void testEquals() {
hashCopy.put("foo", 1, 'a');
hashCopy.put("bar", 1, 'b');
hashCopy.put("foo", 3, 'c');
Table<String, Integer, Character> reordered =
Table<String, Integer, @Nullable Character> reordered =
create("foo", 3, 'c', "foo", 1, 'a', "bar", 1, 'b');
Table<String, Integer, Character> smaller = create("foo", 1, 'a', "bar", 1, 'b');
Table<String, Integer, Character> swapOuter =
Table<String, Integer, @Nullable Character> smaller = create("foo", 1, 'a', "bar", 1, 'b');
Table<String, Integer, @Nullable Character> swapOuter =
create("bar", 1, 'a', "foo", 1, 'b', "bar", 3, 'c');
Table<String, Integer, Character> swapValues =
Table<String, Integer, @Nullable Character> swapValues =
create("foo", 1, 'c', "bar", 1, 'b', "foo", 3, 'a');

new EqualsTester()
Expand Down Expand Up @@ -242,9 +242,9 @@ public void testEmptyToArry() {
}

public void testCreateCopyArrayTable() {
Table<String, Integer, Character> original =
Table<String, Integer, @Nullable Character> original =
create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
Table<String, Integer, Character> copy = ArrayTable.create(original);
Table<String, Integer, @Nullable Character> copy = ArrayTable.create(original);
assertEquals(original, copy);
original.put("foo", 1, 'd');
assertEquals((Character) 'd', original.get("foo", 1));
Expand All @@ -258,7 +258,7 @@ public void testCreateCopyHashBasedTable() {
original.put("foo", 1, 'a');
original.put("bar", 1, 'b');
original.put("foo", 3, 'c');
Table<String, Integer, Character> copy = ArrayTable.create(original);
Table<String, Integer, @Nullable Character> copy = ArrayTable.create(original);
assertEquals(4, copy.size());
assertEquals((Character) 'a', copy.get("foo", 1));
assertEquals((Character) 'b', copy.get("bar", 1));
Expand All @@ -281,7 +281,7 @@ public void testCreateCopyEmptyTable() {
}

public void testCreateCopyEmptyArrayTable() {
Table<String, Integer, Character> original =
Table<String, Integer, @Nullable Character> original =
ArrayTable.create(Arrays.<String>asList(), Arrays.<Integer>asList());
ArrayTable<String, Integer, Character> copy = ArrayTable.create(original);
assertThat(copy).isEqualTo(original);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ForwardingSortedMapImplementsMapTest() {
@Override
protected SortedMap<String, Integer> makeEmptyMap() {
return new SimpleForwardingSortedMap<>(
new TreeMap<String, Integer>(Ordering.natural().nullsFirst()));
new TreeMap<String, Integer>(Ordering.<String>natural().nullsFirst()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public class GeneralRangeTest extends TestCase {
private static final Ordering<@Nullable Integer> ORDERING = Ordering.natural().nullsFirst();
private static final Ordering<@Nullable Integer> ORDERING =
Ordering.<Integer>natural().<Integer>nullsFirst();

private static final List<@Nullable Integer> IN_ORDER_VALUES = Arrays.asList(null, 1, 2, 3, 4, 5);

Expand Down Expand Up @@ -150,7 +151,7 @@ public void testIntersectAgainstBiggerRange() {

assertEquals(
GeneralRange.range(ORDERING, 2, CLOSED, 4, OPEN),
range.intersect(GeneralRange.range(ORDERING, null, OPEN, 5, CLOSED)));
range.intersect(GeneralRange.<@Nullable Integer>range(ORDERING, null, OPEN, 5, CLOSED)));

assertEquals(
GeneralRange.range(ORDERING, 2, OPEN, 4, OPEN),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.annotations.J2ktIncompatible;
import com.google.common.testing.NullPointerTester;
import com.google.common.testing.SerializableTester;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Test cases for {@link HashBasedTable}.
Expand All @@ -31,10 +32,10 @@
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public class HashBasedTableTest extends AbstractTableTest {
public class HashBasedTableTest extends AbstractTableTest<Character> {

@Override
protected Table<String, Integer, Character> create(Object... data) {
protected Table<String, Integer, Character> create(@Nullable Object... data) {
Table<String, Integer, Character> table = HashBasedTable.create();
table.put("foo", 4, 'a');
table.put("cat", 1, 'b');
Expand Down
Loading

0 comments on commit 90cb46e

Please sign in to comment.