Skip to content

Commit 8299542

Browse files
author
eugenp
committed
eclipse and cleanup work
1 parent 9543f1f commit 8299542

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

core-java-8/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
<artifactId>maven-compiler-plugin</artifactId>
8787
<version>${maven-compiler-plugin.version}</version>
8888
<configuration>
89-
<source>1.7</source>
90-
<target>1.7</target>
89+
<source>1.8</source>
90+
<target>1.8</target>
9191
</configuration>
9292
</plugin>
9393

core-java-8/src/test/java/org/baeldung/java8/Java8ComparatorUnitTest.java renamed to core-java-8/src/test/java/org/baeldung/java8/Java8SortUnitTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.baeldung.java8;
22

3-
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
4-
53
import java.util.Collections;
64
import java.util.List;
75

@@ -10,15 +8,15 @@
108

119
import com.google.common.collect.Lists;
1210

13-
public class Java8ComparatorUnitTest {
11+
public class Java8SortUnitTest {
1412

1513
// tests -
1614

1715
@Test
18-
public final void when_thenCorrect() {
19-
final List<Human> humans = Lists.newArrayList(new Human(randomAlphabetic(5)), new Human(randomAlphabetic(5)));
16+
public final void whenSortingEntitiesByName_thenCorrectlySorted() {
17+
final List<Human> humans = Lists.newArrayList(new Human("Sarah", 10), new Human("Jack", 12));
2018
Collections.sort(humans, (final Human h1, final Human h2) -> h1.getName().compareTo(h2.getName()));
21-
System.out.println(humans);
19+
// Assert.assertThat(actual, matcher);
2220
}
2321

2422
}

core-java-8/src/test/java/org/baeldung/java8/entity/Human.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
public class Human {
44
private String name;
5+
private int age;
56

67
public Human() {
78
super();
89
}
910

10-
public Human(final String name) {
11+
public Human(final String name, final int age) {
1112
super();
1213

1314
this.name = name;
15+
this.age = age;
1416
}
1517

1618
// API
@@ -23,11 +25,21 @@ public void setName(final String name) {
2325
this.name = name;
2426
}
2527

28+
public int getAge() {
29+
return age;
30+
}
31+
32+
public void setAge(final int age) {
33+
this.age = age;
34+
}
35+
2636
//
37+
2738
@Override
2839
public int hashCode() {
2940
final int prime = 31;
3041
int result = 1;
42+
result = prime * result + age;
3143
result = prime * result + ((name == null) ? 0 : name.hashCode());
3244
return result;
3345
}
@@ -44,6 +56,9 @@ public boolean equals(final Object obj) {
4456
return false;
4557
}
4658
final Human other = (Human) obj;
59+
if (age != other.age) {
60+
return false;
61+
}
4762
if (name == null) {
4863
if (other.name != null) {
4964
return false;
@@ -57,7 +72,7 @@ public boolean equals(final Object obj) {
5772
@Override
5873
public String toString() {
5974
final StringBuilder builder = new StringBuilder();
60-
builder.append("Human [name=").append(name).append("]");
75+
builder.append("Human [name=").append(name).append(", age=").append(age).append("]");
6176
return builder.toString();
6277
}
6378

0 commit comments

Comments
 (0)