1 5 package com.tc.object.walker; 6 7 import java.lang.reflect.Field ; 8 9 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) { throw new NullPointerException (); } 37 if (!(o instanceof FieldData)) { throw new ClassCastException (o.getClass().getName()); } 38 39 FieldData other = (FieldData) o; 40 41 String thisFieldName = field.getName(); 42 String otherFieldName = other.field.getName(); 43 44 int i = thisFieldName.compareTo(otherFieldName); 45 if (i == 0) { 46 return field.getDeclaringClass().getName().compareTo(other.field.getDeclaringClass().getName()); 47 } else { 48 return i; 49 } 50 } 51 52 Field getField() { 53 return field; 54 } 55 } | Popular Tags |