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

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

public class StorableIndex<S extends Storable>
extends Object
implements Appender

Represents an index that must be defined for a specific Storable type.

Author:
Brian S O'Neill
See Also:
Index

Constructor Summary
StorableIndex(Class<S> type, IndexInfo indexInfo)
          Creates a StorableIndex from an IndexInfo.
StorableIndex(OrderedProperty<S>[] properties, Direction direction)
          Creates a StorableIndex from OrderedProperties.
StorableIndex(StorableKey<S> key, Direction direction)
          Creates a StorableIndex from a StorableKey.
StorableIndex(StorableProperty<S>[] properties, Direction[] directions)
          Creates a StorableIndex from the given properties and matching directions.
StorableIndex(StorableProperty<S>[] properties, Direction[] directions, boolean unique)
          Creates a StorableIndex from the given properties and matching directions.
StorableIndex(StorableProperty<S>[] properties, Direction[] directions, boolean unique, boolean clustered)
          Creates a StorableIndex from the given properties and matching directions.
 
Method Summary
 StorableIndex<S> addProperty(StorableProperty<S> property, Direction direction)
          Returns a StorableIndex with the given property added.
 void appendTo(Appendable app)
          Appends the same results as toString, but without the "StorableIndex" prefix.
 StorableIndex<S> clustered(boolean clustered)
          Returns a StorableIndex instance which is clustered or not.
 boolean equals(Object obj)
           
 String getNameDescriptor()
          Converts this index into a parseable name descriptor string, whose general format is:
 OrderedProperty<S>[] getOrderedProperties()
          Returns a new array with all the properties in it, with directions folded in.
 OrderedProperty<S> getOrderedProperty(int index)
          Returns a specific property in this index, with the direction folded in.
 StorableProperty<S>[] getProperties()
          Returns a new array with all the properties in it.
 StorableProperty<S> getProperty(int index)
          Returns a specific property in this index.
 int getPropertyCount()
          Returns the count of properties in this index.
 Direction getPropertyDirection(int index)
          Returns the requested direction of a specific property in this index.
 Direction[] getPropertyDirections()
          Returns a new array with all the property directions in it.
 Class<S> getStorableType()
          Returns the type of storable this index applies to.
 String getTypeDescriptor()
          Converts this index into a parseable type descriptor string, which basically consists of Java type descriptors appended together.
 int hashCode()
           
 boolean isClustered()
          Returns true if index is known to be clustered, which means it defines the physical ordering of storables.
 boolean isUnique()
           
static
<S extends Storable>
StorableIndex<S>
parseNameDescriptor(String desc, StorableInfo<S> info)
          Parses an index descriptor and returns an index object.
 StorableIndex<S> reverse()
          Returns a StorableIndex instance with all the properties reversed.
 StorableIndex<S> setDefaultDirection(Direction direction)
          Returns a StorableIndex instance with all unspecified directions set to the given direction.
 String toString()
           
 StorableIndex<S> unique(boolean unique)
          Returns a StorableIndex instance which is unique or not.
 StorableIndex<S> uniquify(StorableKey<S> key)
          Returns a StorableIndex which is unique, possibly by appending properties from the given key.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StorableIndex

public StorableIndex(StorableProperty<S>[] properties,
                     Direction[] directions)
Creates a StorableIndex from the given properties and matching directions. Both arrays must match length.

Throws:
IllegalArgumentException - if any argument is null, if lengths do not match, or if any length is zero.

StorableIndex

public StorableIndex(StorableProperty<S>[] properties,
                     Direction[] directions,
                     boolean unique)
Creates a StorableIndex from the given properties and matching directions. Both arrays must match length. Allows specification of the uniqueness of the index.

Parameters:
properties -
directions -
unique -

StorableIndex

public StorableIndex(StorableProperty<S>[] properties,
                     Direction[] directions,
                     boolean unique,
                     boolean clustered)
Creates a StorableIndex from the given properties and matching directions. Both arrays must match length. Allows specification of the uniqueness of the index as well as clustered option.

Parameters:
properties -
directions -
unique -
clustered -

StorableIndex

public StorableIndex(StorableKey<S> key,
                     Direction direction)
