KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > databinding > observable > value > ValueDiff


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

11
12 package org.eclipse.core.databinding.observable.value;
13
14 import org.eclipse.core.databinding.observable.Diffs;
15
16 /**
17  * @since 1.0
18  *
19  */

20 public abstract class ValueDiff {
21     /**
22      * Creates a value diff.
23      */

24     public ValueDiff() {
25     }
26
27     /**
28      * @return the old value
29      */

30     public abstract Object JavaDoc getOldValue();
31
32     /**
33      * @return the new value
34      */

35     public abstract Object JavaDoc getNewValue();
36
37     public boolean equals(Object JavaDoc obj) {
38         if (obj instanceof ValueDiff) {
39             ValueDiff val = (ValueDiff) obj;
40
41             return Diffs.equals(val.getNewValue(), getNewValue())
42                     && Diffs.equals(val.getOldValue(), getOldValue());
43
44         }
45         return false;
46     }
47         
48     public int hashCode() {
49         final int prime = 31;
50         int result = 1;
51         Object JavaDoc nv = getNewValue();
52         Object JavaDoc ov = getOldValue();
53         result = prime * result + ((nv == null) ? 0 : nv.hashCode());
54         result = prime * result + ((ov == null) ? 0 : ov.hashCode());
55         return result;
56     }
57
58     /**
59      * @see java.lang.Object#toString()
60      */

61     public String JavaDoc toString() {
62         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
63         buffer
64             .append(getClass().getName())
65             .append("{oldValue [") //$NON-NLS-1$
66
.append(getOldValue() != null ? getOldValue().toString() : "null") //$NON-NLS-1$
67
.append("], newValue [") //$NON-NLS-1$
68
.append(getNewValue() != null ? getNewValue().toString() : "null") //$NON-NLS-1$
69
.append("]}"); //$NON-NLS-1$
70

71         return buffer.toString();
72     }
73 }
74
Popular Tags