diff options
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); + } + +} |