1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package nl.hippo.client.api.event;
17
18 import java.io.Serializable;
19
20 public class NamedEvent implements Serializable {
21
22 private static final long serialVersionUID = 1L;
23 private static final String[] TYPE_NAMES = new String[] { "update", "create", "delete", "null" };
24
25 public static final int UPDATE_TYPE = 0;
26 public static final int CREATE_TYPE = 1;
27 public static final int DELETE_TYPE = 2;
28 public static final int NULL_TYPE = 3;
29
30 protected int type;
31 protected String namespace;
32 protected String path;
33
34 protected final String name;
35
36 public NamedEvent(String name) {
37 if(name != null) {
38 this.name = name.toLowerCase();
39 } else {
40 this.name = name;
41 }
42 }
43
44 public NamedEvent(int type, String namespace, String path) {
45 this.type = type;
46 if(namespace != null) {
47 this.namespace = namespace.toLowerCase();
48 } else {
49 this.namespace = namespace;
50 }
51 if(path != null) {
52 this.path = path.toLowerCase();
53 } else {
54 this.path = path;
55 }
56
57 this.name = "/" + this.namespace + this.path;
58 }
59
60 public String getName() {
61 return name;
62 }
63
64 public String getPath() {
65 return path;
66 }
67
68 public String getType() {
69 return TYPE_NAMES[type];
70 }
71
72 public String getNamespace() {
73 return namespace;
74 }
75
76 public boolean equals(Object obj) {
77 if (obj != null && obj instanceof NamedEvent) {
78 return name.equalsIgnoreCase(((NamedEvent) obj).getName());
79 }
80 return false;
81 }
82
83 public int hashCode() {
84 return name.hashCode();
85 }
86
87 public String toString() {
88 return "NamedEvent[" + name + "]";
89 }
90 }