use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.
the class ComparatorsTest method fromFunctionsWithTwoArgs.
@Test
public void fromFunctionsWithTwoArgs() {
Person raab = new Person("Don", "Raab", 0);
Person white = new Person("Barry", "White", 0);
Person manilow = new Person("Barry", "Manilow", 0);
Comparator<Person> personComparator = Comparators.fromFunctions(Person.TO_FIRST, Person.TO_LAST);
Verify.assertPositive(personComparator.compare(raab, white));
Verify.assertNegative(personComparator.compare(white, raab));
Verify.assertZero(personComparator.compare(raab, raab));
Verify.assertPositive(personComparator.compare(white, manilow));
Verify.assertNegative(personComparator.compare(manilow, white));
}
use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.
the class ComparatorsTest method fromFunctionsWithThreeArgs.
@Test
public void fromFunctionsWithThreeArgs() {
Person raab = new Person("Don", "Raab", 21);
Person white = new Person("Barry", "White", 16);
Person manilow = new Person("Barry", "Manilow", 60);
Person manilow2 = new Person("Barry", "Manilow", 61);
Comparator<Person> personComparator = Comparators.fromFunctions(Person.TO_FIRST, Person.TO_LAST, Person.TO_AGE);
Verify.assertPositive(personComparator.compare(raab, white));
Verify.assertNegative(personComparator.compare(white, raab));
Verify.assertZero(personComparator.compare(raab, raab));
Verify.assertPositive(personComparator.compare(white, manilow));
Verify.assertNegative(personComparator.compare(manilow, white));
Verify.assertNegative(personComparator.compare(manilow, manilow2));
Verify.assertPositive(personComparator.compare(manilow2, manilow));
}
use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.
the class FunctionsTest method pair.
@Test
public void pair() {
Person john = new Person("John", "Smith");
Person jane = new Person("Jane", "Smith");
Person johnDoe = new Person("John", "Doe");
MutableList<Person> people = FastList.newListWith(john, jane, johnDoe);
MutableList<Person> sorted = people.sortThisBy(Functions.pair(Person.TO_LAST, Person.TO_FIRST));
Assert.assertEquals(FastList.newListWith(johnDoe, jane, john), sorted);
}
use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.
the class HashingStrategiesTest method identityHashingStrategy.
@Test
public void identityHashingStrategy() {
Person john1 = new Person("John", "Smith");
Person john2 = new Person("John", "Smith");
Verify.assertEqualsAndHashCode(john1, john2);
HashingStrategy<Object> identityHashingStrategy = HashingStrategies.identityStrategy();
Assert.assertNotEquals(identityHashingStrategy.computeHashCode(john1), identityHashingStrategy.computeHashCode(john2));
Assert.assertTrue(identityHashingStrategy.equals(john1, john1));
Assert.assertFalse(identityHashingStrategy.equals(john1, john2));
}
use of org.eclipse.collections.impl.test.domain.Person in project eclipse-collections by eclipse.
the class HashingStrategiesTest method nullSafeFromFunction.
@Test
public void nullSafeFromFunction() {
Person john = new Person("John", "Smith");
Person jane = new Person("Jane", "Smith");
Person nullLast = new Person("Jane", null);
Person nullFirst = new Person(null, "Smith");
HashingStrategy<Person> lastHashingStrategy = HashingStrategies.nullSafeFromFunction(Person.TO_LAST);
HashingStrategy<Person> firstHashingStrategy = HashingStrategies.nullSafeFromFunction(Person.TO_FIRST);
Assert.assertEquals("John".hashCode(), firstHashingStrategy.computeHashCode(john));
Assert.assertEquals(0, firstHashingStrategy.computeHashCode(nullFirst));
Assert.assertEquals("Jane".hashCode(), firstHashingStrategy.computeHashCode(nullLast));
Assert.assertEquals(firstHashingStrategy.computeHashCode(jane), firstHashingStrategy.computeHashCode(nullLast));
Assert.assertNotEquals(john.hashCode(), firstHashingStrategy.computeHashCode(john));
Assert.assertFalse(firstHashingStrategy.equals(john, jane));
Assert.assertEquals("Smith".hashCode(), lastHashingStrategy.computeHashCode(john));
Assert.assertEquals(0, lastHashingStrategy.computeHashCode(nullLast));
Assert.assertEquals("Smith".hashCode(), lastHashingStrategy.computeHashCode(nullFirst));
Assert.assertEquals(lastHashingStrategy.computeHashCode(john), lastHashingStrategy.computeHashCode(nullFirst));
Assert.assertNotEquals(john.hashCode(), lastHashingStrategy.computeHashCode(john));
Assert.assertTrue(lastHashingStrategy.equals(john, jane));
Assert.assertNotEquals(lastHashingStrategy.computeHashCode(john), firstHashingStrategy.computeHashCode(john));
Assert.assertNotEquals(lastHashingStrategy.computeHashCode(john), firstHashingStrategy.computeHashCode(jane));
Assert.assertEquals(lastHashingStrategy.computeHashCode(john), lastHashingStrategy.computeHashCode(jane));
}
Aggregations