Class Util
- java.lang.Object
-
- org.jpl7.Util
-
public final class Util extends java.lang.Object
This class provides a bunch of static utility methods to support JPL's Java API.
Copyright (C) 2004 Paul SingletonCopyright (C) 1998 Fred Dushin
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String[]
atomListToStringArray(Term t)
static Term
intArrayArrayToList(int[][] a)
Converts an array of arrays of int to a corresponding JPL list of listsstatic Term
intArrayToList(int[] a)
Converts an array of int to a corresponding JPL liststatic boolean
isList(Term term)
whether the Term represents a proper liststatic int
listToLength(Term term)
static Term[]
listToTermArray(Term t)
converts a proper list to an array of terms, else throws an exceptionstatic java.util.Map<term_t,Variable>
namevarsToMap(Term nvs)
Converts a (JPL) list of Name=Var pairs (as yielded by atom_to_term/3) to a Map from Prolog variables (necessarily in term_t holders) to named JPL Variablesstatic Term
stringArrayToList(java.lang.String[] a)
Converts an array of String to a corresponding JPL liststatic Term
termArrayToList(Term[] terms)
Converts an array of Terms to a JPL representation of a Prolog list of terms whose members correspond to the respective array elements.static Term
textParamsToTerm(java.lang.String text, Term[] params)
Converts a Prolog source text to a corresponding JPL Term (in which each Variable has the appropriate name from the source text), replacing successive occurrences of ? in the text by the corresponding element of Term[] params.static Term
textToTerm(java.lang.String text)
Converts a Prolog source text to a corresponding JPL Term (in which each Variable has the appropriate name from the source text).static java.lang.String
toString(java.util.Map<java.lang.String,Term> varnames_to_Terms)
Converts a substitution, in the form of a Map from variable names to Terms, to a String.
-
-
-
Method Detail
-
termArrayToList
public static Term termArrayToList(Term[] terms)
Converts an array of Terms to a JPL representation of a Prolog list of terms whose members correspond to the respective array elements.- Parameters:
terms
- An array of Term- Returns:
- Term a list of the array elements
-
toString
public static java.lang.String toString(java.util.Map<java.lang.String,Term> varnames_to_Terms)
Converts a substitution, in the form of a Map from variable names to Terms, to a String.- Parameters:
varnames_to_Terms
- A Map from variable names to Terms.- Returns:
- String A String representation of the variable bindings
-
namevarsToMap
public static java.util.Map<term_t,Variable> namevarsToMap(Term nvs)
Converts a (JPL) list of Name=Var pairs (as yielded by atom_to_term/3) to a Map from Prolog variables (necessarily in term_t holders) to named JPL Variables- Parameters:
nvs
- A JPL list of Name=Var pairs (as yielded by atom_to_term/3)- Returns:
- Map A Map from Prolog variables (necessarily in term_t holders) to named JPL Variables
-
textToTerm
public static Term textToTerm(java.lang.String text)
Converts a Prolog source text to a corresponding JPL Term (in which each Variable has the appropriate name from the source text). Throws PrologException containing error(syntax_error(_),_) if text is invalid.- Parameters:
text
- A Prolog source text denoting a term- Returns:
- Term a JPL Term equivalent to the given source text
-
textParamsToTerm
public static Term textParamsToTerm(java.lang.String text, Term[] params)
Converts a Prolog source text to a corresponding JPL Term (in which each Variable has the appropriate name from the source text), replacing successive occurrences of ? in the text by the corresponding element of Term[] params. (New in JPL 3.0.4) Throws PrologException containing error(syntax_error(_),_) if text is invalid.- Parameters:
text
- A Prolog source text denoting a term- Returns:
- Term a JPL Term equivalent to the given source text
-
stringArrayToList
public static Term stringArrayToList(java.lang.String[] a)
Converts an array of String to a corresponding JPL list- Parameters:
a
- An array of String objects- Returns:
- Term a JPL list corresponding to the given String array
-
intArrayToList
public static Term intArrayToList(int[] a)
Converts an array of int to a corresponding JPL list- Parameters:
a
- An array of int values- Returns:
- Term a JPL list corresponding to the given int array
-
intArrayArrayToList
public static Term intArrayArrayToList(int[][] a)
Converts an array of arrays of int to a corresponding JPL list of lists- Parameters:
a
- An array of arrays of int values- Returns:
- Term a JPL list of lists corresponding to the given int array of arrays
-
isList
public static final boolean isList(Term term)
whether the Term represents a proper list- Parameters:
term
-- Returns:
- whether the Term represents a proper list
-
listToLength
public static int listToLength(Term term)
- Parameters:
term
- any Term- Returns:
- the length of the proper list which the Term represents, else -1
-
listToTermArray
public static Term[] listToTermArray(Term t)
converts a proper list to an array of terms, else throws an exception- Returns:
- an array of terms whose successive elements are the corresponding members of the list (if it is a list)
- Throws:
JPLException
-
atomListToStringArray
public static java.lang.String[] atomListToStringArray(Term t)
-
-