codeblocks
Class BlockLinkChecker

java.lang.Object
  extended by codeblocks.BlockLinkChecker

public class BlockLinkChecker
extends java.lang.Object

BlockLinkChecker determines if two Block objects can connect. In particular, BlockLinkChecker will report which sockets of the two Block objects can connect. Interested Block objects may make a static call to canLink() to determine if it can link to another Block object. BlockLinkChecker uses a list of LinkRules to check the Connectors of each Block. Rules may be added, inserted, and removed from the checker. There is only one instance of the BlockLinkChecker.


Constructor Summary
BlockLinkChecker()
           
 
Method Summary
static void addRule(LinkRule rule)
          Adds a rule to the end of this checker's list of rules.
static BlockLink canLink(Block block1, Block block2, BlockConnector con1, BlockConnector con2)
          Returns a BlockLink instance if the two specified blocks can connect at the specified block connectors at each block; null if no link is possible.
static BlockLink getLink(RenderableBlock rblock1, java.lang.Iterable<RenderableBlock> otherBlocks)
          Checks to see if a RenderableBlocks can connect to other RenderableBlocks.
static BlockConnector getPlugEquivalent(Block b)
           
static java.lang.Iterable<BlockConnector> getSocketEquivalents(Block b)
           
static BlockLink getWeakLink(RenderableBlock rblock1, java.lang.Iterable<RenderableBlock> otherBlocks)
          NOTE: ALWAYS prefer BlockLinkChecker.getLink over this method.
static boolean hasPlugEquivalent(Block b)
           
static void insertRule(LinkRule rule, int index)
          Insert rule at the specified index in this checker's list of rules.
static void printRules()
          Prints to the console all the rules this LinkChecker currently supports.
static void removeRule(LinkRule rule)
          Removes the specified rule from the rule list
static void reset()
          Clears all the rules within this.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockLinkChecker

public BlockLinkChecker()
Method Detail

reset

public static void reset()
Clears all the rules within this.


addRule

public static void addRule(LinkRule rule)
Adds a rule to the end of this checker's list of rules. If the rule already exists in the rule list, the rule is removed in the original location and added to the end of the list.

Parameters:
rule - the desired LinkRule to be added

insertRule

public static void insertRule(LinkRule rule,
                              int index)
Insert rule at the specified index in this checker's list of rules. The original rule at the specified index and rules after it are shifted down the list. If the index is greater or equal to the length of the rule list, then the rule is added to the end of the list. If the rule already exists in the rule list, the rule is moved to the specified index.

Parameters:
rule - the desired rule to insert
index - the index to insert the rule in

removeRule

public static void removeRule(LinkRule rule)
Removes the specified rule from the rule list

Parameters:
rule - the desired LinkRule to remove

canLink

public static BlockLink canLink(Block block1,
                                Block block2,
                                BlockConnector con1,
                                BlockConnector con2)
Returns a BlockLink instance if the two specified blocks can connect at the specified block connectors at each block; null if no link is possible.

Parameters:
block1 - Block instance to compare
block2 - Block instance to compare
con1 - the BlockConnector at block1 to compare against con2
con2 - the BlockConnector at block2 to compare against con1

getLink

public static BlockLink getLink(RenderableBlock rblock1,
                                java.lang.Iterable<RenderableBlock> otherBlocks)
Checks to see if a RenderableBlocks can connect to other RenderableBlocks. This would mean that they have BlockConnectors that satisfy at least one of the LinkRules, and that these sockets are in close proximity.

Parameters:
rblock1 - one of the blocks to check
otherBlocks - the other blocks to check against
Returns:
a BlockLink object that gives the two closest matching BlockConnectors in these blocks, or null if no such matching exists.

getWeakLink

public static BlockLink getWeakLink(RenderableBlock rblock1,
                                    java.lang.Iterable<RenderableBlock> otherBlocks)
NOTE: ALWAYS prefer BlockLinkChecker.getLink over this method. Checks to see if a RenderableBlocks can connect to other RenderableBlocks, implying that rblock1 has at least one BlockConnectors that satisfies at least one of the LinkRules. Does not require close proximity.

Parameters:
rblock1 - one of the blocks to check
otherBlocks - the other blocks to check against
Returns:
a BlockLink object that gives the two closest matching BlockConnectors in these blocks, or null if no such matching exists.

hasPlugEquivalent

public static boolean hasPlugEquivalent(Block b)

getPlugEquivalent

public static BlockConnector getPlugEquivalent(Block b)

getSocketEquivalents

public static java.lang.Iterable<BlockConnector> getSocketEquivalents(Block b)

printRules

public static void printRules()
Prints to the console all the rules this LinkChecker currently supports.