eclipse and cleanup work

This commit is contained in:
eugenp 2013-12-25 14:37:06 +02:00
parent 9543f1f067
commit 82995423dc
3 changed files with 23 additions and 10 deletions

View File

@ -86,8 +86,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

View File

@ -1,7 +1,5 @@
package org.baeldung.java8;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import java.util.Collections;
import java.util.List;
@ -10,15 +8,15 @@ import org.junit.Test;
import com.google.common.collect.Lists;
public class Java8ComparatorUnitTest {
public class Java8SortUnitTest {
// tests -
@Test
public final void when_thenCorrect() {
final List<Human> humans = Lists.newArrayList(new Human(randomAlphabetic(5)), new Human(randomAlphabetic(5)));
public final void whenSortingEntitiesByName_thenCorrectlySorted() {
final List<Human> humans = Lists.newArrayList(new Human("Sarah", 10), new Human("Jack", 12));
Collections.sort(humans, (final Human h1, final Human h2) -> h1.getName().compareTo(h2.getName()));
System.out.println(humans);
// Assert.assertThat(actual, matcher);
}
}

View File

@ -2,15 +2,17 @@ package org.baeldung.java8.entity;
public class Human {
private String name;
private int age;
public Human() {
super();
}
public Human(final String name) {
public Human(final String name, final int age) {
super();
this.name = name;
this.age = age;
}
// API
@ -23,11 +25,21 @@ public class Human {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(final int age) {
this.age = age;
}
//
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + age;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@ -44,6 +56,9 @@ public class Human {
return false;
}
final Human other = (Human) obj;
if (age != other.age) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
@ -57,7 +72,7 @@ public class Human {
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("Human [name=").append(name).append("]");
builder.append("Human [name=").append(name).append(", age=").append(age).append("]");
return builder.toString();
}