Class DefaultInMemoryAtomSet

All Implemented Interfaces:
AtomSet, InMemoryAtomSet, CloseableIterable<Atom>, CloseableIterableWithoutException<Atom>, Iterable<Atom>

public class DefaultInMemoryAtomSet extends AbstractInMemoryAtomSet
The DefaultInMemoryAtomSet is a simple in memory atom set based on a java set. It is a wrapper for any Collection that implements the Set interface. Recommended sets : - By default, use a HashSet of Atom - If you want an ordered set, you can use a TreeSet of Atom - If you want to access elements in the order there are added into the set, use LinkedHashSet of Atom that combine a HashSet and a Linked List
Author:
Guillaume Pérution-Kihli
  • Constructor Details

    • DefaultInMemoryAtomSet

      public DefaultInMemoryAtomSet()
      Default constructor By default, we use a HashSet of Atom
    • DefaultInMemoryAtomSet

      public DefaultInMemoryAtomSet(Set<Atom> javaAtomSet)
      This constructor allows you to use any Collection that implements the Set of Atom interface
      Parameters:
      javaAtomSet - the Set that will contain all the atoms
    • DefaultInMemoryAtomSet

      public DefaultInMemoryAtomSet(Collection<Atom> collection)
      A copy constructor that can copy any Collection of Atom
      Parameters:
      collection - the atoms to copy into the set
    • DefaultInMemoryAtomSet

      public DefaultInMemoryAtomSet(Atom... atoms)
      Creates an atom set containing the provided atoms.
      Parameters:
      atoms - the atoms to add to the set
    • DefaultInMemoryAtomSet

      public DefaultInMemoryAtomSet(CloseableIterator<Atom> it) throws IteratorException
      Construct the atom set with the elements contained in the iterator in parameter
      Parameters:
      it - The elements to add
      Throws:
      IteratorException - if the iterator cannot be fully consumed
    • DefaultInMemoryAtomSet

      public DefaultInMemoryAtomSet(CloseableIteratorWithoutException<Atom> it)
      Construct the atom set with the elements contained in the iterator in parameter
      Parameters:
      it - The elements to add
    • DefaultInMemoryAtomSet

      public DefaultInMemoryAtomSet(AtomSet atomset) throws IteratorException
      Construct the atom set with the elements contained in the AtomSet in parameter
      Parameters:
      atomset - the elements to add
      Throws:
      IteratorException - if the atom set iterator cannot be fully consumed
    • DefaultInMemoryAtomSet

      public DefaultInMemoryAtomSet(InMemoryAtomSet atomset)
      Construct the atom set with the elements contained in the AtomSet in parameter
      Parameters:
      atomset - the elements to add
  • Method Details

    • match

      Description copied from interface: AtomSet
      Returns an iterator over atoms that match predicate and constants from the specified atom.
      Parameters:
      atom - the atom pattern to match
      s - a substitution of Variable from atom into Term from this atom set.
      Returns:
      an iterator over atoms.
    • atomsByPredicate

      public CloseableIteratorWithoutException<Atom> atomsByPredicate(Predicate p)
      Description copied from interface: AtomSet
      Returns an iterator over all atoms with the specified predicate.
      Parameters:
      p - the predicate to search for
      Returns:
      an iterator over all atoms with the specified predicate.
    • termsByPredicatePosition

      public CloseableIteratorWithoutException<Term> termsByPredicatePosition(Predicate p, int position)
      Description copied from interface: AtomSet
      Returns an iterator over terms which are in a specific position in at least one atom with the specified predicate.
      Parameters:
      p - the predicate to inspect
      position - the term position in atoms, positions starts from 0.
      Returns:
      an iterator over terms which appear in the specified position of the specified predicate.
    • predicatesIterator

      public CloseableIteratorWithoutException<Predicate> predicatesIterator()
      Description copied from interface: AtomSet
      Returns an iterator over all predicates in this atom set. Each predicate is iterated only once time.
      Returns:
      an iterator over all predicates.
    • termsIterator

      public CloseableIteratorWithoutException<Term> termsIterator()
      Description copied from interface: AtomSet
      Returns an iterator over all terms in this atom set. Each term is iterated only once time.
      Returns:
      an iterator over all terms.
    • termsIterator

      Deprecated.
      Description copied from interface: AtomSet
      This method is deprecated since 1.3, use AtomSet.variablesIterator(), AtomSet.constantsIterator() or AtomSet.literalsIterator() instead.

      Returns an iterator of all terms of the specified type in this atom set. Each term is iterated only once time.
      Parameters:
      type - the term type to filter on
      Returns:
      an iterator of all terms.
    • iterator

      Description copied from interface: AtomSet
      Returns an iterator over the atoms in this atom set.
      Returns:
      an iterator over the atoms in this atom set.
    • add

      public boolean add(Atom atom)
      Description copied from interface: AtomSet
      Add the specified atom to this atom set if is not already present.
      Parameters:
      atom - the atom to be added to this atom set
      Returns:
      true if this atom set did not already contain the specified atom
    • removeWithoutCheck

      public void removeWithoutCheck(Atom atom)
      Description copied from interface: AtomSet
      Remove the specified atom from this this atom set.
      Parameters:
      atom - the atom to be removed
    • remove

      public boolean remove(Atom atom)
      Description copied from interface: AtomSet
      Remove the specified atom from this this atom set.
      Specified by:
      remove in interface AtomSet
      Specified by:
      remove in interface InMemoryAtomSet
      Overrides:
      remove in class AbstractInMemoryAtomSet
      Parameters:
      atom - the atom to be removed
      Returns:
      true if this atom set contained the specified atom.
    • clear

      public void clear()
      Description copied from interface: AtomSet
      Removes all atoms from this atom set.
    • getFreshSymbolGenerator

      public TermGenerator getFreshSymbolGenerator()
      Description copied from interface: AtomSet
      Returns the fresh symbol generator associated with this atom set.
      Returns:
      the symbol generator used by this atom set
    • size

      public int size()
      Description copied from class: AbstractAtomSet
      This default implementation should be overriden, it is convenient for in memory set, but will be inefficient in some case.
      Specified by:
      size in interface AtomSet
      Specified by:
      size in interface InMemoryAtomSet
      Overrides:
      size in class AbstractInMemoryAtomSet
      Returns:
      the number of atoms in the set
      See Also:
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: AtomSet
      Returns whether this atom set contains no atom.
      Specified by:
      isEmpty in interface AtomSet
      Specified by:
      isEmpty in interface InMemoryAtomSet
      Overrides:
      isEmpty in class AbstractInMemoryAtomSet
      Returns:
      true if this atom set is empty, false otherwise.
    • getTerms

      public Set<Term> getTerms()
      Description copied from interface: AtomSet
      Returns a Set of all terms in this atom set.
      Specified by:
      getTerms in interface AtomSet
      Specified by:
      getTerms in interface InMemoryAtomSet
      Overrides:
      getTerms in class AbstractInMemoryAtomSet
      Returns:
      a Set of all terms.
    • getPredicates

      public Set<Predicate> getPredicates()
      Description copied from interface: AtomSet
      Returns a Set of all predicates in this atom set.
      Specified by:
      getPredicates in interface AtomSet
      Specified by:
      getPredicates in interface InMemoryAtomSet
      Overrides:
      getPredicates in class AbstractInMemoryAtomSet
      Returns:
      a Set of all predicates.
    • spliterator

      public Spliterator<Atom> spliterator()
      Description copied from interface: InMemoryAtomSet
      Creates a Spliterator over the elements in this InMemoryAtomSet.

      The Spliterator reports Spliterator.DISTINCT. Implementations should document the reporting of additional characteristic values. The default implementation creates a late-binding spliterator from the InMemoryAtomSet's Iterator. The spliterator inherits the fail-fast properties of the InMemoryAtomSet's iterator.

      The created Spliterator additionally reports Spliterator.SIZED. The created Spliterator additionally reports Spliterator.SUBSIZED.

      Returns:
      a Spliterator over the elements in this InMemoryAtomSet
    • stream

      public Stream<Atom> stream()
      Description copied from interface: InMemoryAtomSet
      Returns a sequential Stream with this InMemoryAtomSet as its source.

      This method should be overridden when the InMemoryAtomSet.spliterator() method cannot return a spliterator that is IMMUTABLE, CONCURRENT, or late-binding. (See InMemoryAtomSet.spliterator() for details.) The default implementation creates a sequential Stream from the InMemoryAtomSet Spliterator.

      Returns:
      a sequential Stream over the elements in this InMemoryAtomSet
    • parallelStream

      public Stream<Atom> parallelStream()
      Description copied from interface: InMemoryAtomSet
      Returns a possibly parallel Stream with this InMemoryAtomSet as its source. It is allowable for this method to return a sequential stream.

      This method should be overridden when the InMemoryAtomSet.spliterator() method cannot return a spliterator that is IMMUTABLE, CONCURRENT, or late-binding. (See InMemoryAtomSet.spliterator() for details.) The default implementation creates a parallel Stream from the InMemoryAtomSet Spliterator.

      Returns:
      a possibly parallel Stream over the elements in this InMemoryAtomSet