helix.graph.model.impl
Class RColorSet

java.lang.Object
  extended by helix.graph.model.impl.AbstractRegistryValue
      extended by helix.graph.model.impl.RColorSet
All Implemented Interfaces:
RegistryValue, Iterable<Integer>

public class RColorSet
extends AbstractRegistryValue
implements Iterable<Integer>

Implements set of colors to store into Registry


Constructor Summary
RColorSet()
          constructor : make an empty RColorSet
RColorSet(Iterable<Integer> colors)
          constructor : make a RColorSet by using a specified set of integers
RColorSet(RColorSet cset)
          constructor : make a RColorSet by copying another RColorSet
RColorSet(String s)
          constructor : make a RColorSet by parsing the binary string argument (e.g.
 
Method Summary
 void andColors(RColorSet cset)
          compute the intersection ('and') between this ColorSet and the ColorSet argument.
 void clearColor(int color)
          unset color in this ColorSet same as : setColor(i, false)
 void clearColors()
          clear all colors in this ColorSet
 int countColors()
          count the number of colors in this ColorSet
 boolean equals(Object o)
           
static RColorSet getColors(Registry r)
          same as getColors(r, Registry.Colors)
static RColorSet getColors(Registry r, String key)
          Lookup the RColorSet associated to key in registry and create an empty RColorSet if it does not exist.
 boolean hasColor(int color)
          test if this ColorSet has the specified color
static boolean hasColor(Registry r, int i)
          same as hasColor(r, Registry.Colors)
static boolean hasColor(Registry r, String key, int i)
          tells if registry r has a RcolorSet on key and if this RColorSet has color i
static boolean hasColors(Registry r)
          same as hasColors(r, Registry.Colors)
static boolean hasColors(Registry r, String key)
          tells if registry r has a RcolorSet on key and if this RcolorSet is not empty
 int hashCode()
           
 boolean includeColors(RColorSet cset)
          tell if this ColorSet includes all colors in the ColorSet argument.
 boolean intersectColor(RColorSet cset)
          tell if this ColorSet intersects the ColorSet argument i.e.
 boolean isEmpty()
          tell if this ColorSet is empty same as (cset.countColors == 0)
 Iterator<Integer> iterator()
          return an iterable over colors
 RegistryValue klone()
          Potentially clone this instance.
 int length()
          get the "logical size" of this ColorSet : the highest color of the set plus one.
 int maxColor()
          return highest color in this colorSet (or -1 if colorSet is empty)
 int minColor()
          return lowest color in this colorSet (or -1 if colorSet is empty)
static int nbColors(Registry r)
          same as nbColors(r, Registry.Colors)
static int nbColors(Registry r, String key)
          get the number of colors in RColorSet associated o key in registry r.
 void orColors(RColorSet cset)
          compute the union ('or') between this ColorSet and the ColorSet argument.
 void setColor(int color)
          set color in this ColorSet same as : setColor(i, true)
 void setColor(int color, boolean b)
          set/unset color in this ColorSet
 void setColors(RColorSet cset)
          set all colors in this ColorSet at same values as in argument same as this.clearColors(); this.orColors(cset);
 void shift(int shift)
          shift bits to left or right in this ColorSet by specified amount.
 int singleColor()
          if this ColorSet has a single color return this color else throws an IllegalValueException
 String toString()
          Get a String representation of this instance value note: this representation may not be suitable as the constructor argument, use serialize() instead.
 void xorColors(RColorSet cset)
          compute the 'xor' between this ColorSet and the ColorSet argument.
 
Methods inherited from class helix.graph.model.impl.AbstractRegistryValue
serialize, toBoolean, toFloat, toInt
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RColorSet

public RColorSet()
constructor : make an empty RColorSet


RColorSet

public RColorSet(String s)
          throws IllegalValueException
constructor : make a RColorSet by parsing the binary string argument (e.g. "10001") note: the first (lowest) color is on the right

Throws:
IllegalValueException

RColorSet

public RColorSet(RColorSet cset)
constructor : make a RColorSet by copying another RColorSet


RColorSet

public RColorSet(Iterable<Integer> colors)
constructor : make a RColorSet by using a specified set of integers

Method Detail

klone

public RegistryValue klone()
Description copied from interface: RegistryValue
Potentially clone this instance.

Specified by:
klone in interface RegistryValue
Returns:
a clone (deep copy) of this instance. Note that it may be the instance itself (for immutable objects).

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Description copied from interface: RegistryValue
Get a String representation of this instance value note: this representation may not be suitable as the constructor argument, use serialize() instead.

Specified by:
toString in interface RegistryValue
Overrides:
toString in class Object
Returns:
String representation of this instance value

iterator

public Iterator<Integer> iterator()
return an iterable over colors

Specified by:
iterator in interface Iterable<Integer>

hasColor

public boolean hasColor(int color)
test if this ColorSet has the specified color


setColor

public void setColor(int color,
                     boolean b)
set/unset color in this ColorSet


setColor

public void setColor(int color)
set color in this ColorSet same as : setColor(i, true)


clearColor

public void clearColor(int color)
unset color in this ColorSet same as : setColor(i, false)


clearColors

public void clearColors()
clear all colors in this ColorSet


setColors

public void setColors(RColorSet cset)
set all colors in this ColorSet at same values as in argument same as this.clearColors(); this.orColors(cset);


andColors

public void andColors(RColorSet cset)
compute the intersection ('and') between this ColorSet and the ColorSet argument. i.e. keep only colors that present in both ColorSets.


orColors

public void orColors(RColorSet cset)
compute the union ('or') between this ColorSet and the ColorSet argument. i.e. keep colors that present in either or both ColorSets.


xorColors

public void xorColors(RColorSet cset)
compute the 'xor' between this ColorSet and the ColorSet argument. i.e. keep colors that present in either (but not both) ColorSets.


shift

public void shift(int shift)
shift bits to left or right in this ColorSet by specified amount. shift > 0 : shift bits to left shift < 0 : shift bits to right


countColors

public int countColors()
count the number of colors in this ColorSet


minColor

public int minColor()
return lowest color in this colorSet (or -1 if colorSet is empty)


maxColor

public int maxColor()
return highest color in this colorSet (or -1 if colorSet is empty)


length

public int length()
get the "logical size" of this ColorSet : the highest color of the set plus one. Returns zero if the BitSet contains no set bits


isEmpty

public boolean isEmpty()
tell if this ColorSet is empty same as (cset.countColors == 0)


includeColors

public boolean includeColors(RColorSet cset)
tell if this ColorSet includes all colors in the ColorSet argument.


intersectColor

public boolean intersectColor(RColorSet cset)
tell if this ColorSet intersects the ColorSet argument i.e. if they have at least one color in common


singleColor

public int singleColor()
                throws IllegalValueException
if this ColorSet has a single color return this color else throws an IllegalValueException

Throws:
IllegalValueException

getColors

public static final RColorSet getColors(Registry r,
                                        String key)
Lookup the RColorSet associated to key in registry and create an empty RColorSet if it does not exist. This helper function is equivalent to :

 if (r.has(key))
    return (RColorSet) r.get(key);
 else
    return (RColorSet) r.set(key, new RColorSet());
 


getColors

public static final RColorSet getColors(Registry r)
same as getColors(r, Registry.Colors)


hasColors

public static final boolean hasColors(Registry r,
                                      String key)
tells if registry r has a RcolorSet on key and if this RcolorSet is not empty


hasColors

public static final boolean hasColors(Registry r)
same as hasColors(r, Registry.Colors)


hasColor

public static final boolean hasColor(Registry r,
                                     String key,
                                     int i)
tells if registry r has a RcolorSet on key and if this RColorSet has color i


hasColor

public static final boolean hasColor(Registry r,
                                     int i)
same as hasColor(r, Registry.Colors)


nbColors

public static final int nbColors(Registry r,
                                 String key)
get the number of colors in RColorSet associated o key in registry r. this number is 0 if there is no RColorSet or if the RColorSet is empty


nbColors

public static final int nbColors(Registry r)
same as nbColors(r, Registry.Colors)