Skip to content

Commit d7a35fe

Browse files
Added index field to ListChange
Also implemented hashcode + equals for testing purposes.
1 parent 5fb0fc4 commit d7a35fe

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/main/java/io/reactivex/rxjavafx/sources/ListChange.java

+27-4
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,52 @@
1515
*/
1616
package io.reactivex.rxjavafx.sources;
1717

18+
import java.util.Objects;
19+
1820
/**
1921
* Holds an ADDED, REMOVED, or UPDATED flag with the associated value
2022
* @param <T>
2123
*/
2224
public final class ListChange<T> {
2325
private final T value;
2426
private final Flag flag;
27+
private final int index;
2528

26-
private ListChange(T value, Flag flag) {
29+
private ListChange(T value, Flag flag, int index) {
2730
this.value = value;
2831
this.flag = flag;
32+
this.index = index;
2933
}
30-
public static <T> ListChange<T> of(T value, Flag flag) {
31-
return new ListChange<>(value, flag);
34+
public static <T> ListChange<T> of(T value, Flag flag, int index) {
35+
return new ListChange<>(value, flag, index);
3236
}
3337
public T getValue() {
3438
return value;
3539
}
3640
public Flag getFlag() {
3741
return flag;
3842
}
43+
public int getIndex() {
44+
return index;
45+
}
46+
3947
@Override
4048
public String toString() {
41-
return flag + " " + value;
49+
return flag + " " + value + " " + index;
50+
}
51+
52+
@Override
53+
public boolean equals(Object o) {
54+
if (this == o) return true;
55+
if (o == null || getClass() != o.getClass()) return false;
56+
ListChange<?> that = (ListChange<?>) o;
57+
return index == that.index &&
58+
value.equals(that.value) &&
59+
flag == that.flag;
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
return Objects.hash(value, flag, index);
4265
}
4366
}

0 commit comments

Comments
 (0)