42 lines
902 B
Java
42 lines
902 B
Java
package com.inmind.treeset02;
|
|
|
|
import java.util.Objects;
|
|
|
|
public class Student implements Comparable<Student>{
|
|
String name;
|
|
int age;
|
|
|
|
public Student(String name, int age) {
|
|
this.name = name;
|
|
this.age = age;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "Student{" +
|
|
"name='" + name + '\'' +
|
|
", age=" + age +
|
|
'}';
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
Student student = (Student) o;
|
|
return age == student.age && Objects.equals(name, student.name);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
int result = Objects.hashCode(name);
|
|
result = 31 * result + age;
|
|
return result;
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(Student o) {
|
|
return this.age - o.age;
|
|
}
|
|
}
|