org.deri.iris.optimisations.magicsets
Class AdornedProgram.AdornedRule

java.lang.Object
  extended by org.deri.iris.optimisations.magicsets.AdornedProgram.AdornedRule
Enclosing class:
AdornedProgram

public static class AdornedProgram.AdornedRule
extends Object

Simple representation of an adorned rule. The only difference to an ordinary rule is, that it has a sip attached, and that you can exchange literals.

ATTENTION: the replaceHeadLiteral and replaceBodyLiteral are slow, because they copy the head and body for each invocation.

Author:
Richard P??ttler (richard dot poettler at sti2 dot at)

Constructor Summary
AdornedProgram.AdornedRule(IRule rule, ISip sip)
          Constructs a new adorned rule.
 
Method Summary
 boolean equals(Object object)
           
 IRule getRule()
          Returns the plain rule object.
 ISip getSip()
          Returns the sip associated with this rule.
 int hashCode()
           
 AdornedProgram.AdornedRule replaceBodyLiteral(ILiteral literal, IPredicate predicate)
          Replaces the predicate of a given body literal with another one.
 AdornedProgram.AdornedRule replaceHeadLiteral(ILiteral literal, IPredicate predicate)
          Replaces the predicate of a given head literal with another one.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AdornedProgram.AdornedRule

public AdornedProgram.AdornedRule(IRule rule,
                                  ISip sip)
Constructs a new adorned rule.

Parameters:
rule - the rule
sip - the sip for this rule
Throws:
IllegalArgumentException - if the rule is null
IllegalArgumentException - if the sip is null
Method Detail

getSip

public ISip getSip()
Returns the sip associated with this rule.

Returns:
the rule

getRule

public IRule getRule()
Returns the plain rule object.

Returns:
the plain rule object

replaceHeadLiteral

public AdornedProgram.AdornedRule replaceHeadLiteral(ILiteral literal,
                                                     IPredicate predicate)
Replaces the predicate of a given head literal with another one. This method doesn't change the object itself, but creates another one, applies the changes and returns the modified rule object.

Parameters:
literal - the literal, for which to exchange the predicate
predicate - the new predicate which should be set
Returns:
a new rule with the applied changes, or the same rule again, if the literal couldn't be found
Throws:
IllegalArgumentException - if the literal is null
IllegalArgumentException - if the predicate is null
IllegalArgumentException - if the arity of the predicate of the literal and the new predicate doesn't match.

replaceBodyLiteral

public AdornedProgram.AdornedRule replaceBodyLiteral(ILiteral literal,
                                                     IPredicate predicate)
Replaces the predicate of a given body literal with another one. This method doesn't change the object itself, but creates another one, applies the changes and returns the modified rule object.

Parameters:
literal - the literal, for which to exchange the predicate
predicate - the new predicate which should be set
Returns:
a new rule with the applied changes, or the same rule again, if the literal couldn't be found
Throws:
IllegalArgumentException - if the literal is null
IllegalArgumentException - if the predicate is null
IllegalArgumentException - if the arity of the predicate of the literal and the new predicate doesn't match.

toString

public String toString()
Overrides:
toString in class Object

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object