Class Facts

  • All Implemented Interfaces:
    java.lang.Iterable<Fact<?>>

    public class Facts
    extends java.lang.Object
    implements java.lang.Iterable<Fact<?>>
    This class encapsulates a set of facts and represents a facts namespace. Facts have unique names within a Facts object.
    • Constructor Summary

      Constructors 
      Constructor Description
      Facts()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> void add​(Fact<T> fact)
      Add a fact, replacing any fact with the same name.
      java.util.Map<java.lang.String,​java.lang.Object> asMap()
      Return a copy of the facts as a map.
      void clear()
      Clear facts.
      <T> T get​(java.lang.String factName)
      Get the value of a fact by its name.
      Fact<?> getFact​(java.lang.String factName)
      Get a fact by name.
      java.util.Iterator<Fact<?>> iterator()
      Return an iterator on the set of facts.
      <T> void put​(java.lang.String name, T value)
      Add a fact, replacing any fact with the same name.
      void remove​(java.lang.String factName)
      Remove a fact by name.
      <T> void remove​(Fact<T> fact)
      Remove a fact.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • Facts

        public Facts()
    • Method Detail

      • 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
      • asMap

        public java.util.Map<java.lang.String,​java.lang.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
      • clear

        public void clear()
        Clear facts.
      • get

        public <T> T get​(java.lang.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​(java.lang.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
      • iterator

        public java.util.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 java.lang.Iterable<Fact<?>>
        Returns:
        an iterator on the set of facts
      • put

        public <T> void put​(java.lang.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
      • remove

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

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object