bdi4jade.belief

## Class AbstractBelief<K,V>

- java.lang.Object
- - bdi4jade.core.MetadataElementImpl
  - - bdi4jade.belief.AbstractBelief<K,V>

- Type Parameters:
    `K` - the type of the belief name or key.
    `V` - the type of the belief value.
  All Implemented Interfaces:
    Belief<K,V>, MetadataElement, jade.content.Concept, jade.content.ContentElement, jade.content.Term, java.io.Serializable, java.lang.Cloneable
  Direct Known Subclasses:
    AbstractBeliefSet, DerivedBelief, PersistentBelief, TransientBelief

      public abstract class AbstractBelief<K,V>
      extends MetadataElementImpl
      implements Belief<K,V>

  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
    Constructor and Description
    `AbstractBelief()` The default constructor.
    `AbstractBelief(K name)` Initializes a belief with its name.
    `AbstractBelief(K name, V value)` Initializes a belief with its name and an initial value.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addBeliefBase(BeliefBase beliefBase)` Adds a belief base that contains this belief.
    `java.lang.Object` | `clone()` Clones a 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.
    `K` | `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 beliefBase)` Removes a belief base that does not contain this belief anymore.
    `void` | `setName(K name)` Sets the name of this belief.
    `void` | `setValue(V 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(V 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

      `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

          public AbstractBelief()

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

    - #### AbstractBelief

          public AbstractBelief(K name)

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

    - #### AbstractBelief

          public AbstractBelief(K name,
                                V 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<K,V>`
      Parameters:
        `beliefBase` - the belief base to be added.
      See Also:
        `Belief.addBeliefBase(BeliefBase)`

    - #### clone

          public java.lang.Object clone()
                                 throws java.lang.CloneNotSupportedException

      Description copied from interface: `Belief`
      Clones a belief. This may be particularly useful to share this belief with other agents, copying the information of this belief without sharing other information, such as belief bases associated with a belief.
      Specified by:
        `clone` in interface `Belief<K,V>`
      Overrides:
        `clone` in class `java.lang.Object`
      Returns:
        the clone of this belief.
      Throws:
        `java.lang.CloneNotSupportedException` - if an implementation of a belief does not support clone.
      See Also:
        `Object.clone()`

    - #### 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<K,V>`
      Returns:
        the belief bases.
      See Also:
        `Belief.getBeliefBases()`

    - #### getName

          public final K getName()

      Description copied from interface: `Belief`
      Returns the name of this belief.
      Specified by:
        `getName` in interface `Belief<K,V>`
      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 beliefBase)

      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<K,V>`
      Parameters:
        `beliefBase` - the belief base to be removed.
      See Also:
        `Belief.removeBeliefBase(BeliefBase)`

    - #### setName

          public void setName(K 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(V value)

      Sets a new value to the belief and notifies belief bases of changes on this belief value.
      Specified by:
        `setValue` in interface `Belief<K,V>`
      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(V value)

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