summaryrefslogtreecommitdiff
path: root/src/main/java/com/mavlushechka/a1qa/models/Post.java
blob: c936a7145ff376d3ff4a16878d0ede3dde63e633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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);
    }

}