From b503b09219e7aad8bb5d067ccd9e09d248590451 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 22 Sep 2006 06:37:59 +0000 Subject: Added method to get the tail of a chained property. --- .../com/amazon/carbonado/info/ChainedProperty.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/amazon/carbonado/info/ChainedProperty.java b/src/main/java/com/amazon/carbonado/info/ChainedProperty.java index e0b1121..1c4022d 100644 --- a/src/main/java/com/amazon/carbonado/info/ChainedProperty.java +++ b/src/main/java/com/amazon/carbonado/info/ChainedProperty.java @@ -213,7 +213,7 @@ public class ChainedProperty implements Appender { new StorableProperty[getChainCount() + 1 + propChainCount]; int pos = 0; - if (newChain.length > 1) { + if (getChainCount() > 0) { System.arraycopy(mChain, 0, newChain, 0, mChain.length); pos = mChain.length; } @@ -243,6 +243,24 @@ public class ChainedProperty implements Appender { return get(mPrime, newChain); } + /** + * Returns a new ChainedProperty which contains everything that follows + * this ChainedProperty's prime property. + * + * @throws IllegalStateException if chain count is zero + */ + public ChainedProperty tail() { + if (getChainCount() == 0) { + throw new IllegalStateException(); + } + if (getChainCount() == 1) { + return get(mChain[0]); + } + StorableProperty[] newChain = new StorableProperty[getChainCount() - 1]; + System.arraycopy(mChain, 1, newChain, 0, newChain.length); + return get(mChain[0], newChain); + } + @Override public int hashCode() { int hash = mPrime.hashCode(); -- cgit v1.2.3