bdi4jade.plan

## Class AbstractPlan

- java.lang.Object
- - bdi4jade.core.MetadataElementImpl
  - - bdi4jade.plan.AbstractPlan

- All Implemented Interfaces:
    MetadataElement, Plan
  Direct Known Subclasses:
    DefaultPlan

      public abstract class AbstractPlan
      extends MetadataElementImpl
      implements Plan

  This class represents the plan abstraction, being an abstract implementation of the `Plan` interface.
  Author:
    Ingrid Nunes

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface bdi4jade.plan.Plan

      `Plan.EndState`

  - ### Field Summary

    - ### Fields inherited from class bdi4jade.core.MetadataElementImpl

      `metadata`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractPlan()` The default constructor.
    `` | `AbstractPlan(java.lang.String id)` Creates a new plan with an identifier.
    `` | `AbstractPlan(java.lang.String id, GoalTemplate goalTemplate)` Creates a new plan with an identifier and a template of goals it can achieve.
    `` | `AbstractPlan(java.lang.String id, GoalTemplate goalTemplate, jade.lang.acl.MessageTemplate messageTemplate)` Creates a new plan with an identifier, a template of goals it can achieve, and a template of messages it can process.
    `` | `AbstractPlan(java.lang.String id, jade.lang.acl.MessageTemplate messageTemplate)` Creates a new plan with an identifier and a template of messages it can process.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addGoalTemplate(GoalTemplate goalTemplate)` Adds template of goals that this plan can achieve.
    `void` | `addMessageTemplate(jade.lang.acl.MessageTemplate messageTemplate)` Adds a message template of messages that this plan can process.
    `boolean` | `canAchieve(Goal goal)` Verifies if a given goal can be achieved by this plan.
    `boolean` | `canProcess(jade.lang.acl.ACLMessage message)` Verifies if the message matches with any of the message templates of this plan.
    `boolean` | `equals(java.lang.Object obj)` Returns true if the object given as parameter is a plan and has the same id of this plan.
    `java.util.Set<GoalTemplate>` | `getGoalTemplates()` Returns the set of goal templates of the goals that can be achieved by this plan.
    `java.lang.String` | `getId()` Returns the identifier of this plan.
    `java.util.Set<jade.lang.acl.MessageTemplate>` | `getMessageTemplates()` Returns the set of message templates of the messages that can be processed by this plan.
    `PlanLibrary` | `getPlanLibrary()` Returns the plan library with which this plan is associated.
    `int` | `hashCode()`
    `protected void` | `initGoalTemplates()` This method is invoked in the Plan constructor.
    `protected void` | `initMessageTemplates()` This method is invoked in the Plan constructor.
    `boolean` | `isContextApplicable(Goal goal)` Verifies that this plan can be executed in the current context and a given goal.
    `void` | `setPlanLibrary(PlanLibrary planLibrary)` Sets the plan library with which this plan is associated.
    `java.lang.String` | `toString()` Returns the string representation of this plan, which is its id.

    - ### Methods inherited from class bdi4jade.core.MetadataElementImpl

      `getMetadata, getMetadata, hasMetadata, putMetadata, removeMetadata`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface bdi4jade.plan.Plan

      `createPlanBody`

    - ### Methods inherited from interface bdi4jade.core.MetadataElement

      `getMetadata, getMetadata, hasMetadata, putMetadata, removeMetadata`

