01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.walker;
06:
07: import java.lang.reflect.Field;
08:
09: class FieldData implements Comparable {
10:
11: private final Field field;
12: private boolean isShadowed;
13:
14: FieldData(Field field) {
15: this .field = field;
16: this .field.setAccessible(true);
17: }
18:
19: boolean isShadowed() {
20: return isShadowed;
21: }
22:
23: void setShadowed(boolean b) {
24: this .isShadowed = b;
25: }
26:
27: Object getValue(Object instance) {
28: try {
29: return field.get(instance);
30: } catch (Exception e) {
31: throw new RuntimeException(e);
32: }
33: }
34:
35: public int compareTo(Object o) {
36: if (o == null) {
37: throw new NullPointerException();
38: }
39: if (!(o instanceof FieldData)) {
40: throw new ClassCastException(o.getClass().getName());
41: }
42:
43: FieldData other = (FieldData) o;
44:
45: String this FieldName = field.getName();
46: String otherFieldName = other.field.getName();
47:
48: int i = this FieldName.compareTo(otherFieldName);
49: if (i == 0) {
50: return field.getDeclaringClass().getName().compareTo(
51: other.field.getDeclaringClass().getName());
52: } else {
53: return i;
54: }
55: }
56:
57: Field getField() {
58: return field;
59: }
60: }
|