Class ListUtils


  • public final class ListUtils
    extends java.lang.Object
    Helper methods for performing common tasks with Prolog list data structures.
    See Also:
    List, ListFactory, TermUtils
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ListUtils()
      Private constructor as all methods are static.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isMember​(Term element, Term list)
      Checks is a term can be unified with at least one element of a list.
      static java.util.List<Term> toJavaUtilList​(Term list)
      Returns a new java.util.List containing the contents of the specified org.projog.core.term.List.
      static java.util.List<Term> toSortedJavaUtilList​(Term unsorted)
      Returns a new java.util.List containing the sorted contents of the specified org.projog.core.term.List.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ListUtils

        private ListUtils()
        Private constructor as all methods are static.
    • Method Detail

      • toJavaUtilList

        public static java.util.List<Term> toJavaUtilList​(Term list)
        Returns a new java.util.List containing the contents of the specified org.projog.core.term.List.

        Will return null if list is neither of type TermType.LIST or TermType.EMPTY_LIST, or if list represents a partial list (i.e. a list that does not have an empty list as its tail).

        See Also:
        toSortedJavaUtilList(Term)
      • toSortedJavaUtilList

        public static java.util.List<Term> toSortedJavaUtilList​(Term unsorted)
        Returns a new java.util.List containing the sorted contents of the specified org.projog.core.term.List.

        The elements in the returned list will be ordered using the standard ordering of terms, as implemented by TermComparator.

        Will return null if list is neither of type TermType.LIST or TermType.EMPTY_LIST, or if list represents a partial list (i.e. a list that does not have an empty list as its tail).

        See Also:
        toJavaUtilList(Term)
      • isMember

        public static boolean isMember​(Term element,
                                       Term list)
        Checks is a term can be unified with at least one element of a list.

        Iterates through each element of list attempting to unify with element. Returns true immediately after the first unifiable element is found. If list contains no elements that can be unified with element then false is returned.

        Throws:
        ProjogException - if list is not of type TermType#LIST or TermType#EMPTY_LIST