eclipse and cleanup work
This commit is contained in:
parent
9543f1f067
commit
82995423dc
@ -86,8 +86,8 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>1.8</source>
|
||||||
<target>1.7</target>
|
<target>1.8</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package org.baeldung.java8;
|
package org.baeldung.java8;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -10,15 +8,15 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
public class Java8ComparatorUnitTest {
|
public class Java8SortUnitTest {
|
||||||
|
|
||||||
// tests -
|
// tests -
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void when_thenCorrect() {
|
public final void whenSortingEntitiesByName_thenCorrectlySorted() {
|
||||||
final List<Human> humans = Lists.newArrayList(new Human(randomAlphabetic(5)), new Human(randomAlphabetic(5)));
|
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()));
|
Collections.sort(humans, (final Human h1, final Human h2) -> h1.getName().compareTo(h2.getName()));
|
||||||
System.out.println(humans);
|
// Assert.assertThat(actual, matcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -2,15 +2,17 @@ package org.baeldung.java8.entity;
|
|||||||
|
|
||||||
public class Human {
|
public class Human {
|
||||||
private String name;
|
private String name;
|
||||||
|
private int age;
|
||||||
|
|
||||||
public Human() {
|
public Human() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Human(final String name) {
|
public Human(final String name, final int age) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.age = age;
|
||||||
}
|
}
|
||||||
|
|
||||||
// API
|
// API
|
||||||
@ -23,11 +25,21 @@ public class Human {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAge(final int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
|
result = prime * result + age;
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -44,6 +56,9 @@ public class Human {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Human other = (Human) obj;
|
final Human other = (Human) obj;
|
||||||
|
if (age != other.age) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
if (other.name != null) {
|
if (other.name != null) {
|
||||||
return false;
|
return false;
|
||||||
@ -57,7 +72,7 @@ public class Human {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
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();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user