com.seventytwomiles.architecturerules.domain
Class Rule

java.lang.Object
  extended by com.seventytwomiles.architecturerules.domain.Rule

public class Rule
extends Object

Represents a Rule that may not be violoated.

Author:
mikenereson

Constructor Summary
Rule()
          Constructs a new Rule.
Rule(String id)
          Instantiates a new Rule with the given id.
Rule(String id, String packageName)
          Instantiates a new Rule with the given id.
 
Method Summary
 boolean addPackage(String packageName)
          Adds a package to the Packages collection.
 Rule addViolation(JPackage violation)
          Add a new violation to this Rule.
 Rule addViolation(String violation)
          Add a new violation to this Rule.
 String describe()
          Describes the properties of this rule in an xml-like format.
 String describePackages()
          Creates a String representation of this packages.
 boolean equals(Object object)
           
 String getComment()
          Getter for property comment.
 String getDescriptionOfRule()
          Creates a String representation of this Rule.
 String getId()
          Getter for property id.
 Collection<JPackage> getPackages()
          Getter for property packages
 Collection<JPackage> getViolations()
          Get all of the violations.
 int hashCode()
           
 Rule removePackage(String packageName)
          Remove a package from this Rule.
 Rule removeViolation(JPackage violation)
           
 Rule removeViolation(String violation)
          Remove a violation from this Rule.
 Rule setComment(String comment)
          Setter for property comment.
 Rule setId(String id)
          Setter for property id.
 void setIdString(String id)
          Same as setId(String).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rule

public Rule()

Constructs a new Rule.


Rule

public Rule(String id)

Instantiates a new Rule with the given id.

Parameters:
id - sets the id

Rule

public Rule(String id,
            String packageName)

Instantiates a new Rule with the given id.

This constructor is to provide some sense of backwards compatibility with the releases in series 1 (1.0 and 1.1)

Parameters:
id - sets the id
packageName - a @packages to assert on.
Method Detail

setId

public Rule setId(String id)

Setter for property id.

Parameters:
id - Value to set for property id.
Returns:
Rule this Rule to allow for method chaining.

addPackage

public boolean addPackage(String packageName)

Adds a package to the Packages collection.

Parameters:
packageName - String
Returns:
boolean true when the package is actually added to the Collection. false would be returned if the package was already in the Collection of packages.

getComment

public String getComment()

Getter for property comment.

Returns:
Value for property comment.

getId

public String getId()

Getter for property id.

Returns:
Value for property id.

getPackages

public Collection<JPackage> getPackages()

Getter for property packages

Returns:
Value for property packages.

equals

public boolean equals(Object object)
Overrides:
equals in class Object
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

addViolation

public Rule addViolation(JPackage violation)

Add a new violation to this Rule.

Parameters:
violation - String a package this this Rule's package may NOT depend upon
Returns:
Rule this Rule to allow for method chaining.
Throws:
IllegalArchitectureRuleException - a RuntimeException when the violation could not be added because the violation is one of the packages being checked.

addViolation

public Rule addViolation(String violation)

Add a new violation to this Rule.

Parameters:
violation - String a package this this Rule's package may NOT depend upon
Returns:
Rule this Rule to allow for method chaining.
Throws:
IllegalArchitectureRuleException - a RuntimeException when the violation could not be added because the violation is one of the packages being checked.

describe

public String describe()

Describes the properties of this rule in an xml-like format.

Returns:
String of xml that describes this Rule.

getDescriptionOfRule

public String getDescriptionOfRule()

Creates a String representation of this Rule. Useful for debugging and logging.

Returns:
String describes this rule at its current state. Such as ['dao' for 'com.company.dao, com.company.dao.hibernate']

describePackages

public String describePackages()

Creates a String representation of this packages. Useful for debugging and logging.

Returns:
String describes this Rule's packages. Such as com.company.dao, com.company.dao.hibernate

getViolations

public Collection<JPackage> getViolations()

Get all of the violations.

Note: this Collection is unmodifiable, use addViolation(com.seventytwomiles.architecturerules.domain.JPackage) and removeViolation(java.lang.String)

Returns:
Collection unmodifiable
Throws:
UnsupportedOperationException - when getViolations.add(Object) or getViolations.remove(Object) is called. Use addViolation(com.seventytwomiles.architecturerules.domain.JPackage) and removeViolation(java.lang.String).

removePackage

public Rule removePackage(String packageName)

Remove a package from this Rule.

Parameters:
packageName - String a package this this Rule's package should not test on
Returns:
Rule this Rule to allow for method chaining.

removeViolation

public Rule removeViolation(String violation)

Remove a violation from this Rule.

Parameters:
violation - String a package this this Rule's package should not test on
Returns:
Rule this Rule to allow for method chaining.

removeViolation

public Rule removeViolation(JPackage violation)

setComment

public Rule setComment(String comment)

Setter for property comment.

Parameters:
comment - Value to set for property comment.
Returns:
Rule this Rule to allow for method chaining.

setIdString

public void setIdString(String id)

Same as setId(String). The DigesterConfiguraitonFactory that builds the Configuration class can invoke void setter. When we added method chaining at version 2.1.0, we made setId return Rule, and the configuration factory broke. So this method was created to allow for the ConfigurationFactory to work, and for method chaining to be supported.

Parameters:
id - Value to set for property id.


Copyright © 2007-2008. All Rights Reserved.