Skip to content

Commit

Permalink
Replace usages of Comparators.nullSafeEquals() with Objects.equals().
Browse files Browse the repository at this point in the history
Signed-off-by: Craig P. Motlin <cmotlin@gmail.com>
  • Loading branch information
motlin committed Dec 30, 2019
1 parent 90c6652 commit 5491e4f
Show file tree
Hide file tree
Showing 45 changed files with 241 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.impl.CollidingInt;
import org.eclipse.collections.impl.block.factory.Comparators;
import org.eclipse.collections.impl.test.SerializeTestHelper;
import org.eclipse.collections.impl.test.Verify;
import org.junit.Assert;
Expand Down Expand Up @@ -1701,11 +1701,11 @@ public boolean equals(Object o)

Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;

if (!Comparators.nullSafeEquals(this.key, entry.getKey()))
if (!Objects.equals(this.key, entry.getKey()))
{
return false;
}
return Comparators.nullSafeEquals(this.value, entry.getValue());
return Objects.equals(this.value, entry.getValue());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -2055,7 +2056,7 @@ public static void assertListsEqual(String listName, List<?> expectedList, List<
{
Object eachExpected = expectedList.get(index);
Object eachActual = actualList.get(index);
if (!Comparators.nullSafeEquals(eachExpected, eachActual))
if (!Objects.equals(eachExpected, eachActual))
{
junit.framework.Assert.failNotEquals(listName + " first differed at element [" + index + "];", eachExpected, eachActual);
}
Expand Down Expand Up @@ -2236,7 +2237,7 @@ public static void assertIterablesEqual(String iterableName, Iterable<?> expecte
Object eachExpected = expectedIterator.next();
Object eachActual = actualIterator.next();

if (!Comparators.nullSafeEquals(eachExpected, eachActual))
if (!Objects.equals(eachExpected, eachActual))
{
//noinspection UseOfObsoleteAssert
junit.framework.Assert.failNotEquals(iterableName + " first differed at element [" + index + "];", eachExpected, eachActual);
Expand Down Expand Up @@ -2284,7 +2285,7 @@ public static void assertMapsEqual(String mapName, Map<?, ?> expectedMap, Map<?,
Object expectedKey = expectedEntry.getKey();
Object expectedValue = expectedEntry.getValue();
Object actualValue = actualMap.get(expectedKey);
if (!Comparators.nullSafeEquals(actualValue, expectedValue))
if (!Objects.equals(actualValue, expectedValue))
{
Assert.fail("Values differ at key " + expectedKey + " expected " + expectedValue + " but was " + actualValue);
}
Expand Down Expand Up @@ -2571,7 +2572,7 @@ private static void assertMapContainsValues(
Object expectedKey = expectedKeyValues[i++];
Object expectedValue = expectedKeyValues[i++];
Object actualValue = actualMap.get(expectedKey);
if (!Comparators.nullSafeEquals(expectedValue, actualValue))
if (!Objects.equals(expectedValue, actualValue))
{
missingEntries.put(
expectedKey,
Expand Down Expand Up @@ -3076,7 +3077,7 @@ public static void assertContainsKeyValue(
Verify.assertContainsKey(mapName, expectedKey, actualMap);

Object actualValue = actualMap.get(expectedKey);
if (!Comparators.nullSafeEquals(actualValue, expectedValue))
if (!Objects.equals(actualValue, expectedValue))
{
Assert.fail(
mapName
Expand Down Expand Up @@ -3129,7 +3130,7 @@ public static void assertContainsKeyValue(
Verify.assertContainsKey(mapIterableName, expectedKey, mapIterable);

Object actualValue = mapIterable.get(expectedKey);
if (!Comparators.nullSafeEquals(actualValue, expectedValue))
if (!Objects.equals(actualValue, expectedValue))
{
Assert.fail(
mapIterableName
Expand Down Expand Up @@ -3182,7 +3183,7 @@ public static void assertContainsKeyValue(
Verify.assertContainsKey(mapIterableName, expectedKey, mutableMapIterable);

Object actualValue = mutableMapIterable.get(expectedKey);
if (!Comparators.nullSafeEquals(actualValue, expectedValue))
if (!Objects.equals(actualValue, expectedValue))
{
Assert.fail(
mapIterableName
Expand Down Expand Up @@ -3235,7 +3236,7 @@ public static void assertContainsKeyValue(
Verify.assertContainsKey(mapIterableName, expectedKey, immutableMapIterable);

Object actualValue = immutableMapIterable.get(expectedKey);
if (!Comparators.nullSafeEquals(actualValue, expectedValue))
if (!Objects.equals(actualValue, expectedValue))
{
Assert.fail(
mapIterableName
Expand Down Expand Up @@ -3563,7 +3564,7 @@ public static void assertItemAtIndex(
Verify.assertObjectNotNull(listName, list);

Object actualItem = list.get(index);
if (!Comparators.nullSafeEquals(expectedItem, actualItem))
if (!Objects.equals(expectedItem, actualItem))
{
Assert.assertEquals(
listName + " has incorrect element at index:<" + index + '>',
Expand All @@ -3590,7 +3591,7 @@ public static void assertItemAtIndex(
{
Assert.assertNotNull(array);
Object actualItem = array[index];
if (!Comparators.nullSafeEquals(expectedItem, actualItem))
if (!Objects.equals(expectedItem, actualItem))
{
Assert.assertEquals(
arrayName + " has incorrect element at index:<" + index + '>',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.collections.api.bag.Bag;
Expand All @@ -37,7 +38,6 @@
import org.eclipse.collections.api.set.ImmutableSet;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.bag.mutable.HashBag;
import org.eclipse.collections.impl.block.factory.Comparators;
import org.eclipse.collections.impl.block.factory.Predicates;
import org.eclipse.collections.impl.block.procedure.MultimapEachPutProcedure;
import org.eclipse.collections.impl.factory.Bags;
Expand Down Expand Up @@ -186,7 +186,7 @@ public T getOnly()
@Override
public boolean contains(Object object)
{
return Comparators.nullSafeEquals(this.value, object);
return Objects.equals(this.value, object);
}

@Override
Expand Down Expand Up @@ -393,7 +393,7 @@ public int sizeDistinct()
@Override
public int occurrencesOf(Object item)
{
return Comparators.nullSafeEquals(this.value, item) ? 1 : 0;
return Objects.equals(this.value, item) ? 1 : 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.RandomAccess;
import java.util.function.BinaryOperator;
Expand All @@ -37,7 +38,6 @@
import org.eclipse.collections.api.map.primitive.MutableObjectLongMap;
import org.eclipse.collections.api.tuple.Twin;
import org.eclipse.collections.impl.AbstractRichIterable;
import org.eclipse.collections.impl.block.factory.Comparators;
import org.eclipse.collections.impl.block.factory.PrimitiveFunctions;
import org.eclipse.collections.impl.block.factory.Procedures2;
import org.eclipse.collections.impl.block.procedure.MutatingAggregationProcedure;
Expand Down Expand Up @@ -211,7 +211,7 @@ public boolean remove(Object o)
Iterator<T> iterator = this.iterator();
while (iterator.hasNext())
{
if (Comparators.nullSafeEquals(o, iterator.next()))
if (Objects.equals(o, iterator.next()))
{
iterator.remove();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.RandomAccess;
import java.util.Set;

import org.eclipse.collections.api.collection.ImmutableCollection;
import org.eclipse.collections.api.collection.MutableCollection;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.impl.block.factory.Comparators;
import org.eclipse.collections.impl.block.procedure.CollectionAddProcedure;
import org.eclipse.collections.impl.block.procedure.CollectionRemoveProcedure;
import org.eclipse.collections.impl.factory.Lists;
Expand Down Expand Up @@ -150,7 +150,7 @@ public boolean equals(Object o)
}

CollectionAdapter<?> that = (CollectionAdapter<?>) o;
return Comparators.nullSafeEquals(this.delegate, that.delegate);
return Objects.equals(this.delegate, that.delegate);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Objects;
import java.util.function.UnaryOperator;

import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.impl.block.factory.Comparators;

/**
* A DoubletonList is a two-element memory efficient List. It is created by calling Lists.fixedSize.of(one, two).
Expand Down Expand Up @@ -100,7 +100,7 @@ public T get(int index)
@Override
public boolean contains(Object obj)
{
return Comparators.nullSafeEquals(obj, this.element1) || Comparators.nullSafeEquals(obj, this.element2);
return Objects.equals(obj, this.element1) || Objects.equals(obj, this.element2);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Objects;
import java.util.function.UnaryOperator;

import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.impl.block.factory.Comparators;

/**
* This is a four element memory efficient List which is created by calling Lists.fixedSize.of(one, two, three, four).
Expand Down Expand Up @@ -90,10 +90,10 @@ public T get(int index)
@Override
public boolean contains(Object obj)
{
return Comparators.nullSafeEquals(obj, this.element1)
|| Comparators.nullSafeEquals(obj, this.element2)
|| Comparators.nullSafeEquals(obj, this.element3)
|| Comparators.nullSafeEquals(obj, this.element4);
return Objects.equals(obj, this.element1)
|| Objects.equals(obj, this.element2)
|| Objects.equals(obj, this.element3)
|| Objects.equals(obj, this.element4);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Objects;
import java.util.function.UnaryOperator;

import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.impl.block.factory.Comparators;

/**
* This is a five element memory efficient List which is created by calling Lists.fixedSize.of(one, two, three, four, five).
Expand Down Expand Up @@ -94,11 +94,11 @@ public T get(int index)
@Override
public boolean contains(Object obj)
{
return Comparators.nullSafeEquals(obj, this.element1)
|| Comparators.nullSafeEquals(obj, this.element2)
|| Comparators.nullSafeEquals(obj, this.element3)
|| Comparators.nullSafeEquals(obj, this.element4)
|| Comparators.nullSafeEquals(obj, this.element5);
return Objects.equals(obj, this.element1)
|| Objects.equals(obj, this.element2)
|| Objects.equals(obj, this.element3)
|| Objects.equals(obj, this.element4)
|| Objects.equals(obj, this.element5);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Objects;
import java.util.function.UnaryOperator;

import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.impl.block.factory.Comparators;

/**
* This is a six element immutable List which is created by calling Lists.fixedSize.of(one, two, three, four, five, six).
Expand Down Expand Up @@ -111,12 +111,12 @@ public T get(int index)
@Override
public boolean contains(Object obj)
{
return Comparators.nullSafeEquals(obj, this.element1)
|| Comparators.nullSafeEquals(obj, this.element2)
|| Comparators.nullSafeEquals(obj, this.element3)
|| Comparators.nullSafeEquals(obj, this.element4)
|| Comparators.nullSafeEquals(obj, this.element5)
|| Comparators.nullSafeEquals(obj, this.element6);
return Objects.equals(obj, this.element1)
|| Objects.equals(obj, this.element2)
|| Objects.equals(obj, this.element3)
|| Objects.equals(obj, this.element4)
|| Objects.equals(obj, this.element5)
|| Objects.equals(obj, this.element6);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Comparator;
import java.util.Objects;
import java.util.function.UnaryOperator;

import org.eclipse.collections.api.block.function.Function;
Expand All @@ -30,7 +31,6 @@
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.impl.block.factory.Comparators;

/**
* This class is a memory efficient list with one element. Unlike Collections.singletonList(), it can be sorted. It is
Expand Down Expand Up @@ -78,7 +78,7 @@ public int size()
@Override
public boolean contains(Object obj)
{
return Comparators.nullSafeEquals(obj, this.element1);
return Objects.equals(obj, this.element1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Objects;
import java.util.function.UnaryOperator;

import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.impl.block.factory.Comparators;

/**
* This is a three element memory efficient List which is created by calling Lists.fixedSize.of(one, two, three).
Expand Down Expand Up @@ -86,9 +86,9 @@ public T get(int index)
@Override
public boolean contains(Object obj)
{
return Comparators.nullSafeEquals(obj, this.element1)
|| Comparators.nullSafeEquals(obj, this.element2)
|| Comparators.nullSafeEquals(obj, this.element3);
return Objects.equals(obj, this.element1)
|| Objects.equals(obj, this.element2)
|| Objects.equals(obj, this.element3);
}

/**
Expand Down
Loading

0 comments on commit 5491e4f

Please sign in to comment.