Skip to content

Commit

Permalink
Replace some new HashSet<>() with immutable Set.copyOf
Browse files Browse the repository at this point in the history
  • Loading branch information
gartens committed Jan 7, 2025
1 parent 682af0f commit 6e617c0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/polypheny/db/rex/RexSimplify.java
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ private <C extends Comparable<C>> RexNode simplifyAnd2ForUnknownAsFalse( List<Re
// Example #1. x AND y AND z AND NOT (x AND y) - not satisfiable
// Example #2. x AND y AND NOT (x AND y) - not satisfiable
// Example #3. x AND y AND NOT (x AND y AND z) - may be satisfiable
final Set<RexNode> termsSet = new HashSet<>( terms );
final Set<RexNode> termsSet = Set.copyOf( terms );
for ( RexNode notDisjunction : notTerms ) {
if ( !RexUtil.isDeterministic( notDisjunction ) ) {
continue;
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/polypheny/db/util/EquivalenceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;

Expand Down Expand Up @@ -169,7 +170,7 @@ public int size() {
* Returns the number of equivalence classes in this equivalence set.
*/
public int classCount() {
return new HashSet<>( parents.values() ).size();
return Set.copyOf( parents.values() ).size();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void testAsList() {
assertEquals( list1, listView );
assertThat( list1.hashCode(), equalTo( listView.hashCode() ) );

final Set<Integer> set = new HashSet<>( list1 );
final Set<Integer> set = Set.copyOf( list1 );
assertThat( setView.hashCode(), is( set.hashCode() ) );
assertThat( setView, equalTo( set ) );

Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/org/polypheny/db/util/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ private List<Integer> checkIntegerIntervalSet( String s, int... ints ) {
final Set<Integer> set = IntegerIntervalSet.of( s );
assertEquals( set.size(), ints.length );
List<Integer> list = new ArrayList<>( set );
assertEquals( new HashSet<>( Ints.asList( ints ) ), set );
assertEquals( Set.copyOf( Ints.asList( ints ) ), set );
return list;
}

Expand Down Expand Up @@ -980,7 +980,7 @@ public void testCompositeMap() {
private void checkCompositeMap( String[] beatles, Map<String, Integer> map ) {
assertThat( 4, equalTo( map.size() ) );
assertThat( false, equalTo( map.isEmpty() ) );
assertThat( map.keySet(), equalTo( (Set<String>) new HashSet<>( Arrays.asList( beatles ) ) ) );
assertThat( map.keySet(), equalTo( Set.copyOf( Arrays.asList( beatles ) ) ) );
assertThat( ImmutableMultiset.copyOf( map.values() ), equalTo( ImmutableMultiset.copyOf( Arrays.asList( 4, 4, 6, 5 ) ) ) );
}

Expand Down

0 comments on commit 6e617c0

Please sign in to comment.