package com.mavlushechka.a1qa.models; import java.util.Objects; public class Post implements Comparable { 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); } }