1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.primefaces.extensions.model.keynote;
23
24 import java.io.Serializable;
25 import java.util.Objects;
26 import java.util.UUID;
27
28 import org.primefaces.extensions.model.common.KeyData;
29
30 public class KeynoteItem implements KeyData, Serializable {
31
32 public static final String DEFAULT_TYPE = "default";
33 private static final long serialVersionUID = 1L;
34
35 private String key;
36 private Serializable data;
37 private String type;
38
39 public KeynoteItem() {
40
41 setKey(generateKey());
42 }
43
44 public KeynoteItem(final Serializable data) {
45 this();
46 this.data = data;
47 type = DEFAULT_TYPE;
48 }
49
50 public KeynoteItem(final Serializable data, final String type) {
51 this.data = data;
52 if (type != null) {
53 this.type = type;
54 }
55 else {
56 this.type = DEFAULT_TYPE;
57 }
58
59
60 setKey(generateKey());
61 }
62
63 @Override
64 public String getKey() {
65 return key;
66 }
67
68 @Override
69 public void setKey(final String key) {
70 this.key = key;
71 }
72
73 @Override
74 public Serializable getData() {
75 return data;
76 }
77
78 @Override
79 public void setData(final Serializable data) {
80 this.data = data;
81 }
82
83 public String getType() {
84 return type;
85 }
86
87 public static String generateKey() {
88 return UUID.randomUUID().toString().replace("-", "").substring(0, 8);
89 }
90
91 @Override
92 public boolean equals(Object o) {
93 if (this == o) {
94 return true;
95 }
96 if (!(o instanceof KeynoteItem)) {
97 return false;
98 }
99 KeynoteItem that = (KeynoteItem) o;
100 return Objects.equals(getKey(), that.getKey());
101 }
102
103 @Override
104 public int hashCode() {
105 return Objects.hash(getKey());
106 }
107
108 @Override
109 public String toString() {
110 final StringBuilder builder = new StringBuilder();
111 builder.append("KeynoteItem [key=");
112 builder.append(key);
113 builder.append(", data=");
114 builder.append(data);
115 builder.append(", type=");
116 builder.append(type);
117 builder.append("]");
118 return builder.toString();
119 }
120
121 }