package org.matheclipse.core.convert;

import org.matheclipse.core.expression.F;
import org.matheclipse.core.interfaces.IAST;

public class Lists {
	/**
	 * Returns the size of a array, returning zero if the array is
	 * null.
	 * 
	 * @param p_array
	 *          the array for which to return the size.
	 * @return the size of the array, or 0 if the array is
	 *         null.
	 */
	public static  int sizeOf(T... p_array) {
		if (p_array == null) {
			return 0;
		}
		return p_array.length;
	}

	/**
	 * Returns a {@link org.matheclipse.core.interfaces.IAST} of boolean
	 * {@link org.matheclipse.core.interfaces.ISymbol}s from an array of
	 * booleans.
	 * 
	 * @param p_booleans
	 *          the array of boolean values to be converted to a
	 *          {@link org.matheclipse.core.interfaces.IAST}.
	 * 
	 * @return a {@link org.matheclipse.core.interfaces.IAST} of
	 *                 {@org.matheclipse.core.interfaces.ISymbol
	 * 
	 * } objects.
	 */
	public static IAST asAST(boolean... p_booleans) {
		IAST ast = F.ast(F.List);
		if (p_booleans != null) {
			for (int i = 0, t = p_booleans.length; i < t; i++) {
				if (p_booleans[i]) {
					ast.add(F.True);
				} else {
					ast.add(F.False);
				}
			}
		}
		return ast;
	}

	/**
	 * Returns a {@link org.matheclipse.core.interfaces.IAST} of
	 * {@link org.matheclipse.core.interfaces.INum}s from an array of
	 * doubles.
	 * 
	 * @param p_doubles
	 *          the array of double values to be converted to a
	 *          {@link org.matheclipse.core.interfaces.IAST}.
	 * 
	 * @return a {@link org.matheclipse.core.interfaces.IAST} of
	 *         {@link org.matheclipse.core.interfaces.INum} objects.
	 */
	public static IAST asList(double... p_doubles) {
		IAST ast = F.ast(F.List);
		if (p_doubles != null) {
			for (int i = 0, t = p_doubles.length; i < t; i++) {
				ast.add(F.num(p_doubles[i]));
			}
		}
		return ast;
	}

	/**
	 * Returns a {@link org.matheclipse.core.interfaces.IAST} of
	 * {@link org.matheclipse.core.interfaces.INum}s from an array of
	 * floats.
	 * 
	 * @param p_doubles
	 *          the array of float values to be converted to a
	 *          {@link org.matheclipse.core.interfaces.IAST}.
	 * 
	 * @return a {@link org.matheclipse.core.interfaces.IAST} of
	 *         {@link org.matheclipse.core.interfaces.INum} objects.
	 */
	public static IAST asList(float... p_doubles) {
		IAST ast = F.ast(F.List);
		if (p_doubles != null) {
			for (int i = 0, t = p_doubles.length; i < t; i++) {
				ast.add(F.num(p_doubles[i]));
			}
		}
		return ast;
	}

	/**
	 * Returns a {@link org.matheclipse.core.interfaces.IAST} of
	 * {@link org.matheclipse.core.interfaces.IStringX}s from an array of
	 * Strings.
	 * 
	 * @param p_strings
	 *          the array of String values to be converted to a
	 *          {@link org.matheclipse.core.interfaces.IAST}.
	 * 
	 * @return a {@link org.matheclipse.core.interfaces.IAST} of
	 *         {@link org.matheclipse.core.interfaces.IStringX} objects.
	 */
	public static IAST asList(String... p_strings) {
		IAST ast = F.ast(F.List);
		if (p_strings != null) {
			for (int i = 0, t = p_strings.length; i < t; i++) {
				ast.add(F.stringx(p_strings[i]));
			}
		}
		return ast;
	}