- - ### Constructor Detail

    - #### AbstractPlan

          protected AbstractPlan()

      The default constructor. It should be only used if persistence frameworks are used.

    - #### AbstractPlan

          public AbstractPlan(java.lang.String id)

      Creates a new plan with an identifier.
      Parameters:
        `id` - the plan identifier.

    - #### AbstractPlan

          public AbstractPlan(java.lang.String id,
                              GoalTemplate goalTemplate)

      Creates a new plan with an identifier and a template of goals it can achieve.
      Parameters:
        `id` - the plan identifier.
        `goalTemplate` - the template of goals that this plan can achieve.

    - #### AbstractPlan

          public AbstractPlan(java.lang.String id,
                              GoalTemplate goalTemplate,
                              jade.lang.acl.MessageTemplate messageTemplate)

      Creates a new plan with an identifier, a template of goals it can achieve, and a template of messages it can process.
      Parameters:
        `id` - the plan identifier.
        `goalTemplate` - the template of goals that this plan can achieve.
        `messageTemplate` - the template of messages that this plan can process.

    - #### AbstractPlan

          public AbstractPlan(java.lang.String id,
                              jade.lang.acl.MessageTemplate messageTemplate)

      Creates a new plan with an identifier and a template of messages it can process.
      Parameters:
        `id` - the plan identifier.
        `messageTemplate` - the template of messages that this plan can process.

  - ### Method Detail

    - #### addGoalTemplate

          public void addGoalTemplate(GoalTemplate goalTemplate)

      Adds template of goals that this plan can achieve.
      Parameters:
        `goalTemplate` - the template of goals that this plan can achieve.

    - #### addMessageTemplate

          public void addMessageTemplate(jade.lang.acl.MessageTemplate messageTemplate)

      Adds a message template of messages that this plan can process.
      Parameters:
        `messageTemplate` - the message template of messages that can be processed.

    - #### canAchieve

          public boolean canAchieve(Goal goal)

      Verifies if a given goal can be achieved by this plan. It first checks if the current context is applicable by invoking the `isContextApplicable(Goal)` method. If so, when the goal is a `MessageGoal`, it invokes the method `canProcess(ACLMessage)`. Otherwise, it checks if the class of this goal is in the goal set of this plan.
      Specified by:
        `canAchieve` in interface `Plan`
      Parameters:
        `goal` - the goal to be verified.
      Returns:
        true if the given goal can be achieved by this plan, false otherwise.
      See Also:
        `Plan.canAchieve(Goal)`

    - #### canProcess

          public boolean canProcess(jade.lang.acl.ACLMessage message)

      Verifies if the message matches with any of the message templates of this plan.
      Specified by:
        `canProcess` in interface `Plan`
      Parameters:
        `message` - the message to be checked.
      Returns:
        true if this plan can process the message, false otherwise.
      See Also:
        `Plan.canProcess(ACLMessage)`

    - #### equals

          public boolean equals(java.lang.Object obj)

      Returns true if the object given as parameter is a plan and has the same id of this plan.
      Overrides:
        `equals` in class `java.lang.Object`
      Parameters:
        `obj` - the object to be tested as equals to this plan.
      See Also:
        `Object.equals(java.lang.Object)`

    - #### getGoalTemplates

          public java.util.Set<GoalTemplate> getGoalTemplates()

      Returns the set of goal templates of the goals that can be achieved by this plan.
      Returns:
        the goal templates

    - #### getId

          public java.lang.String getId()

      Returns the identifier of this plan.
      Specified by:
        `getId` in interface `Plan`
      Returns:
        the id.
      See Also:
        `Plan.getId()`

    - #### getMessageTemplates

          public java.util.Set<jade.lang.acl.MessageTemplate> getMessageTemplates()

      Returns the set of message templates of the messages that can be processed by this plan.
      Returns:
        the message templates

    - #### getPlanLibrary

          public PlanLibrary getPlanLibrary()

      Returns the plan library with which this plan is associated.
      Specified by:
        `getPlanLibrary` in interface `Plan`
      Returns:
        the planLibrary.
      See Also:
        `Plan.getPlanLibrary()`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`
      See Also:
        `Object.hashCode()`

    - #### initGoalTemplates

          protected void initGoalTemplates()

      This method is invoked in the Plan constructor. It is responsible for initializing the goal templates that this plan can achieve. The method should be overridden by subclasses.

    - #### initMessageTemplates

          protected void initMessageTemplates()

      This method is invoked in the Plan constructor. It is responsible for initializing the message templates that this plan can process. The method should be overridden by subclasses.

    - #### isContextApplicable

          public boolean isContextApplicable(Goal goal)

      Verifies that this plan can be executed in the current context and a given goal. The method should be overridden by subclasses, this implementation returns always true.
      Specified by:
        `isContextApplicable` in interface `Plan`
      Parameters:
        `goal` - the goal to be achieved whose conditions may be tested to verify the applicability of this plan.
      Returns:
        true.
      See Also:
        `Plan.isContextApplicable(Goal)`

    - #### setPlanLibrary

          public void setPlanLibrary(PlanLibrary planLibrary)

      Sets the plan library with which this plan is associated.
      Specified by:
        `setPlanLibrary` in interface `Plan`
      Parameters:
        `planLibrary` - the planLibrary to set

    - #### toString

          public java.lang.String toString()

      Returns the string representation of this plan, which is its id.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        the id of the plan.
      See Also:
        `Object.toString()`