Search in sources :

Example 6 with Person

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));
}
Also used : Person(org.eclipse.collections.impl.test.domain.Person) Test(org.junit.Test)

Example 7 with Person

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));
}
Also used : Person(org.eclipse.collections.impl.test.domain.Person) Test(org.junit.Test)

Example 8 with Person

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);
}
Also used : Person(org.eclipse.collections.impl.test.domain.Person) Test(org.junit.Test)

Example 9 with Person

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));
}
Also used : Person(org.eclipse.collections.impl.test.domain.Person) Test(org.junit.Test)

Example 10 with Person

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));
}
Also used : Person(org.eclipse.collections.impl.test.domain.Person) Test(org.junit.Test)

Aggregations

Person (org.eclipse.collections.impl.test.domain.Person)17 Test (org.junit.Test)17 Pair (org.eclipse.collections.api.tuple.Pair)3 ObjectIntPair (org.eclipse.collections.api.tuple.primitive.ObjectIntPair)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1