net.sf.groovydice
Class DiceRollingCommand

java.lang.Object
  extended by net.sf.groovydice.DiceRollingCommand
All Implemented Interfaces:
groovy.lang.GroovyObject, Comparable

public class DiceRollingCommand
extends Object
implements groovy.lang.GroovyObject, Comparable

This class provides the basic dice rolling functionality and methods to allow dice rolling commands to be compared and derived.

Since:
1.3
Version:
2
Author:
Daniel F. Martins

Constructor Summary
DiceRollingCommand()
           
 
Method Summary
 int compareTo(Object command)
          Compare the sum of this roll to the sum of the given roll.
 Object derive(Object allDice, Object sides)
          Create a new dice rolling command based on this one.
 boolean equals(Object command)
          Whether the sum of this roll is equals to the sum of the given roll.
 List getAllDice()
           
 GroovyDice getConfig()
           
 groovy.lang.MetaClass getMetaClass()
           
 Object getProperty(String name)
           
 Integer getSides()
           
 Object getView()
          Get a copy of dice results lists.
 int hashCode()
          Simple hashCode method.
 Object invokeMethod(String name, Object args)
           
 Object isCase(Object condition)
          Returns whether the given parameter is found in this dice roll.
 Object roll(int n)
          Roll the dice using the number generator specified at the configuration context.
 void setAllDice(List value)
           
 void setConfig(GroovyDice value)
           
 void setMetaClass(groovy.lang.MetaClass metaClass)
           
 void setProperty(String name, Object value)
           
 void setSides(Integer value)
           
 String toString()
          Default string representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DiceRollingCommand

public DiceRollingCommand()
Method Detail

getSides

public Integer getSides()

setSides

public void setSides(Integer value)

getAllDice

public List getAllDice()

setAllDice

public void setAllDice(List value)

getConfig

public GroovyDice getConfig()

setConfig

public void setConfig(GroovyDice value)

getView

public Object getView()
Get a copy of dice results lists.

Returns:
Array of Numbers that represents the rolled dice.
See Also:
allDice

roll

public Object roll(int n)
Roll the dice using the number generator specified at the configuration context.

Parameters:
n - Optional parameter that specify the number of dice to roll. Defaults to 1.
Returns:
this.

derive

public Object derive(Object allDice,
                     Object sides)
Create a new dice rolling command based on this one.

Parameters:
allDice - Specify the set of already rolled dice.
sides - Optional parameter to specify the number of sides.
Returns:
New dice rolling command.

equals

public boolean equals(Object command)
Whether the sum of this roll is equals to the sum of the given roll.

Overrides:
equals in class Object
Parameters:
command - Dice rolling command.
Returns:
Whether the sum of this roll is equals to the sum of the given roll.

compareTo

public int compareTo(Object command)
Compare the sum of this roll to the sum of the given roll.

Specified by:
compareTo in interface Comparable
Parameters:
command - Dice rolling command.
Returns:
< 0 if the sum of this roll is lesser than the sum of the given roll; = 0 if the sum of this roll is equals to the sum of the given roll; > 0 if the sum of this roll is greater than the sum of the given roll.
Throws:
ClassCastException - if the given object is not expected.

isCase

public Object isCase(Object condition)
Returns whether the given parameter is found in this dice roll.

Parameters:
condition - Can be any object accepted by grep() method,like a number, an array, a range, a closure etc. You can also pass a dice rolling command to use its dice as the condition.
Returns:
Whether the given parameter is found in the dice of this roll.

hashCode

public int hashCode()
Simple hashCode method.

Overrides:
hashCode in class Object
Returns:
Hashcode.

toString

public String toString()
Default string representation of this object.

Overrides:
toString in class Object
Returns:
Dice type, dice list and dice sum.

getMetaClass

public groovy.lang.MetaClass getMetaClass()
Specified by:
getMetaClass in interface groovy.lang.GroovyObject

setMetaClass

public void setMetaClass(groovy.lang.MetaClass metaClass)
Specified by:
setMetaClass in interface groovy.lang.GroovyObject

invokeMethod

public Object invokeMethod(String name,
                           Object args)
Specified by:
invokeMethod in interface groovy.lang.GroovyObject

getProperty

public Object getProperty(String name)
Specified by:
getProperty in interface groovy.lang.GroovyObject

setProperty

public void setProperty(String name,
                        Object value)
Specified by:
setProperty in interface groovy.lang.GroovyObject


Copyright © 2008-2010 Daniel F. Martins. All Rights Reserved.