From f3de17fa7152ccc7637709835a49a0a1baaa611e Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Mon, 14 Nov 2016 04:14:29 +0700 Subject: some fields are finalized; equals() improvements --- juick-core/src/main/java/com/juick/Message.java | 2 -- juick-core/src/main/java/com/juick/PM.java | 10 +++++----- .../src/main/java/com/juick/Recommendation.java | 9 +++++---- juick-core/src/main/java/com/juick/Tag.java | 19 +++++++++---------- juick-core/src/main/java/com/juick/User.java | 7 ++++--- 5 files changed, 23 insertions(+), 24 deletions(-) (limited to 'juick-core/src/main/java/com/juick') diff --git a/juick-core/src/main/java/com/juick/Message.java b/juick-core/src/main/java/com/juick/Message.java index 2c004f5a..8afd1d7b 100644 --- a/juick-core/src/main/java/com/juick/Message.java +++ b/juick-core/src/main/java/com/juick/Message.java @@ -29,9 +29,7 @@ import java.util.stream.Collectors; * @author Ugnich Anton */ public class Message implements Comparable { - private int MID = 0; - private int RID = 0; @JsonProperty("replyto") diff --git a/juick-core/src/main/java/com/juick/PM.java b/juick-core/src/main/java/com/juick/PM.java index 658cafc9..4686b34a 100644 --- a/juick-core/src/main/java/com/juick/PM.java +++ b/juick-core/src/main/java/com/juick/PM.java @@ -4,13 +4,13 @@ package com.juick; * Created by vt on 08/02/16. */ public class PM { - private User to; - - public User getTo() { - return to; - } + private final User to; public PM(User to) { this.to = to; } + + public User getTo() { + return to; + } } diff --git a/juick-core/src/main/java/com/juick/Recommendation.java b/juick-core/src/main/java/com/juick/Recommendation.java index 4cfa67c2..1ae41771 100644 --- a/juick-core/src/main/java/com/juick/Recommendation.java +++ b/juick-core/src/main/java/com/juick/Recommendation.java @@ -4,13 +4,14 @@ package com.juick; * Created by vt on 08/02/16. */ public class Recommendation { - User from; + private final User from; - public User getFrom() { - return from; - } public Recommendation(User from) { this.from = from; } + + public User getFrom() { + return from; + } } diff --git a/juick-core/src/main/java/com/juick/Tag.java b/juick-core/src/main/java/com/juick/Tag.java index 8b790377..fa518e84 100644 --- a/juick-core/src/main/java/com/juick/Tag.java +++ b/juick-core/src/main/java/com/juick/Tag.java @@ -23,35 +23,34 @@ import com.fasterxml.jackson.annotation.JsonValue; import java.util.Objects; /** - * * @author Ugnich Anton */ public class Tag { + private final String name; - private String Name; public int TID = 0; public int SynonymID = 0; public int UsageCnt = 0; + public Tag(String name) { - this.Name = name; + this.name = name; } @Override public boolean equals(Object o) { - boolean equal = false; - if (o != null && o instanceof Tag) { - equal = Objects.equals(Name, ((Tag) o).Name); - } - return equal; + return o == this || + (o instanceof Tag) && Objects.equals(name, ((Tag) o).name); } + @JsonIgnore public String getName() { - return Name; + return name; } + @Override @JsonValue public String toString() { - return Name; + return name; } } diff --git a/juick-core/src/main/java/com/juick/User.java b/juick-core/src/main/java/com/juick/User.java index a8109e50..b8936bab 100644 --- a/juick-core/src/main/java/com/juick/User.java +++ b/juick-core/src/main/java/com/juick/User.java @@ -21,11 +21,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; /** - * * @author Ugnich Anton */ public class User { - private int UID = 0; private String UName = null; @JsonIgnore @@ -53,7 +51,8 @@ public class User { @Override public boolean equals(Object obj) { - return (obj instanceof User && ((User) obj).getUID() == this.getUID()); + return obj == this || + (obj instanceof User && ((User) obj).getUID() == this.getUID()); } @JsonProperty("uid") @@ -100,10 +99,12 @@ public class User { public void setAuthHash(String authHash) { AuthHash = authHash; } + @JsonProperty("unreadCount") public Integer getUnreadCount() { return MessagesCount; } + public void setUnreadCount(Integer count) { MessagesCount = count; } -- cgit v1.2.3