KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > common > UnorderedCollectionDiff


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.common;
13
14 import com.versant.core.util.OIDObjectOutput;
15 import com.versant.core.util.OIDObjectInput;
16
17 import java.io.IOException JavaDoc;
18
19 /**
20  * This holds the differences between two unordered collections. It is stored
21  * in the new State when changes to an unordered collection field are persisted.
22  */

23 public class UnorderedCollectionDiff extends CollectionDiff {
24
25     public UnorderedCollectionDiff() {
26     }
27
28     public UnorderedCollectionDiff(VersantFieldMetaData fmd) {
29         super(fmd);
30     }
31
32     /**
33      * The deleted values (null if none).
34      */

35     public Object JavaDoc[] deletedValues;
36
37     protected Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
38         UnorderedCollectionDiff cloned = null;
39         try {
40             cloned = (UnorderedCollectionDiff)super.clone();
41             cloned.deletedValues = new Object JavaDoc[deletedValues.length];
42             System.arraycopy(deletedValues, 0, cloned.deletedValues, 0,
43                     deletedValues.length);
44             return cloned;
45         } catch (CloneNotSupportedException JavaDoc e) {
46             e.printStackTrace();
47         }
48         return cloned;
49     }
50
51     public String JavaDoc toString() {
52         return "<UnorderedCollectionDiff: status = " + status + ": amount added ="
53                 + (insertedValues != null ? insertedValues.length : -1)
54                 + " deleted amount = "
55                 + (deletedValues != null ? deletedValues.length : -1) + ">";
56     }
57
58     public void writeExternal(OIDObjectOutput out) throws IOException JavaDoc {
59         super.writeExternal(out);
60         write(out, fmd.getElementTypeCode(), fmd.isElementTypePC(),
61                 deletedValues);
62     }
63
64     public void readExternal(OIDObjectInput in) throws IOException JavaDoc,
65             ClassNotFoundException JavaDoc {
66         super.readExternal(in);
67         deletedValues = read(in, fmd.getElementTypeCode(),
68                 fmd.isElementTypePC());
69     }
70
71     public void dump() {
72         if (Debug.DEBUG) {
73             Debug.OUT.println("ToBeAdded");
74         }
75         if (insertedValues != null) {
76             for (int i = 0; i < insertedValues.length; i++) {
77                 if (Debug.DEBUG) {
78                     Debug.OUT.println("inserted = " + insertedValues[i]);
79                 }
80             }
81         }
82
83         if (Debug.DEBUG) {
84             Debug.OUT.println("ToBeDeleted");
85         }
86         if (deletedValues != null) {
87             for (int i = 0; i < deletedValues.length; i++) {
88                 if (Debug.DEBUG) {
89                     Debug.OUT.println("deleted = " + deletedValues[i]);
90                 }
91             }
92         }
93     }
94
95 }
96
Popular Tags