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  /*
23   * tuProlog - Copyright (C) 2001-2002  aliCE team at deis.unibo.it
24   *
25   * This library is free software; you can redistribute it and/or
26   * modify it under the terms of the GNU Lesser General Public
27   * License as published by the Free Software Foundation; either
28   * version 2.1 of the License, or (at your option) any later version.
29   *
30   * This library is distributed in the hope that it will be useful,
31   * but WITHOUT ANY WARRANTY; without even the implied warranty of
32   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
33   * Lesser General Public License for more details.
34   *
35   * You should have received a copy of the GNU Lesser General Public
36   * License along with this library; if not, write to the Free Software
37   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38   */
39  package jTrolog.terms;
40  
41  /**
42   * This class represents a prolog Flag
43   */
44  @SuppressWarnings("serial")
45  public class Flag implements java.io.Serializable {
46  
47  	private String name;
48  	private Struct valueList;
49  	private Term value;
50  	private boolean modifiable;
51  
52  	/**
53  	 * Builds a Prolog flag
54  	 * 
55  	 * @param name
56  	 *            is the name of the flag
57  	 * @param valueSet
58  	 *            is the Prolog list of the possible values
59  	 * @param defValue
60  	 *            is the default value
61  	 * @param modifiable
62  	 *            states if the flag is modifiable
63  	 */
64  	public Flag(String name, Struct valueSet, Term defValue, boolean modifiable) {
65  		this.name = name;
66  		this.valueList = valueSet;
67  		this.modifiable = modifiable;
68  		value = defValue;
69  	}
70  
71  	/**
72  	 * @return the name of the flag
73  	 */
74  	public String getName() {
75  		return name;
76  	}
77  
78  	/**
79  	 * @return a Prolog list of the flag's possible values
80  	 */
81  	public Struct getValueList() {
82  		return valueList;
83  	}
84  
85  	/**
86  	 * Sets the value of a flag
87  	 * 
88  	 * @param value
89  	 *            new value of the flag
90  	 */
91  	public void setValue(Term value) {
92  		if (modifiable)
93  			this.value = value;
94  	}
95  
96  	/**
97  	 * @return the current value of the flag
98  	 */
99  	public Term getValue() {
100 		return value;
101 	}
102 
103 	/**
104 	 * @return true if the value is modifiable
105 	 */
106 	public boolean isModifiable() {
107 		return modifiable;
108 	}
109 }