01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.change.event;
05:
06: import com.tc.object.ObjectID;
07: import com.tc.object.change.TCChangeBufferEvent;
08: import com.tc.object.dna.api.DNAWriter;
09:
10: public class ArrayElementChangeEvent implements TCChangeBufferEvent {
11:
12: private final Object value;
13: private final int index;
14: private final int length;
15:
16: public ArrayElementChangeEvent(int index, Object value) {
17: this (index, value, -1);
18: }
19:
20: /**
21: * @param index index in the array for the changed element or start index for the subarray
22: * @param value new value or copied array for the subarray
23: * @param legnth the length of the subarray
24: */
25: public ArrayElementChangeEvent(int index, Object value, int length) {
26: this .index = index;
27: this .value = value;
28: this .length = length;
29: }
30:
31: public void write(DNAWriter to) {
32: if (isSubarray()) {
33: to.addSubArrayAction(index, value, length);
34: } else {
35: to.addArrayElementAction(index, value);
36: }
37: }
38:
39: public Object getValue() {
40: return value;
41: }
42:
43: public int getIndex() {
44: return index;
45: }
46:
47: public boolean isReference() {
48: return value instanceof ObjectID;
49: }
50:
51: public boolean isSubarray() {
52: return length != -1;
53: }
54:
55: public int getLength() {
56: return length;
57: }
58: }
|