org.eigenbase.relopt
Class RelTraitSet

java.lang.Object
  extended by org.eigenbase.relopt.RelTraitSet

public class RelTraitSet
extends Object

RelTraitSet represents an ordered set of RelTraits.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/relopt/RelTraitSet.java#12 $
Author:
Stephan Zuercher

Field Summary
private  RelTrait[] traits
           
 
Constructor Summary
RelTraitSet(RelTrait... traits)
          Constructs a RelTraitSet with the given set of RelTraits.
 
Method Summary
 void addTrait(RelTrait trait)
          Adds a new RelTrait to the set.
private  RelTrait canonize(RelTrait trait)
          Converts a trait to canonical form.
 RelTraitSet clone()
           
 boolean contains(RelTrait trait)
          Returns whether this trait set contains a given trait.
 boolean equals(Object obj)
          Compares two RelTraitSet objects for equality.
private  int findIndex(RelTraitDef traitDef)
          Finds the index of a trait of a given type in this set.
 RelTrait getTrait(int index)
          Retrieves a RelTrait from the set.
 RelTrait getTrait(RelTraitDef traitDef)
          Retrieves a RelTrait of the given type from the set.
 boolean matches(RelTraitSet that)
          Compares two RelTraitSet objects to see if they match for the purposes of firing a rule.
 RelTrait setTrait(int index, RelTrait trait)
          Replaces an existing RelTrait in the set.
 RelTrait setTrait(RelTraitDef traitDef, RelTrait trait)
          Replaces an existing RelTrait in the set.
 int size()
          Returns the size of the RelTraitSet.
 String toString()
          Outputs the traits of this set as a String.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

traits

private RelTrait[] traits
Constructor Detail

RelTraitSet

public RelTraitSet(RelTrait... traits)
Constructs a RelTraitSet with the given set of RelTraits.

Parameters:
traits - Traits
Method Detail

getTrait

public RelTrait getTrait(int index)
Retrieves a RelTrait from the set.

Parameters:
index - 0-based index into ordered RelTraitSet
Returns:
the RelTrait
Throws:
ArrayIndexOutOfBoundsException - if index greater than or equal to size() or less than 0.

getTrait

public RelTrait getTrait(RelTraitDef traitDef)
Retrieves a RelTrait of the given type from the set.

Parameters:
traitDef - the type of RelTrit to retrieve
Returns:
the RelTrait, or null if not found

setTrait

public RelTrait setTrait(int index,
                         RelTrait trait)
Replaces an existing RelTrait in the set. This method must not be used to modify the traits of a RelNode that has already been registered with a RelOptPlanner.

Parameters:
index - 0-based index into ordered RelTraitSet
trait - the new RelTrait
Returns:
the old RelTrait at the index

setTrait

public RelTrait setTrait(RelTraitDef traitDef,
                         RelTrait trait)
Replaces an existing RelTrait in the set. This method must not be used to modify the traits of a RelNode that has already been registered with a RelOptPlanner.

Parameters:
traitDef - the type of RelTrait to replace
Returns:
the RelTrait at the index

addTrait

public void addTrait(RelTrait trait)
Adds a new RelTrait to the set. This method must not be used to modify the traits of a RelNode that has already been registered with a RelOptPlanner.

Parameters:
trait - the new RelTrait

size

public int size()
Returns the size of the RelTraitSet.

Returns:
the size of the RelTraitSet.

canonize

private RelTrait canonize(RelTrait trait)
Converts a trait to canonical form.

After canonization, t1.equals(t2) if and only if t1 == t2.

Parameters:
trait - Trait
Returns:
Trait in canonical form

equals

public boolean equals(Object obj)
Compares two RelTraitSet objects for equality.

Overrides:
equals in class Object
Parameters:
obj - another RelTraitSet
Returns:
true if traits are equal and in the same order, false otherwise

matches

public boolean matches(RelTraitSet that)
Compares two RelTraitSet objects to see if they match for the purposes of firing a rule. A null RelTrait within a RelTraitSet indicates a wildcard: any RelTrait in the other RelTraitSet will match. If one RelTraitSet is smaller than the other, comparison stops when the last RelTrait from the smaller set has been examined and the remaining RelTraits in the larger set are assumed to match.

Parameters:
that - another RelTraitSet
Returns:
true if the RelTraitSets match, false otherwise

contains

public boolean contains(RelTrait trait)
Returns whether this trait set contains a given trait.

Parameters:
trait - Sought trait
Returns:
Whether set contains given trait

toString

public String toString()
Outputs the traits of this set as a String. Traits are output in the String in order, separated by periods.

Overrides:
toString in class Object

clone

public RelTraitSet clone()
Overrides:
clone in class Object

findIndex

private int findIndex(RelTraitDef traitDef)
Finds the index of a trait of a given type in this set.

Parameters:
traitDef - Sought trait definition
Returns:
index of trait, or -1 if not found