com.amazon.carbonado.info
Class ChainedProperty<S extends Storable>

java.lang.Object
  extended by com.amazon.carbonado.info.ChainedProperty<S>
All Implemented Interfaces:
Appender, Serializable

public class ChainedProperty<S extends Storable>
extends Object
implements Serializable, Appender

Represents a property to filter on or to order by. Properties may be specified in a simple form, like "firstName", or in a chained form, like "address.state". In both forms, the first property is the "prime" property. All properties that follow are chained.

Author:
Brian S O'Neill
See Also:
Serialized Form

Method Summary
 ChainedProperty<S> append(ChainedProperty<?> property)
          Returns a new ChainedProperty with another property appended.
 ChainedProperty<S> append(StorableProperty<?> property)
          Returns a new ChainedProperty with another property appended.
 ChainedProperty<S> append(StorableProperty<?> property, boolean outerJoin)
          Returns a new ChainedProperty with another property appended.
 void appendTo(Appendable app)
          Appends the chained property formatted as "name.subname.subsubname".
 boolean equals(Object obj)
           
static
<S extends Storable>
ChainedProperty<S>
get(StorableProperty<S> prime)
          Returns a canonical instance which has no chain.
static
<S extends Storable>
ChainedProperty<S>
get(StorableProperty<S> prime, StorableProperty<?>... chain)
          Returns a canonical instance.
static
<S extends Storable>
ChainedProperty<S>
get(StorableProperty<S> prime, StorableProperty<?>[] chain, boolean[] outerJoin)
          Returns a canonical instance.
 int getChainCount()
          Returns amount of properties chained from prime property, which may be zero.
 StorableProperty<?> getChainedProperty(int index)
           
 StorableProperty<?> getLastProperty()
          Returns the last property in the chain, or the prime property if chain is empty.
 StorableProperty<S> getPrimeProperty()
           
 Class<?> getType()
          Returns the type of the last property in the chain, or of the prime property if the chain is empty.
 int hashCode()
           
 boolean isDerived()
          Returns true if any property in the chain is derived.
 boolean isNullable()
          Returns true if any property in the chain can be null.
 boolean isOuterJoin(int index)
          Returns true if the property at the given index should be treated as an outer join.
static
<S extends Storable>
ChainedProperty<S>
parse(StorableInfo<S> info, String str)
          Parses a chained property.
 ChainedProperty<?> tail()
          Returns a new ChainedProperty which contains everything that follows this ChainedProperty's prime property.
 String toString()
          Returns the chained property formatted as "name.subname.subsubname".
 ChainedProperty<S> trim()
          Returns a new ChainedProperty with the last property in the chain removed.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

get

public static <S extends Storable> ChainedProperty<S> get(StorableProperty<S> prime)
Returns a canonical instance which has no chain.

Throws:
IllegalArgumentException - if prime is null

get

public static <S extends Storable> ChainedProperty<S> get(StorableProperty<S> prime,
                                                          StorableProperty<?>... chain)
Returns a canonical instance.

Throws:
IllegalArgumentException - if prime is null or if chained properties are not formed properly

get

public static <S extends Storable> ChainedProperty<S> get(StorableProperty<S> prime,
                                                          StorableProperty<?>[] chain,
                                                          boolean[] outerJoin)
Returns a canonical instance.

Throws:
IllegalArgumentException - if prime is null or if chained properties are not formed properly
Since:
1.2

parse

public static <S extends Storable> ChainedProperty<S> parse(StorableInfo<S> info,
                                                            String str)
                                                 throws IllegalArgumentException
Parses a chained property.

Parameters:
info - Info for Storable type containing property
str - string to parse
Throws:
IllegalArgumentException - if any parameter is null or string format is incorrect

getPrimeProperty

public StorableProperty<S> getPrimeProperty()

getType

public Class<?> getType()
Returns the type of the last property in the chain, or of the prime property if the chain is empty.


isNullable

public boolean isNullable()
Returns true if any property in the chain can be null.

Since:
1.2
See Also:
Nullable

isDerived

public boolean isDerived()
Returns true if any property in the chain is derived.

Since:
1.2
See Also:
Derived

getLastProperty

public StorableProperty<?> getLastProperty()
Returns the last property in the chain, or the prime property if chain is empty.


getChainCount

public int getChainCount()
Returns amount of properties chained from prime property, which may be zero.


getChainedProperty

public StorableProperty<?> getChainedProperty(int index)
                                       throws IndexOutOfBoundsException
Parameters:
index - valid range is 0 to chainCount - 1
Throws:
IndexOutOfBoundsException

isOuterJoin

public boolean isOuterJoin(int index)
                    throws IndexOutOfBoundsException
Returns true if the property at the given index should be treated as an outer join. Index zero is the prime property.

Parameters:
index - valid range is 0 to chainCount
Throws:
IndexOutOfBoundsException
Since:
1.2

append

public ChainedProperty<S> append(StorableProperty<?> property)
Returns a new ChainedProperty with another property appended.


append

public ChainedProperty<S> append(StorableProperty<?> property,
                                 boolean outerJoin)
Returns a new ChainedProperty with another property appended.

Parameters:
outerJoin - pass true for outer join
Since:
1.2

append

public ChainedProperty<S> append(ChainedProperty<?> property)
Returns a new ChainedProperty with another property appended.


trim

public ChainedProperty<S> trim()
Returns a new ChainedProperty with the last property in the chain removed.

Throws:
IllegalStateException - if chain count is zero

tail

public ChainedProperty<?> tail()
Returns a new ChainedProperty which contains everything that follows this ChainedProperty's prime property.

Throws:
IllegalStateException - if chain count is zero

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Returns the chained property formatted as "name.subname.subsubname". This format is parseable only if the chain is composed of valid many-to-one joins.

Overrides:
toString in class Object

appendTo

public void appendTo(Appendable app)
              throws IOException
Appends the chained property formatted as "name.subname.subsubname". This format is parseable only if the chain is composed of valid many-to-one joins.

Specified by:
appendTo in interface Appender
Parameters:
app - Appendable object to receive string representation
Throws:
IOException - if thrown from given Appendable


Copyright © 2006-2009 Amazon Technologies, Inc.. All Rights Reserved.