org.moyoman.debug
Class Aggregate

java.lang.Object
  |
  +--org.moyoman.debug.Debug
        |
        +--org.moyoman.debug.Aggregate

public class Aggregate
extends Debug

This class represents groups of stones and their relations. A stone is assigned to a group, but there are a number of options beyond that. Stones within a group can also be assigned to a subgroup, so if groups of one module are grouped together into a single group in a succeeding module, both the group and subgroup can be indicated. An example is that each subgroup would be stones that are captures as a unit, while the group are an aggregate of units that act as a group. For example, a three space extension from a two stone wall would have three stones in the same group, but two subgroups.

Pairs of groups can be related by either empty points, stones not in either group, or without any other points or stones. It is an error to try to relate the same two groups in more than one way. If this needs to be done, then there should be a separate Aggregate object for each relation.
As an example of a relation by points, if black and white each want to extend from a shimari to the same points, then those points would relate the group of the black and white shimaris.
As an example of a relation by stones, if certain moves would cause two groups of the same color to become one group, then those stones would relate the two groups.
As an example of a relation without points or stones, groups which are spatially adjacent would be related this way.

Subsets of a group can be selected as special, for example the cutting stones in a group of stones.


Field Summary
private  ArrayList groups
          Each element is an ArrayList containing Stone objects.
private static short NONE
          Value returned by getRelationType if the two groups are not related.
private static short POINTS
          Value returned by getRelationType if the two groups are related by points.
private  ArrayList relateGroups
          Each element is an IntPair object.
private  HashMap relateGroupsByPoints
          The keys are IntPair objects, and the values are an array of Point objects.
private  HashMap relateGroupsByStones
          The keys are IntPair objects, and the values are an array of Stone objects.
private  ArrayList special
          Each element is a Stone object.
private static short STONES
          Value returned by getRelationType if the two groups are related by stones.
private  int[] subgroupCount
          The index is the group number, the value is the number of subgroups.
private  HashMap subgroups
          Element key is a Stone object, each value is a String object.
private static short WITHOUT_POINTS_OR_STONES
          Value returned by getRelationType if the two groups are related without points or stones.
 
Fields inherited from class org.moyoman.debug.Debug
 
Constructor Summary
Aggregate(String h)
          Create a new Aggregate object.
 
Method Summary
 int addGroup(Stone[] stones)
          Add a group of stones.
 Stone[] getGroupStones(int group)
          Return the stones in a particular group.
 Point[] getRelatingPoints(IntPair ip)
          Get the points which relate the two groups.
 Stone[] getRelatingStone(IntPair ip)
          Get the stones which relate the two groups.
 IntPair[] getRelations()
          Get all of the relations without points or stones.
 IntPair[] getRelationsByPoints()
          Get all of the relations through points.
 IntPair[] getRelationsByStones()
          Get all of the relations through stones.
 short getRelationType(IntPair ip)
          Returns information on how the groups are related.
 int getSubgroup(Stone st)
          Return the subgroup for the stone.
 int getTotalGroups()
          Return the total number of groups.
 int getTotalSubgroups(int group)
          Get the total number of subgroups for the given group.
 DebugType getType()
          Get the type of this debug object.
 boolean hasSubgroup(Stone st)
          Determine if the stone is in a subgroup.
 boolean isSpecial(Stone st)
          Determine if the stone is marked as special.
static void main(String[] args)
          This method is used for unit testing.
 void relateGroups(int group1, int group2)
          Relate two groups without any points or stones.
 void relateGroups(int group1, int group2, Point[] points)
          Relate two groups through a set of points.
 void relateGroups(int group1, int group2, Stone[] stones)
          Relate two groups through a set of stones.
 void setSpecial(Stone st)
          Set the special status of the stone.
 int setSubgroup(int group, Stone[] stones)
          Set the subgroup for a set of stones.
 String toString()
          Return a String representation of the object.
private  void validateIntPairUnrelated(IntPair ip)
          Verify that the two groups are not already related.
private  boolean validateStoneGroup(int group, Stone st)
          Determine if the stone is in the specified group.
 
Methods inherited from class org.moyoman.debug.Debug
getHeaderType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NONE

private static final short NONE
Value returned by getRelationType if the two groups are not related.

See Also:
Constant Field Values

WITHOUT_POINTS_OR_STONES

private static final short WITHOUT_POINTS_OR_STONES
Value returned by getRelationType if the two groups are related without points or stones.

See Also:
Constant Field Values

POINTS

private static final short POINTS
Value returned by getRelationType if the two groups are related by points.

See Also:
Constant Field Values

STONES

private static final short STONES
Value returned by getRelationType if the two groups are related by stones.

See Also:
Constant Field Values

groups

private ArrayList groups
Each element is an ArrayList containing Stone objects.


subgroups

private HashMap subgroups
Element key is a Stone object, each value is a String object.


subgroupCount

private int[] subgroupCount
The index is the group number, the value is the number of subgroups.


relateGroups

private ArrayList relateGroups
Each element is an IntPair object.


relateGroupsByPoints

private HashMap relateGroupsByPoints
The keys are IntPair objects, and the values are an array of Point objects.


relateGroupsByStones

private HashMap relateGroupsByStones
The keys are IntPair objects, and the values are an array of Stone objects.


special

private ArrayList special
Each element is a Stone object.

Constructor Detail

Aggregate

public Aggregate(String h)
Create a new Aggregate object.

Parameters:
h - The header.
Method Detail

main

public static void main(String[] args)
This method is used for unit testing.


addGroup

public int addGroup(Stone[] stones)
Add a group of stones.

