View Javadoc
1   /*
2    * Copyright (c) 2011-2024 PrimeFaces Extensions
3    *
4    *  Permission is hereby granted, free of charge, to any person obtaining a copy
5    *  of this software and associated documentation files (the "Software"), to deal
6    *  in the Software without restriction, including without limitation the rights
7    *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    *  copies of the Software, and to permit persons to whom the Software is
9    *  furnished to do so, subject to the following conditions:
10   *
11   *  The above copyright notice and this permission notice shall be included in
12   *  all copies or substantial portions of the Software.
13   *
14   *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20   *  THE SOFTWARE.
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          // generate key
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          // generate key
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 }