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.sheet;
23
24 import java.io.Serializable;
25 import java.util.Objects;
26
27 /**
28 * Represents the data associated with the update of a single cell.
29 *
30 * @author Mark Lassiter / Melloware
31 * @since 6.2
32 */
33 public class SheetUpdate implements Serializable {
34
35 private static final long serialVersionUID = 1L;
36
37 private final transient Object rowData;
38
39 private final transient Object oldValue;
40
41 private final transient Object newValue;
42
43 private final transient Object rowKey;
44
45 private final int colIndex;
46
47 private transient String toString;
48
49 private transient int hashCode;
50
51 /**
52 * Constructs an instance representing a single cell update.
53 *
54 * @param rowKey the row key of the row being updated
55 * @param colIndex the column index of the column being updated
56 * @param rowData the rowData associated with the row being updated
57 * @param oldValue the old cell value
58 * @param newValue the new cell value
59 */
60 public SheetUpdate(Object rowKey, int colIndex, Object rowData,
61 Object oldValue, Object newValue) {
62 this.rowKey = rowKey;
63 this.colIndex = colIndex;
64 this.rowData = rowData;
65 this.oldValue = oldValue;
66 this.newValue = newValue;
67 }
68
69 @Override
70 public int hashCode() {
71 if (hashCode == 0) {
72 hashCode = 7;
73 hashCode = 73 * hashCode + Objects.hashCode(rowKey);
74 hashCode = 73 * hashCode + colIndex;
75 }
76 return hashCode;
77 }
78
79 @Override
80 public boolean equals(Object obj) {
81 if (this == obj) {
82 return true;
83 }
84 if (obj == null) {
85 return false;
86 }
87 if (getClass() != obj.getClass()) {
88 return false;
89 }
90 final SheetUpdate other = (SheetUpdate) obj;
91 if (colIndex != other.colIndex) {
92 return false;
93 }
94 if (!Objects.equals(rowKey, other.rowKey)) {
95 return false;
96 }
97 return true;
98 }
99
100 @Override
101 public String toString() {
102 if (toString == null) {
103 toString = "SheetUpdate{" + "rowData=" + rowData + ", oldValue=" + oldValue
104 + ", newValue=" + newValue + ", rowKey=" + rowKey + ", colIndex=" + colIndex + '}';
105 }
106 return toString;
107 }
108
109 /**
110 * The rowData value.
111 *
112 * @return the rowData the row data for this update
113 */
114 public Object getRowData() {
115 return rowData;
116 }
117
118 /**
119 * The oldValue value.
120 *
121 * @return the oldValue
122 */
123 public Object getOldValue() {
124 return oldValue;
125 }
126
127 /**
128 * The newValue value.
129 *
130 * @return the newValue
131 */
132 public Object getNewValue() {
133 return newValue;
134 }
135
136 /**
137 * The rowKey value.
138 *
139 * @return the rowKey
140 */
141 public Object getRowKey() {
142 return rowKey;
143 }
144
145 /**
146 * The colIndex value.
147 *
148 * @return the colIndex
149 */
150 public int getColIndex() {
151 return colIndex;
152 }
153
154 }