You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
69 lines
1.7 KiB
/* |
|
* To change this license header, choose License Headers in Project Properties. |
|
* To change this template file, choose Tools | Templates |
|
* and open the template in the editor. |
|
*/ |
|
package collectionexample; |
|
|
|
import java.util.Objects; |
|
|
|
/** |
|
* |
|
* @author denis |
|
*/ |
|
public class Person implements Comparable<Person>{ |
|
|
|
public String name; |
|
public Integer phone; |
|
|
|
public Person(String name, Integer phone) { |
|
this.name = name; |
|
this.phone = phone; |
|
} |
|
|
|
@Override |
|
public String toString() { |
|
return "Person{" + "name=" + name + ", phone=" + phone + '}'; |
|
} |
|
|
|
@Override |
|
public int hashCode() { |
|
int hash = 3; |
|
hash = 37 * hash + Objects.hashCode(this.name); |
|
hash = 37 * hash + Objects.hashCode(this.phone); |
|
return hash; |
|
} |
|
|
|
@Override |
|
public boolean equals(Object obj) { |
|
if (this == obj) { |
|
return true; |
|
} |
|
if (obj == null) { |
|
return false; |
|
} |
|
if (getClass() != obj.getClass()) { |
|
return false; |
|
} |
|
final Person other = (Person) obj; |
|
if (!Objects.equals(this.name, other.name)) { |
|
return false; |
|
} |
|
if (!Objects.equals(this.phone, other.phone)) { |
|
return false; |
|
} |
|
if (!Objects.equals(this.hashCode(), other.hashCode())) { |
|
return false; |
|
} |
|
return true; |
|
} |
|
|
|
@Override |
|
public int compareTo(Person person) { |
|
int res = this.name.compareTo(person.name); |
|
if(res==0) res = this.phone.compareTo(person.phone); |
|
return res; |
|
} |
|
|
|
|
|
}
|
|
|