11package com .urise .webapp .model ;
22
3- import java .util .Comparator ;
3+ import java .util .Objects ;
44import java .util .UUID ;
55
66/**
77 * Initial resume class
88 */
9- public class Resume implements Comparator < Resume >, Comparable <Resume > {
9+ public class Resume implements Comparable <Resume > {
1010
1111 // Unique identifier
1212 private final String uuid ;
@@ -17,6 +17,8 @@ public Resume(String fullName) {
1717 }
1818
1919 public Resume (String uuid , String fullName ) {
20+ Objects .requireNonNull (fullName , "fullName must not be null" );
21+ Objects .requireNonNull (uuid , "uuid must not be null" );
2022 this .uuid = uuid ;
2123 this .fullName = fullName ;
2224 }
@@ -31,34 +33,28 @@ public String getFullName() {
3133
3234 @ Override
3335 public String toString () {
34- return uuid ;
36+ return uuid + "(" + fullName + ")" ;
3537 }
3638
37- @ Override
38- public int compare (Resume o1 , Resume o2 ) {
39- return o1 .getUuid ().equals (o2 .getUuid ())?
40- o1 .getFullName ().compareTo (o2 .getFullName ()):
41- o1 .getUuid ().compareTo (o2 .getUuid ());
42- }
43-
44-
4539 @ Override
4640 public boolean equals (Object o ) {
4741 if (this == o ) return true ;
4842 if (o == null || getClass () != o .getClass ()) return false ;
49-
5043 Resume resume = (Resume ) o ;
51-
44+ if (! uuid . equals ( resume . uuid )) return false ;
5245 return uuid .equals (resume .uuid );
5346 }
5447
5548 @ Override
5649 public int hashCode () {
57- return uuid .hashCode ();
50+ int result = uuid .hashCode ();
51+ result = 31 * result + fullName .hashCode ();
52+ return result ;
5853 }
5954
6055 @ Override
6156 public int compareTo (Resume o ) {
62- return this .getFullName ().equals (o .fullName )?this .getUuid ().compareTo (o .getUuid ()):this .getFullName ().compareTo (o .getFullName ());
57+ int cmp = fullName .compareTo (o .fullName );
58+ return cmp != 0 ? cmp : uuid .compareTo (o .getUuid ());
6359 }
6460}
0 commit comments