Class Facts

java.lang.Object
org.jeasy.rules.api.Facts
All Implemented Interfaces:
Iterable<Fact<?>>

public class Facts extends Object implements Iterable<Fact<?>>
This class encapsulates a set of facts and represents a facts namespace. Facts have unique names within a Facts object.
Author:
Mahmoud Ben Hassine ([email protected])
  • Constructor Details

    • Facts

      public Facts()
  • Method Details

    • put

      public <T> void put(String name, T value)
      Add a fact, replacing any fact with the same name.
      Parameters:
      name - of the fact to add, must not be null
      value - of the fact to add, must not be null
    • add

      public <T> void add(Fact<T> fact)
      Add a fact, replacing any fact with the same name.
      Parameters:
      fact - to add, must not be null
    • remove

      public void remove(String factName)
      Remove a fact by name.
      Parameters:
      factName - name of the fact to remove, must not be null
    • remove

      public <T> void remove(Fact<T> fact)
      Remove a fact.
      Parameters:
      fact - to remove, must not be null
    • get

      public <T> T get(String factName)
      Get the value of a fact by its name. This is a convenience method provided as a short version of getFact(factName).getValue().
      Type Parameters:
      T - type of the fact's value
      Parameters:
      factName - name of the fact, must not be null
      Returns:
      the value of the fact having the given name, or null if there is no fact with the given name
    • getFact

      public Fact<?> getFact(String factName)
      Get a fact by name.
      Parameters:
      factName - name of the fact, must not be null
      Returns:
      the fact having the given name, or null if there is no fact with the given name
    • asMap

      public Map<String,Object> asMap()
      Return a copy of the facts as a map. It is not intended to manipulate facts outside of the rules engine (aka other than manipulating them through rules).
      Returns:
      a copy of the current facts as a HashMap
    • iterator

      public Iterator<Fact<?>> iterator()
      Return an iterator on the set of facts. It is not intended to remove facts using this iterator outside of the rules engine (aka other than doing it through rules)
      Specified by:
      iterator in interface Iterable<Fact<?>>
      Returns:
      an iterator on the set of facts
    • clear

      public void clear()
      Clear facts.
    • toString

      public String toString()
      Overrides:
      toString in class Object