Class ListUtils

java.lang.Object
org.projog.core.term.ListUtils

public final class ListUtils extends Object
Helper methods for performing common tasks with Prolog list data structures.
See Also:
  • Method Details

    • toJavaUtilList

      public static 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

      public static 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:
    • 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