00001 //tabstop=4 00002 //*****************************************************************************/ 00003 // Project: jpl 00004 // 00005 // File: $Id$ 00006 // Date: $Date$ 00007 // Author: Fred Dushin <fadushin@syr.edu> 00008 // 00009 // 00010 // Description: 00011 // 00012 // 00013 // ------------------------------------------------------------------------- 00014 // Copyright (c) 2004 Paul Singleton 00015 // Copyright (c) 1998 Fred Dushin 00016 // All rights reserved. 00017 // 00018 // This library is free software; you can redistribute it and/or 00019 // modify it under the terms of the GNU Library Public License 00020 // as published by the Free Software Foundation; either version 2 00021 // of the License, or (at your option) any later version. 00022 // 00023 // This library is distributed in the hope that it will be useful, 00024 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00026 // GNU Library Public License for more details. 00027 //*****************************************************************************/ 00028 package jpl; 00029 00030 import java.util.Map; 00031 import jpl.fli.Prolog; 00032 import jpl.fli.term_t; 00033 00034 //----------------------------------------------------------------------/ 00035 // JRef 00064 public class JRef extends Term { 00065 00066 //==================================================================/ 00067 // Attributes 00068 //==================================================================/ 00069 00073 protected final Object ref; 00074 00075 //==================================================================/ 00076 // Constructors 00077 //==================================================================/ 00078 00085 public JRef(Object ref) { 00086 if (ref instanceof String) { 00087 throw new JPLException("a JRef cannot have a String value (String maps to atom)"); 00088 } else { 00089 this.ref = ref; 00090 } 00091 } 00092 00093 //==================================================================/ 00094 // Methods (common) 00095 //==================================================================/ 00096 00097 public Term arg(int ano) { 00098 return (ano == 1 ? new Atom(jpl.fli.Prolog.object_to_tag(ref)) : null); 00099 } 00100 00106 public String toString() { 00107 return "" + ref + ""; // WRONG 00108 } 00109 00116 public final boolean equals(Object obj) { 00117 return this == obj || (obj instanceof JRef && ref == ((JRef) obj).ref); 00118 } 00119 00120 public final int type() { 00121 return Prolog.JREF; 00122 } 00123 00124 public String typeName(){ 00125 return "JRef"; 00126 } 00127 00128 //==================================================================/ 00129 // Methods (peculiar) 00130 //==================================================================/ 00131 00137 public Object ref() { 00138 return ref; 00139 } 00140 00141 //==================================================================/ 00142 // Methods (deprecated) 00143 //==================================================================/ 00144 00151 public Term[] args() { 00152 return new Term[] { 00153 }; 00154 } 00155 00162 public String debugString() { 00163 return "(JRef " + toString() + ")"; 00164 } 00165 00166 //==================================================================/ 00167 // Converting JPL Terms to Prolog terms 00168 //==================================================================/ 00169 00179 protected final void put(Map varnames_to_vars, term_t term) { 00180 00181 Prolog.put_jref(term, ref); 00182 } 00183 00184 //==================================================================/ 00185 // Computing Substitutions 00186 //==================================================================/ 00187 00194 protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) { 00195 } 00196 00197 public boolean hasFunctor(String name, int arity) { 00198 return name != null && name.equals("@") && arity == 1; 00199 } 00200 00201 public boolean hasFunctor(int value, int arity) { 00202 return false; 00203 } 00204 00205 public boolean hasFunctor(double value, int arity) { 00206 return false; 00207 } 00208 00209 public Object jrefToObject() { 00210 return ref; 00211 } 00212 00213 } 00214 00215 //345678901234567890123456789012346578901234567890123456789012345678901234567890