	/**
	 * Returns a {@link org.matheclipse.core.interfaces.IAST} of
	 * {@link org.matheclipse.core.interfaces.ISymbol}s from an array of
	 * Strings.
	 * 
	 * @param p_symbols
	 *          the array of String values to be converted to a
	 *          {@link org.matheclipse.core.interfaces.IAST}.
	 * 
	 * @return a {@link org.matheclipse.core.interfaces.IAST} of
	 *         {@link org.matheclipse.core.interfaces.ISymbol} objects.
	 */
	public static IAST asListSymbols(String... p_symbols) {
		IAST ast = F.ast(F.List);
		if (p_symbols != null) {
			for (int i = 0, t = p_symbols.length; i < t; i++) {

				ast.add(F.$s(p_symbols[i]));
			}
		}
		return ast;
	}

	/**
	 * Returns a {@link org.matheclipse.core.interfaces.IAST} of
	 * {@link org.matheclipse.core.interfaces.IInteger}s from an array of
	 * shorts.
	 * 
	 * @param p_shorts
	 *          the array of short values to be converted to a
	 *          {@link org.matheclipse.core.interfaces.IAST}.
	 * 
	 * @return a {@link org.matheclipse.core.interfaces.IAST} of
	 *         {@link org.matheclipse.core.interfaces.IInteger} objects.
	 */
	public static IAST asList(short... p_shorts) {
		IAST ast = F.ast(F.List);
		if (p_shorts != null) {
			for (int i = 0, t = p_shorts.length; i < t; i++) {
				ast.add(F.integer(p_shorts[i]));
			}
		}
		return ast;
	}

	/**
	 * Returns a {@link org.matheclipse.core.interfaces.IAST} of
	 * {@link org.matheclipse.core.interfaces.IInteger}s from an array of
	 * ints.
	 * 
	 * @param p_ints
	 *          the array of int values to be converted to a
	 *          {@link org.matheclipse.core.interfaces.IAST}.
	 * 
	 * @return a {@link org.matheclipse.core.interfaces.IAST} of
	 *         {@link org.matheclipse.core.interfaces.IInteger} objects.
	 */
	public static IAST asList(int... p_ints) {
		IAST ast = F.ast(F.List);
		if (p_ints != null) {
			for (int i = 0, t = p_ints.length; i < t; i++) {
				ast.add(F.integer(p_ints[i]));
			}
		}
		return ast;
	}

	/**
	 * Returns a {@link org.matheclipse.core.interfaces.IAST} of
	 * {@link org.matheclipse.core.interfaces.IInteger}s from an array of
	 * longs.
	 * 
	 * @param p_longs
	 *          the array of long values to be converted to a
	 *          {@link org.matheclipse.core.interfaces.IAST}.
	 * 
	 * @return a {@link org.matheclipse.core.interfaces.IAST} of
	 *         {@link org.matheclipse.core.interfaces.IInteger} objects.
	 */
	public static IAST asList(long... p_longs) {
		IAST ast = F.ast(F.List);
		if (p_longs != null) {
			for (int i = 0, t = p_longs.length; i < t; i++) {
				ast.add(F.integer(p_longs[i]));
			}
		}
		return ast;
	}

	/**
	 * Returns a {@link org.matheclipse.core.interfaces.IAST} of
	 * {@link org.matheclipse.core.interfaces.IExpr}s from an array of
	 * Objects.
	 * 
	 * @param p_objects
	 *          the array of Object values to be converted to a
	 *          {@link org.matheclipse.core.interfaces.IAST}.
	 * 
	 * @return a {@link org.matheclipse.core.interfaces.IAST} of
	 *         {@link org.matheclipse.core.interfaces.IExpr} objects.
	 */
	public static IAST asList(Object... p_objects) {
		IAST ast = F.ast(F.List);
		if (p_objects != null) {
			for (int i = 0, t = p_objects.length; i < t; i++) {
				ast.add(Object2Expr.CONST.convert(p_objects[i]));
			}
		}
		return ast;
	}
}

 

Ads help maintain this website.