KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > PropertyEntry


1 /*****************************************************************************
2  * Copyright (C) Codehaus.org. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on Apr 5, 2005
10  *
11  * Author Ben Yu
12  * ZBS
13  */

14 package jfun.yan;
15
16 /**
17  * This class represents a property of an object.
18  * Objects of this class may be found in the resolution trace
19  * of a YanException object to represent a frame of a property instantiation.
20  * <p>
21  * Codehaus.org.
22  *
23  * @author Ben Yu
24  *
25  */

26 public final class PropertyEntry implements java.io.Serializable JavaDoc {
27   private final Object JavaDoc obj;
28   private final Object JavaDoc key;
29   
30   /**
31    * Create a PropertyEntry object.
32    * @param obj the object that has the property.
33    * @param key the property key.
34    */

35   public PropertyEntry(final Object JavaDoc obj, final Object JavaDoc key) {
36     this.obj = obj;
37     this.key = key;
38   }
39   
40   /**
41    * Gets the property key.
42    * @return the key.
43    */

44   public Object JavaDoc getPropertyKey() {
45     return key;
46   }
47   /**
48    * Gets the object that has the property.
49    * @return the object.
50    */

51   public Object JavaDoc getObject() {
52     return obj;
53   }
54   
55   public boolean equals(Object JavaDoc o) {
56     if(o instanceof PropertyEntry){
57       final PropertyEntry other = (PropertyEntry)o;
58       return eq(key, other.key) && eq(obj, other.obj);
59     }
60     else return false;
61   }
62   private static boolean eq(Object JavaDoc o1, Object JavaDoc o2){
63     return o1==null?o2==null:o1.equals(o2);
64   }
65   private static int hcode(Object JavaDoc o){
66     return o==null?0:o.hashCode();
67   }
68   public int hashCode() {
69     return hcode(obj)*31+hcode(key);
70   }
71   public String JavaDoc toString() {
72     return "property " + key + " of <" + obj + ">";
73   }
74 }
75
Popular Tags