01: /*
02: * Copyright (C) 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 10. April 2007 by Guilherme Silveira
10: */
11: package com.thoughtworks.xstream.converters.reflection;
12:
13: /**
14: * A field key.
15: *
16: * @author Guilherme Silveira
17: * @author Jörg Schaible
18: */
19: public class FieldKey {
20: final private String fieldName;
21: final private Class declaringClass;
22: final private int depth;
23: final private int order;
24:
25: public FieldKey(String fieldName, Class declaringClass, int order) {
26: if (fieldName == null || declaringClass == null) {
27: throw new IllegalArgumentException(
28: "fieldName or declaringClass is null");
29: }
30: this .fieldName = fieldName;
31: this .declaringClass = declaringClass;
32: this .order = order;
33: Class c = declaringClass;
34: int i = 0;
35: while (c.getSuperclass() != null) {
36: i++;
37: c = c.getSuperclass();
38: }
39: depth = i;
40: }
41:
42: public String getFieldName() {
43: return this .fieldName;
44: }
45:
46: public Class getDeclaringClass() {
47: return this .declaringClass;
48: }
49:
50: public int getDepth() {
51: return this .depth;
52: }
53:
54: public int getOrder() {
55: return this .order;
56: }
57:
58: public boolean equals(Object o) {
59: if (this == o)
60: return true;
61: if (!(o instanceof FieldKey))
62: return false;
63:
64: final FieldKey fieldKey = (FieldKey) o;
65:
66: if (!declaringClass.equals(fieldKey.declaringClass))
67: return false;
68: if (!fieldName.equals(fieldKey.fieldName))
69: return false;
70:
71: return true;
72: }
73:
74: public int hashCode() {
75: int result;
76: result = fieldName.hashCode();
77: result = 29 * result + declaringClass.hashCode();
78: return result;
79: }
80:
81: public String toString() {
82: return "FieldKey{" + "order=" + order + ", writer=" + depth
83: + ", declaringClass=" + declaringClass
84: + ", fieldName='" + fieldName + "'" + "}";
85: }
86:
87: }
|