KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > change > event > ArrayElementChangeEvent


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.change.event;
5
6 import com.tc.object.ObjectID;
7 import com.tc.object.change.TCChangeBufferEvent;
8 import com.tc.object.dna.api.DNAWriter;
9
10 public class ArrayElementChangeEvent implements TCChangeBufferEvent {
11
12   private final Object JavaDoc value;
13   private final int index;
14   private final int length;
15
16   public ArrayElementChangeEvent(int index, Object JavaDoc 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 JavaDoc 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 JavaDoc 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 }
59
Popular Tags