Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Fixed warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nibix committed Jun 24, 2024
1 parent d560999 commit 11f3763
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 43 deletions.
20 changes: 10 additions & 10 deletions src/main/java/com/selectivem/check/BackingCollections.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public boolean containsAll(Collection<?> collection) {

abstract static class IndexedUnmodifiableSet<E> extends UnmodifiableSet<E> implements Set<E> {
static <E> IndexedUnmodifiableSet<E> of(E e1) {
return new OneElementSet<E>(e1);
return new OneElementSet<>(e1);
}

static <E> IndexedUnmodifiableSet<E> of(E e1, E e2) {
return new TwoElementSet<E>(e1, e2);
return new TwoElementSet<>(e1, e2);
}

static <E> IndexedUnmodifiableSet<E> of(Set<E> set) {
Expand All @@ -110,7 +110,7 @@ static <E> IndexedUnmodifiableSet<E> of(Set<E> set) {
return new ArrayBackedSet<>(set);
} else {
if (size <= 800) {
InternalBuilder<E> internalBuilder = new HashArrayBackedSet.Builder<E>(
InternalBuilder<E> internalBuilder = new HashArrayBackedSet.Builder<>(
size <= 8 ? 16 : size <= 40 ? 64 : size < 200 ? 256 : 1024, size);

for (E e : set) {
Expand All @@ -119,16 +119,16 @@ static <E> IndexedUnmodifiableSet<E> of(Set<E> set) {

return internalBuilder.build();
} else {
return new SetBackedSet.Builder<E>(set).build();
return new SetBackedSet.Builder<>(set).build();
}
}
}

static <E> InternalBuilder<E> builder(int size) {
if (size <= 800) {
return new HashArrayBackedSet.Builder<E>(size <= 10 ? 16 : size <= 50 ? 64 : size < 200 ? 256 : 1024, size);
return new HashArrayBackedSet.Builder<>(size <= 10 ? 16 : size <= 50 ? 64 : size < 200 ? 256 : 1024, size);
} else {
return new SetBackedSet.Builder<E>(size);
return new SetBackedSet.Builder<>(size);
}
}

Expand Down Expand Up @@ -435,7 +435,7 @@ public E next() {
throw new NoSuchElementException();
}

E element = (E) elements[i];
E element = elements[i];
i++;
return element;
}
Expand Down Expand Up @@ -744,7 +744,7 @@ public IndexedUnmodifiableSet<E> build() {
if (size == 0) {
return IndexedUnmodifiableSet.empty();
} else if (size == 1) {
return new OneElementSet<E>(this.flat[0]);
return new OneElementSet<>(this.flat[0]);
} else if (size == 2) {
return new TwoElementSet<>(this.flat[0], this.flat[1]);
} else {
Expand Down Expand Up @@ -908,7 +908,7 @@ E indexToElement(int i) {
}

static class Builder<E> extends InternalBuilder<E> {
private HashMap<E, Integer> delegate;
private final HashMap<E, Integer> delegate;
private E [] flat;

Builder(int expectedCapacity) {
Expand Down Expand Up @@ -980,7 +980,7 @@ public String toString() {

@Override
boolean contains(Object o) {
return delegate.keySet().contains(o);
return delegate.containsKey(o);
}

private void extendFlat() {
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/com/selectivem/check/CheckTableImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,46 @@
class CheckTableImpl {

static <R, C> CheckTable<R, C> create(R row, Set<C> columns) {
if (columns.size() == 0) {
int columnsSize = columns.size();

if (columnsSize == 0) {
throw new IllegalArgumentException("Must contain at least one column");
} else if (columns.size() == 1) {
return new CheckTableImpl.SingleCellCheckTable<R, C>(row, columns.iterator().next(), BackingCollections.IndexedUnmodifiableSet.of(row),
} else if (columnsSize == 1) {
return new CheckTableImpl.SingleCellCheckTable<>(row, columns.iterator().next(), BackingCollections.IndexedUnmodifiableSet.of(row),
BackingCollections.IndexedUnmodifiableSet.of(columns));
} else {
return new CheckTableImpl.SingleRowCheckTable<R, C>(row, columns);
return new CheckTableImpl.SingleRowCheckTable<>(row, columns);
}
}

static <R, C> CheckTable<R, C> create(Set<R> rows, C column) {
if (rows.size() == 0) {
int rowsSize = rows.size();

if (rowsSize == 0) {
throw new IllegalArgumentException("Must contain at least one row");
} else if (rows.size() == 1) {
return new CheckTableImpl.SingleCellCheckTable<R, C>(rows.iterator().next(), column, BackingCollections.IndexedUnmodifiableSet.of(rows),
} else if (rowsSize == 1) {
return new CheckTableImpl.SingleCellCheckTable<>(rows.iterator().next(), column, BackingCollections.IndexedUnmodifiableSet.of(rows),
BackingCollections.IndexedUnmodifiableSet.of(column));
} else {
return new CheckTableImpl.SingleColumnCheckTable<R, C>(rows, column);
}
}

static <R, C> CheckTable<R, C> create(Set<R> rows, Set<C> columns) {
if (rows.size() == 0 || columns.size() == 0) {
int rowsSize = rows.size();
int columnsSize = columns.size();

if (rowsSize == 0 || columnsSize == 0) {
throw new IllegalArgumentException("Must contain at least one column and at least one row (got " + rows + "/" + columns + ")");
} else if (rows.size() == 1) {
if (columns.size() == 1) {
return new CheckTableImpl.SingleCellCheckTable<R, C>(rows.iterator().next(), columns.iterator().next(),
} else if (rowsSize == 1) {
if (columnsSize == 1) {
return new CheckTableImpl.SingleCellCheckTable<>(rows.iterator().next(), columns.iterator().next(),
BackingCollections.IndexedUnmodifiableSet.of(rows), BackingCollections.IndexedUnmodifiableSet.of(columns));
} else {
return new CheckTableImpl.SingleRowCheckTable<R, C>(rows.iterator().next(), columns);
return new CheckTableImpl.SingleRowCheckTable<>(rows.iterator().next(), columns);
}
} else if (columns.size() == 1) {
return new CheckTableImpl.SingleColumnCheckTable<R, C>(rows, columns.iterator().next());
} else if (columnsSize == 1) {
return new CheckTableImpl.SingleColumnCheckTable<>(rows, columns.iterator().next());
} else {
return new CheckTableImpl.ArrayCheckTable<>(rows, columns);
}
Expand Down Expand Up @@ -109,7 +116,7 @@ public boolean check(R row, C column) {
checked = true;
}

return checked;
return true;
}

@Override
Expand Down
13 changes: 3 additions & 10 deletions src/test/java/com/selectivem/check/BackingCollectionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ public void builder() {
HashSet<String> reference = new HashSet<>();
BackingCollections.IndexedUnmodifiableSet.InternalBuilder<String> subject = BackingCollections.IndexedUnmodifiableSet
.builder(10);
HashSet<String> addedInRound1 = new HashSet<>();
HashSet<String> addedInRound2 = new HashSet<>();
HashSet<String> addedInRound3 = new HashSet<>();

int size = random.nextInt(100) + 4;

Expand All @@ -88,7 +85,6 @@ public void builder() {

reference.add(string);
subject = subject.with(string);
addedInRound1.add(string);
}

assertEquals(reference, subject);
Expand All @@ -100,7 +96,6 @@ public void builder() {

reference.add(string);
subject = subject.with(string);
addedInRound2.add(string);
assertEquals(reference, subject);
}

Expand All @@ -111,9 +106,7 @@ public void builder() {

reference.add(string);
subject = subject.with(string);
addedInRound3.add(string);
assertEquals(reference, subject);

}

assertEquals(reference, subject);
Expand Down Expand Up @@ -308,13 +301,13 @@ public void toArray() {

Object[] subjectArray = subject.toArray();
Assert.assertEquals(reference,
new HashSet<String>(Arrays.asList(subjectArray).stream().map((e) -> e.toString()).collect(Collectors.toSet())));
new HashSet<>(Arrays.asList(subjectArray).stream().map((e) -> e.toString()).collect(Collectors.toSet())));

String[] subjectStringArray = subject.toArray(new String[0]);
Assert.assertEquals(reference, new HashSet<String>(Arrays.asList(subjectStringArray)));
Assert.assertEquals(reference, new HashSet<>(Arrays.asList(subjectStringArray)));

String[] subjectStringArray2 = subject.toArray(new String[subject.size()]);
Assert.assertEquals(reference, new HashSet<String>(Arrays.asList(subjectStringArray2)));
Assert.assertEquals(reference, new HashSet<>(Arrays.asList(subjectStringArray2)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ public void basicTest() {

CheckList<String> subject = CheckList.create(elements);
Set<String> reference = new HashSet<>();
List<Set<String>> history = new ArrayList<>();

for (int i = 0; i < Math.min(100, elementsList.size()); i++) {
history.add(subject.getCheckedElements());
String element = elementsList.get(i);

boolean checkResult = subject.check(element);
Expand All @@ -96,7 +94,7 @@ public void basicTest() {
Assert.assertEquals(reference, checked);

Assert.assertTrue(subject.getUncheckedElements().toString(),
!subject.getUncheckedElements().stream().anyMatch(e -> subject.getCheckedElements().contains(e)));
subject.getUncheckedElements().stream().noneMatch(e -> subject.getCheckedElements().contains(e)));
Assert.assertEquals(elements.size(), subject.getCheckedElements().size() + subject.getUncheckedElements().size());

Set<String> unchecked = new HashSet<>();
Expand All @@ -118,7 +116,6 @@ public void basicTest() {
int toUncheck = random.nextInt(checkedElements.size());

for (int i = 0; i < toUncheck; i++) {
history.add(subject.getCheckedElements());
String element = checkedElements.get(i);

subject.uncheck(element);
Expand All @@ -136,7 +133,6 @@ public void basicTest() {
}

for (int i = 90; i < Math.min(200, elementsList.size()); i++) {
history.add(subject.getCheckedElements());
String element = elementsList.get(i);

boolean checkResult = subject.check(element);
Expand All @@ -162,7 +158,6 @@ public void basicTest() {
toUncheck = random.nextInt(checkedElements.size());

for (int i = 0; i < toUncheck; i++) {
history.add(subject.getCheckedElements());
String element = checkedElements.get(i);

subject.uncheck(element);
Expand All @@ -176,7 +171,6 @@ public void basicTest() {
}

for (int i = 0; i < elementsList.size(); i++) {
history.add(subject.getCheckedElements());
String element = elementsList.get(i);

boolean checkResult = subject.check(element);
Expand All @@ -197,7 +191,6 @@ public void checkIf_uncheckIf() {
Collections.shuffle(elementsList, random);

CheckList<String> subject = CheckList.create(elements);
Set<String> reference = new HashSet<>();

subject.checkIf(e -> e.contains("7"));
Set<String> expected = elements.stream().filter(e -> e.contains("7")).collect(Collectors.toSet());
Expand Down

0 comments on commit 11f3763

Please sign in to comment.