Skip to content

Commit d560f0f

Browse files
committed
Poll equality
1 parent 0714682 commit d560f0f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/Poll.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ class Poll {
4747
@Expose
4848
var isVisible : Boolean = false
4949

50+
override fun equals(other: Any?): Boolean {
51+
return other is Poll && this.id == other.id && this.totalVotes == other.totalVotes
52+
&& this.question == other.question && this.options.size == other.options.size
53+
&& this.options.containsAll(other.options) && other.options.containsAll(this.options)
54+
}
55+
56+
5057
//@Expose
5158
//var homeAdapter : HomeAdapter? = null
5259

@@ -72,6 +79,21 @@ class Poll {
7279
//gui?.notifyDataSetChanged()
7380
}
7481

82+
override fun hashCode(): Int {
83+
var result = id ?: 0
84+
result = 31 * result + (clubCode?.hashCode() ?: 0)
85+
result = 31 * result + (question?.hashCode() ?: 0)
86+
result = 31 * result + (createdDate?.hashCode() ?: 0)
87+
result = 31 * result + (startDate?.hashCode() ?: 0)
88+
result = 31 * result + (expireDate?.hashCode() ?: 0)
89+
result = 31 * result + multiselect.hashCode()
90+
result = 31 * result + (clubComment?.hashCode() ?: 0)
91+
result = 31 * result + options.hashCode()
92+
result = 31 * result + totalVotes
93+
result = 31 * result + isVisible.hashCode()
94+
return result
95+
}
96+
7597
// Device id + poll id -> hash -> id
7698

7799
}

PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/PollOption.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,20 @@ class PollOption {
2424
var selected : Boolean = false
2525

2626
var isVisible : Boolean = false
27+
override fun equals(other: Any?): Boolean {
28+
return other is PollOption && this.choice == other.choice && this.id == other.id
29+
&& this.voteCount == other.voteCount
30+
}
31+
32+
override fun hashCode(): Int {
33+
var result = id ?: 0
34+
result = 31 * result + (poll ?: 0)
35+
result = 31 * result + (choice?.hashCode() ?: 0)
36+
result = 31 * result + voteCount
37+
result = 31 * result + selected.hashCode()
38+
result = 31 * result + isVisible.hashCode()
39+
return result
40+
}
41+
42+
2743
}

0 commit comments

Comments
 (0)