Creates a StorableIndex from a StorableKey.

Parameters:
direction - optional direction to apply to each key property that has an unspecified direction
Throws:
IllegalArgumentException - if key is null or it has no properties

StorableIndex

public StorableIndex(OrderedProperty<S>[] properties,
                     Direction direction)
Creates a StorableIndex from OrderedProperties.

Parameters:
direction - optional direction to apply to each property that has an unspecified direction
Throws:
IllegalArgumentException - if no properties supplied

StorableIndex

public StorableIndex(Class<S> type,
                     IndexInfo indexInfo)
Creates a StorableIndex from an IndexInfo.

Parameters:
type - type of storable index is defined for
indexInfo - IndexInfo returned from storage object
Throws:
IllegalArgumentException - if any argument is null, if any properties are invalid, or if index info has no properties
Method Detail

parseNameDescriptor

public static <S extends Storable> StorableIndex<S> parseNameDescriptor(String desc,
                                                                        StorableInfo<S> info)
                                                             throws IllegalArgumentException
Parses an index descriptor and returns an index object.

Parameters:
desc - name descriptor, as created by getNameDescriptor()
info - info on storable type
Returns:
index represented by descriptor
Throws:
IllegalArgumentException - if error in descriptor syntax or if it refers to unknown properties

getStorableType

public Class<S> getStorableType()
Returns the type of storable this index applies to.


getPropertyCount

public int getPropertyCount()
Returns the count of properties in this index.


getProperty

public StorableProperty<S> getProperty(int index)
Returns a specific property in this index.


getProperties

public StorableProperty<S>[] getProperties()
Returns a new array with all the properties in it.


getPropertyDirection

public Direction getPropertyDirection(int index)
Returns the requested direction of a specific property in this index.


getPropertyDirections

public Direction[] getPropertyDirections()
Returns a new array with all the property directions in it.


getOrderedProperty

public OrderedProperty<S> getOrderedProperty(int index)
Returns a specific property in this index, with the direction folded in.


getOrderedProperties

public OrderedProperty<S>[] getOrderedProperties()
Returns a new array with all the properties in it, with directions folded in.


isUnique

public boolean isUnique()

isClustered

public boolean isClustered()
Returns true if index is known to be clustered, which means it defines the physical ordering of storables.


unique

public StorableIndex<S> unique(boolean unique)
Returns a StorableIndex instance which is unique or not.


clustered

public StorableIndex<S> clustered(boolean clustered)
Returns a StorableIndex instance which is clustered or not.


reverse

public StorableIndex<S> reverse()
Returns a StorableIndex instance with all the properties reversed.


setDefaultDirection

public StorableIndex<S> setDefaultDirection(Direction direction)
Returns a StorableIndex instance with all unspecified directions set to the given direction. Returns this if all directions are already specified.

Parameters:
direction - direction to replace all unspecified directions

addProperty

public StorableIndex<S> addProperty(StorableProperty<S> property,
                                    Direction direction)
Returns a StorableIndex with the given property added. If this index already contained the given property (regardless of sort direction), this index is returned.

Parameters:
property - property to add unless already in this index
direction - direction to apply to property, if added
Returns:
new index with added property or this if index already contained property

uniquify

public StorableIndex<S> uniquify(StorableKey<S> key)
Returns a StorableIndex which is unique, possibly by appending properties from the given key. If index is already unique, it is returned as-is.


getNameDescriptor

public String getNameDescriptor()
Converts this index into a parseable name descriptor string, whose general format is:

<storable type>~<attr><+|-|~><property><+|-|~><property>...

Attr is "U" for a unique index, "N" for a non-unique index.

Example: my.pkg.UserInfo~N+lastName+firstName-birthDate

See Also:
parseNameDescriptor(String, StorableInfo)

getTypeDescriptor

public String getTypeDescriptor()
Converts this index into a parseable type descriptor string, which basically consists of Java type descriptors appended together. There is one slight difference. Types which may be null are prefixed with a 'N' character.


hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

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

toString

public String toString()
Overrides:
toString in class Object

appendTo

public void appendTo(Appendable app)
              throws IOException
Appends the same results as toString, but without the "StorableIndex" prefix.

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.