KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > graph > NodeDiff


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.graph;
21
22 /**
23  * An abstract superclass of operations on individual nodes and arcs in a digraph.
24  *
25  * @since 1.2
26  * @author Andrus Adamchik
27  */

28 public abstract class NodeDiff implements GraphDiff, Comparable JavaDoc {
29
30     protected int diffId;
31     protected Object JavaDoc nodeId;
32
33     public NodeDiff(Object JavaDoc nodeId) {
34         this.nodeId = nodeId;
35     }
36
37     public NodeDiff(Object JavaDoc nodeId, int diffId) {
38         this.nodeId = nodeId;
39         this.diffId = diffId;
40     }
41
42     public boolean isNoop() {
43         return false;
44     }
45
46     public abstract void apply(GraphChangeHandler tracker);
47
48     public abstract void undo(GraphChangeHandler tracker);
49
50     public Object JavaDoc getNodeId() {
51         return nodeId;
52     }
53
54     /**
55      * Returns an id of this diff that can be used for various purposes, such as
56      * identifying the order of the diff in a sequence.
57      */

58     public int getDiffId() {
59         return diffId;
60     }
61
62     /**
63      * Sets an id of this diff that can be used for various purposes, such as identifying
64      * the order of the diff in a sequence.
65      */

66     public void setDiffId(int diffId) {
67         this.diffId = diffId;
68     }
69
70     /**
71      * Implements a Comparable interface method to compare based on diffId property.
72      */

73     public int compareTo(Object JavaDoc o) {
74         if (!(o instanceof NodeDiff)) {
75             throw new IllegalArgumentException JavaDoc("Can't compare to " + o);
76         }
77
78         return diffId - ((NodeDiff) o).getDiffId();
79     }
80 }
81
Popular Tags