Parameters:
stones - An array of stones that are one group.
Returns:
The number representing that group.

setSubgroup

public int setSubgroup(int group,
                       Stone[] stones)
                throws IndexOutOfBoundsException,
                       InconsistentStateException
Set the subgroup for a set of stones. Each of the stones must be in the correct group, or an exception is thrown.

Parameters:
group - - The group number.
stones - - The stones that are part of the subgroup.
Returns:
An int which is the number of the subgroup.
Throws:
IndexOutOfBoundsException - Thrown if the group number is invalid.
InconsistentStateException - Thrown if any of the stones are not in the specified group.

validateStoneGroup

private boolean validateStoneGroup(int group,
                                   Stone st)
                            throws IndexOutOfBoundsException
Determine if the stone is in the specified group.

Parameters:
group - - The group to which the stone should belong.
st - - The stone being checked.
Returns:
boolean true if the stone is in the group, or false.
Throws:
IndexOutOfBoundsException - Thrown if the group number is invalid.

getGroupStones

public Stone[] getGroupStones(int group)
                       throws IndexOutOfBoundsException
Return the stones in a particular group.

Parameters:
group - The group number.
Returns:
The array of stones that form that group.
Throws:
IndexOutOfBoundsException - Thrown if the group number is invalid.

hasSubgroup

public boolean hasSubgroup(Stone st)
Determine if the stone is in a subgroup.

Parameters:
st - - The stone being checked.
Returns:
true if the stone is in a subgroup, or false.

getSubgroup

public int getSubgroup(Stone st)
                throws NoSuchDataException
Return the subgroup for the stone.

Parameters:
st - - The stone in question.
Returns:
An int which is the subgroup number.
Throws:
NoSuchDataException - Thrown if the hasSubgroup returns false.

getTotalGroups

public int getTotalGroups()
Return the total number of groups.

Returns:
the total number of groups.

getTotalSubgroups

public int getTotalSubgroups(int group)
                      throws IndexOutOfBoundsException
Get the total number of subgroups for the given group.

Parameters:
group - - The group being checked.
Returns:
An int that is the number of subgroups.
Throws:
IndexOutOfBoundsException - Thrown if the group number is invalid.

validateIntPairUnrelated

private void validateIntPairUnrelated(IntPair ip)
                               throws InconsistentStateException
Verify that the two groups are not already related.

Parameters:
ip - - The IntPair object representing the two groups.
Throws:
InconsistentStateException - Thrown if the two groups are already related.

relateGroups

public void relateGroups(int group1,
                         int group2)
                  throws IndexOutOfBoundsException,
                         InconsistentStateException
Relate two groups without any points or stones.

Parameters:
group1 - - The number of the first group.
group2 - - The number of the second group.
Throws:
IndexOutOfBoundsException - - Thrown if either of the two group numbers are invalid.
InconsistentStateException - Thrown if the groups are already related.

relateGroups

public void relateGroups(int group1,
                         int group2,
                         Stone[] stones)
                  throws IndexOutOfBoundsException,
                         InconsistentStateException
Relate two groups through a set of stones.

Parameters:
group1 - - The number of the first group.
group2 - - The number of the second group.
stones - - The stones relating the two groups.
Throws:
IndexOutOfBoundsException - - Thrown if either of the two group numbers are invalid.
InconsistentStateException - Thrown if the groups are already related.

relateGroups

public void relateGroups(int group1,
                         int group2,
                         Point[] points)
                  throws IndexOutOfBoundsException,
                         InconsistentStateException
Relate two groups through a set of points.

Parameters:
group1 - - The number of the first group.
group2 - - The number of the second group.
points - - The points relating the two groups.
Throws:
IndexOutOfBoundsException - - Thrown if either of the two group numbers are invalid.
InconsistentStateException - Thrown if the groups are already related.

getRelations

public IntPair[] getRelations()
Get all of the relations without points or stones.

Returns:
An array of IntPair objects.

getRelationsByPoints

public IntPair[] getRelationsByPoints()
Get all of the relations through points.

Returns:
An array of IntPair objects.

getRelationsByStones

public IntPair[] getRelationsByStones()
Get all of the relations through stones.

Returns:
An array of IntPair objects.

getRelationType

public short getRelationType(IntPair ip)
Returns information on how the groups are related.

Parameters:
ip - The IntPair object which specifies the two groups.
Returns:
One of: NONE, WITHOUT_POINTS_OR_STONES, POINTS, or STONES.

getRelatingPoints

public Point[] getRelatingPoints(IntPair ip)
                          throws NoSuchDataException
Get the points which relate the two groups.

Parameters:
ip - - The two groups which are related.
Returns:
An array of Point objects.
Throws:
NoSuchDataException - - Thrown if the two groups are not related by points.

getRelatingStone

public Stone[] getRelatingStone(IntPair ip)
                         throws NoSuchDataException
Get the stones which relate the two groups.

Parameters:
ip - - The two groups which are related.
Returns:
An array of Stone objects.
Throws:
NoSuchDataException - - Thrown if the two groups are not related by stones.

setSpecial

public void setSpecial(Stone st)
Set the special status of the stone.

Parameters:
st - The stone to be marked as special.

isSpecial

public boolean isSpecial(Stone st)
Determine if the stone is marked as special.

Parameters:
st - - The stone in question.
Returns:
true if the stone is special, or false.

toString

public String toString()
Return a String representation of the object.

Overrides:
toString in class Object
Returns:
A String object representing the state of this object.

getType

public DebugType getType()
Get the type of this debug object.

Specified by:
getType in class Debug
Returns:
DebugType.AGGREGATE;