View Javadoc

1   /*
2    * #%L
3    * prolobjectlink-jpi-jtrolog
4    * %%
5    * Copyright (C) 2012 - 2018 WorkLogic Project
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as
9    * published by the Free Software Foundation, either version 2.1 of the
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20   * #L%
21   */
22  package jTrolog.terms;
23  
24  import jTrolog.terms.Struct;
25  import jTrolog.terms.Term;
26  import jTrolog.terms.Wrapper;
27  import jTrolog.engine.BindingsTable;
28  
29  
30  /**
31   * @author ivar.orstavik@hist.no
32   */
33  @SuppressWarnings({ "serial" })
34  public class WrapStruct extends Struct implements Wrapper {
35  
36  	public final int context;
37  	private Struct basis;
38  
39  	public WrapStruct(Struct struct, int renameVarID) {
40  		super(struct.name, struct.arity, struct.predicateIndicator);
41  		basis = struct;
42  		context = renameVarID;
43  	}
44  
45  	public int getOperatorType() {
46  		return basis.getOperatorType();
47  	}
48  
49  	public Term getArg(int i) {
50  		return BindingsTable.wrapWithID(basis.getArg(i), context);
51  	}
52  
53  	public Var[] getVarList() {
54  		return basis.getVarList();
55  	}
56  
57  	public int getContext() {
58  		return context;
59  	}
60  
61  	public Term getBasis() {
62  		return basis;
63  	}
64  
65  	// public boolean equals(Object t) {
66  	// return (t instanceof WrapStruct && ((WrapStruct) t).getContext() ==
67  	// context && ((WrapStruct) t).getBasis().equals(basis));
68  	// }
69  
70  	public String toString() {
71  		return basis.toString();
72  	}
73  }