01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: FieldMetadata.java,v 1.10.2.2 2008/01/07 15:14:20 cwl Exp $
07: */
08:
09: package com.sleepycat.persist.model;
10:
11: import java.io.Serializable;
12:
13: /**
14: * The metadata for a key field. This class defines common properties for
15: * singular and composite key fields.
16: *
17: * <p>{@code FieldMetadata} objects are thread-safe. Multiple threads may
18: * safely call the methods of a shared {@code FieldMetadata} object.</p>
19: *
20: * @author Mark Hayes
21: */
22: public class FieldMetadata implements Serializable {
23:
24: private static final long serialVersionUID = -9037650229184174279L;
25:
26: private String name;
27: private String className;
28: private String declaringClassName;
29:
30: /**
31: * Used by an {@code EntityModel} to construct field metadata.
32: */
33: public FieldMetadata(String name, String className,
34: String declaringClassName) {
35: this .name = name;
36: this .className = className;
37: this .declaringClassName = declaringClassName;
38: }
39:
40: /**
41: * Returns the field name.
42: */
43: public String getName() {
44: return name;
45: }
46:
47: /**
48: * Returns the class name of the field type.
49: */
50: public String getClassName() {
51: return className;
52: }
53:
54: /**
55: * Returns the name of the class where the field is declared.
56: */
57: public String getDeclaringClassName() {
58: return declaringClassName;
59: }
60:
61: @Override
62: public boolean equals(Object other) {
63: if (other instanceof FieldMetadata) {
64: FieldMetadata o = (FieldMetadata) other;
65: return ClassMetadata.nullOrEqual(name, o.name)
66: && ClassMetadata
67: .nullOrEqual(className, o.className)
68: && ClassMetadata.nullOrEqual(declaringClassName,
69: o.declaringClassName);
70: } else {
71: return false;
72: }
73: }
74:
75: @Override
76: public int hashCode() {
77: return ClassMetadata.hashCode(name)
78: + ClassMetadata.hashCode(className)
79: + ClassMetadata.hashCode(declaringClassName);
80: }
81: }
|