diff options
author | Mavlushechka <mavlushechka@gmail.com> | 2022-09-28 21:30:51 +0500 |
---|---|---|
committer | Mavlushechka <mavlushechka@gmail.com> | 2022-09-28 21:30:51 +0500 |
commit | 7feee798685959f4e234e9f86f53187542d39f1e (patch) | |
tree | 5d3259630b8d4a6ee0e0e295561c97f4d1d87553 /src/main/java/com/mavlushechka/a1qa/models/Post.java | |
parent | 8a762782bc9abfc5b11207ed2e31e94a21fe78ad (diff) |
Solve 1st test case
Diffstat (limited to 'src/main/java/com/mavlushechka/a1qa/models/Post.java')
-rw-r--r-- | src/main/java/com/mavlushechka/a1qa/models/Post.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/java/com/mavlushechka/a1qa/models/Post.java b/src/main/java/com/mavlushechka/a1qa/models/Post.java new file mode 100644 index 0000000..c936a71 --- /dev/null +++ b/src/main/java/com/mavlushechka/a1qa/models/Post.java @@ -0,0 +1,41 @@ +package com.mavlushechka.a1qa.models; + +import java.util.Objects; + +public class Post implements Comparable<Post> { + + public final String id; + public final String title; + public final String body; + public final String userId; + + + public Post(String id, String title, String body, String userId) { + this.id = id; + this.title = title; + this.body = body; + this.userId = userId; + } + + @Override + public int compareTo(Post post) { + int thisId = Integer.parseInt(id); + int otherId = Integer.parseInt(post.id); + + return Integer.compare(thisId, otherId); + } + + @Override + public boolean equals(Object object) { + if (this == object) return true; + if (object == null || getClass() != object.getClass()) return false; + Post post = (Post) object; + return Objects.equals(id, post.id) && Objects.equals(title, post.title) && Objects.equals(body, post.body) && Objects.equals(userId, post.userId); + } + + @Override + public int hashCode() { + return Objects.hash(id, title, body, userId); + } + +} |