| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.shindig.social.opensocial.spi; |
| 19 | |
|
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
|
| 22 | |
import com.google.common.collect.Maps; |
| 23 | |
|
| 24 | |
import java.util.Map; |
| 25 | |
|
| 26 | |
public class GroupId { |
| 27 | 8 | public enum Type { |
| 28 | 1 | all, friends, self, deleted, groupId; |
| 29 | |
|
| 30 | |
|
| 31 | 1 | private static final Map<String, Type> jsonTypeMap = Maps.newHashMap(); |
| 32 | |
|
| 33 | |
static { |
| 34 | 6 | for (Type type : Type.values()) { |
| 35 | 5 | jsonTypeMap.put("@" + type.name(), type); |
| 36 | |
} |
| 37 | 1 | } |
| 38 | |
|
| 39 | |
public static Type jsonValueOf(String jsonType) { |
| 40 | 70 | return jsonTypeMap.get(jsonType); |
| 41 | |
} |
| 42 | |
} |
| 43 | |
|
| 44 | |
private Type type; |
| 45 | |
private String groupId; |
| 46 | |
|
| 47 | 93 | public GroupId(Type type, String groupId) { |
| 48 | 93 | this.groupId = groupId; |
| 49 | 93 | this.type = type; |
| 50 | 93 | } |
| 51 | |
|
| 52 | |
public Type getType() { |
| 53 | 59 | return type; |
| 54 | |
} |
| 55 | |
|
| 56 | |
public String getGroupId() { |
| 57 | |
|
| 58 | 1 | return groupId; |
| 59 | |
} |
| 60 | |
|
| 61 | |
public static GroupId fromJson(String jsonId) { |
| 62 | 70 | Type idSpecEnum = Type.jsonValueOf(jsonId); |
| 63 | 70 | if (idSpecEnum != null) { |
| 64 | 69 | return new GroupId(idSpecEnum, null); |
| 65 | |
} |
| 66 | |
|
| 67 | 1 | return new GroupId(Type.groupId, jsonId); |
| 68 | |
} |
| 69 | |
|
| 70 | |
|
| 71 | |
@Override |
| 72 | |
public boolean equals(Object o) { |
| 73 | 20 | if (!(o instanceof GroupId)) { |
| 74 | 0 | return false; |
| 75 | |
} |
| 76 | |
|
| 77 | 20 | GroupId actual = (GroupId) o; |
| 78 | 20 | return this.type == actual.type |
| 79 | |
&& StringUtils.equals(this.groupId, actual.groupId); |
| 80 | |
} |
| 81 | |
|
| 82 | |
@Override |
| 83 | |
public int hashCode() { |
| 84 | 0 | int groupHashCode = 0; |
| 85 | 0 | if (this.groupId != null) { |
| 86 | 0 | groupHashCode = this.groupId.hashCode(); |
| 87 | |
} |
| 88 | 0 | return this.type.hashCode() + groupHashCode; |
| 89 | |
} |
| 90 | |
} |