From ad8bd5c3b55adc4c5052e850ad407cc04a70d246 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 21 Oct 2007 16:14:05 +0000 Subject: Assign number to properties. --- .../carbonado/info/StorableIntrospector.java | 24 +++++++++++++++++++--- .../amazon/carbonado/info/StorableProperty.java | 8 ++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/info') diff --git a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java index b7f7744..12fbc01 100644 --- a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java +++ b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java @@ -228,9 +228,16 @@ public class StorableIntrospector { // Now that the StorableInfo object has been constructed, assign it // to all properties to prevent it from being prematurely uncached. - for (StorableProperty property : properties.values()) { - if (property instanceof SimpleProperty) { - ((SimpleProperty)property).setEnclosingInfo(info); + // Also assign number now that properties have been sorted. + { + int number = 0; + for (StorableProperty property : properties.values()) { + if (property instanceof SimpleProperty) { + SimpleProperty sp = (SimpleProperty) property; + sp.setEnclosingInfo(info); + sp.setNumber(number); + } + number++; } } @@ -1584,6 +1591,9 @@ public class StorableIntrospector { // Resolved derived to properties. private ChainedProperty[] mDerivedTo; + // Resolved number. + private int mNumber = -1; + // Reference to enclosing StorableInfo. This reference exists to // prevent the StorableInfo from being uncached so as long as a // reference from a property exists. @@ -1621,6 +1631,10 @@ public class StorableIntrospector { return mBeanProperty.getType(); } + public final int getNumber() { + return mNumber; + } + public final Class getEnclosingType() { return mEnclosingType; } @@ -1838,6 +1852,10 @@ public class StorableIntrospector { app.append('}'); } + void setNumber(int number) { + mNumber = number; + } + void setEnclosingInfo(StorableInfo info) { mEnclosingInfo = info; } diff --git a/src/main/java/com/amazon/carbonado/info/StorableProperty.java b/src/main/java/com/amazon/carbonado/info/StorableProperty.java index e61c5e9..53b5098 100644 --- a/src/main/java/com/amazon/carbonado/info/StorableProperty.java +++ b/src/main/java/com/amazon/carbonado/info/StorableProperty.java @@ -39,6 +39,14 @@ public interface StorableProperty extends Appender { */ Class getType(); + /** + * Returns the zero-based numerical position of this property within its + * enclosing type. + * + * @since 1.2 + */ + int getNumber(); + /** * Returns the enclosing type of this property. */ -- cgit v1.2.3