Term.java

/*
 * #%L
 * prolobjectlink-jpi-jtrolog
 * %%
 * Copyright (C) 2012 - 2018 WorkLogic Project
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 2.1 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
 * #L%
 */
package jTrolog.terms;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * Term class - root prolog data type
 * 
 * @see jTrolog.terms.Struct
 * @see Var
 * @see jTrolog.terms.Number
 * @author ivar.orstavik@hist.no
 */
@SuppressWarnings({ "rawtypes", "serial" })
public abstract class Term implements java.io.Serializable {

	public int type;

	public final static int VAR = 1;
	public final static int NUMBER = 2;
	public final static int STRUCT = 3;
	public final static int ATOM = 4;

	// important atoms to be used only once
	public static final Term TRUE = new StructAtom("true".intern());
	public static final Term FALSE = new StructAtom("false".intern());
	public static final StructAtom emptyList = new StructAtom("[]");
	public static final Iterator iterator = new LinkedList().iterator();

	// Tree data Jens Teubner prepost style:
	// http://www-db.in.tum.de/~grust/teaching/ws0506/XML-DB/db-supp-xml-pdf
	// page 17
	public int pos = 0;

	public Term[] tree;
	public int[] prePost;

	protected Term() {
		tree = new Term[] { this };
		prePost = new int[] { 0 };
	}

	public abstract String toStringSmall();
}