bdi4jade.belief

## Class AbstractBelief<T>

- java.lang.Object
- - bdi4jade.core.MetadataElementImpl
  - - bdi4jade.belief.AbstractBelief<T>

- Type Parameters:
    `T` - the type of the belief value.
  All Implemented Interfaces:
    Belief<T>, MetadataElement, jade.content.Concept, jade.content.Term, java.io.Serializable
  Direct Known Subclasses:
    AbstractBeliefSet, PersistentBelief, TransientBelief

      public abstract class AbstractBelief<T>
      extends MetadataElementImpl
      implements Belief<T>

  This is an abstract class that implements the `Belief` interface. It implements some of the interface methods, leaving some implementations to the subclasses, mainly the choice of how the belief value is stored. It is class observable by belief bases (`BeliefBase`), allowing the observation on changes in the value of this belief.
  Author:
    Ingrid Nunes
  See Also:
    Serialized Form

- - ### Field Summary

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

      `metadata`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractBelief()` The default constructor.
    `` | `AbstractBelief(java.lang.String name)` Initializes a belief with its name.
    `` | `AbstractBelief(java.lang.String name, T value)` Initializes a belief with its name and an initial value.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addBeliefBase(BeliefBase beliefBase)` Adds a belief base that contains this belief.
    `boolean` | `equals(java.lang.Object obj)` Returns true of the object is a belief and has the same name of this belief.
    `java.util.Set<BeliefBase>` | `getBeliefBases()` Returns the belief bases with which this belief is associated.
    `java.lang.String` | `getName()` Returns the name of this belief.
    `int` | `hashCode()` Returns the hash code of this belief name.
    `protected void` | `notifyBeliefBases(BeliefEvent beliefEvent)` Notifies the belief bases with which this belief is associated that the value of this belief has changed.
    `void` | `removeBeliefBase(BeliefBase beliefBases)` Removes a belief base that does not contain this belief anymore.
    `protected void` | `setName(java.lang.String name)` Sets the name of this belief.
    `void` | `setValue(T value)` Sets a new value to the belief and notifies belief bases of changes on this belief value.
    `java.lang.String` | `toString()` Returns this belief as a string in the form: "belief name = belief value".
    `protected abstract void` | `updateValue(T value)` Sets the value of this belief.

    - ### 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.belief.Belief

      `getValue`

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

      `getMetadata, getMetadata, hasMetadata, putMetadata, removeMetadata`

- - ### Constructor Detail

    - #### AbstractBelief

          protected AbstractBelief()

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

    - #### AbstractBelief

          public AbstractBelief(java.lang.String name)

      Initializes a belief with its name.
      Parameters:
        `name` - the belief name.

    - #### AbstractBelief

          public AbstractBelief(java.lang.String name,
                        T value)

      Initializes a belief with its name and an initial value.
      Parameters:
        `name` - the belief name.
        `value` - the belief initial value.

  - ### Method Detail

    - #### addBeliefBase

          public void addBeliefBase(BeliefBase beliefBase)

      Description copied from interface: `Belief`
      Adds a belief base that contains this belief. The agent whose capability contains this belief in the belief base believes in this belief.
      Specified by:
        `addBeliefBase` in interface `Belief<T>`
      Parameters:
        `beliefBase` - the belief base to be added.
      See Also:
        `Belief.addBeliefBase(BeliefBase)`

    - #### equals

          public final boolean equals(java.lang.Object obj)

      Returns true of the object is a belief and has the same name of this belief.
      Overrides:
        `equals` in class `java.lang.Object`
      Parameters:
        `obj` - to object to be tested if it is equal to this belief.
      See Also:
        `Object.equals(Object)`

    - #### getBeliefBases

          public java.util.Set<BeliefBase> getBeliefBases()

      Description copied from interface: `Belief`
      Returns the belief bases with which this belief is associated.
      Specified by:
        `getBeliefBases` in interface `Belief<T>`
      Returns:
        the belief bases.
      See Also:
        `Belief.getBeliefBases()`

    - #### getName

          public final java.lang.String getName()

      Description copied from interface: `Belief`
      Returns the name of this belief.
      Specified by:
        `getName` in interface `Belief<T>`
      Returns:
        the string that is the belief name.
      See Also:
        `Belief.getName()`

    - #### hashCode

          public final int hashCode()

      Returns the hash code of this belief name.
      Overrides:
        `hashCode` in class `java.lang.Object`
      Returns:
        the hash code of this belief.
      See Also:
        `Object.hashCode()`

    - #### notifyBeliefBases

          protected void notifyBeliefBases(BeliefEvent beliefEvent)

      Notifies the belief bases with which this belief is associated that the value of this belief has changed.
      Parameters:
        `beliefEvent` - the `BeliefEvent` describing the change on this belief value

    - #### removeBeliefBase

          public void removeBeliefBase(BeliefBase beliefBases)

      Description copied from interface: `Belief`
      Removes a belief base that does not contain this belief anymore. The agent whose capability does not contain this belief in the belief base does not believe in this belief anymore.
      Specified by:
        `removeBeliefBase` in interface `Belief<T>`
      Parameters:
        `beliefBases` - the belief base to be removed.
      See Also:
        `Belief.removeBeliefBase(BeliefBase)`

    - #### setName

          protected void setName(java.lang.String name)

      Sets the name of this belief. Ideally, a belief name should be final and initialized in the constructor. This method should be only used if persistence frameworks are used.
      Parameters:
        `name` - the name to set.

    - #### setValue

          public final void setValue(T value)

      Sets a new value to the belief and notifies belief bases of changes on this belief value.
      Specified by:
        `setValue` in interface `Belief<T>`
      Parameters:
        `value` - the new value.
      See Also:
        `Belief.setValue(Object)`

    - #### toString

          public java.lang.String toString()

      Returns this belief as a string in the form: "belief name = belief value".
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        the string representation of this belief.
      See Also:
        `Object.toString()`

    - #### updateValue

          protected abstract void updateValue(T value)

      Sets the value of this belief. It is invoked by the `setValue(Object)` method.
      Parameters:
        `value` - the value to set.