Repository navigation
Expand file tree
/
Copy pathFeedID.java
More file actions
60 lines (48 loc) · 1.57 KB
/
Copy pathFeedID.java
File metadata and controls
60 lines (48 loc) · 1.57 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package io.getstream.core.models;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import java.util.Objects;
@JsonSerialize(using = ToStringSerializer.class)
public final class FeedID {
private final String slug;
private final String userID;
public FeedID(String slug, String userID) {
checkNotNull(slug, "Feed slug can't be null");
checkArgument(!slug.contains(":"), "Invalid slug");
checkNotNull(userID, "Feed user ID can't be null");
checkArgument(!userID.contains(":"), "Invalid user ID");
this.slug = slug;
this.userID = userID;
}
public FeedID(String id) {
checkNotNull(id, "Feed ID can't be null");
checkArgument(id.contains(":"), "Invalid feed ID");
String[] parts = id.split(":");
checkArgument(parts.length == 2, "Invalid feed ID");
this.slug = parts[0];
this.userID = parts[1];
}
public String getSlug() {
return slug;
}
public String getUserID() {
return userID;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FeedID feedID = (FeedID) o;
return Objects.equals(slug, feedID.slug) && Objects.equals(userID, feedID.userID);
}
@Override
public int hashCode() {
return Objects.hash(slug, userID);
}
@Override
public String toString() {
return slug + ':' + userID;
}
}