View Javadoc

1   /*
2    * #%L
3    * prolobjectlink-jpi-jtrolog
4    * %%
5    * Copyright (C) 2019 Prolobjectlink 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 io.github.prolobjectlink.prolog.jtrolog;
23  
24  import java.util.AbstractSet;
25  import java.util.Iterator;
26  import java.util.Set;
27  
28  import io.github.prolobjectlink.prolog.PrologOperator;
29  import io.github.prolobjectlink.prolog.PrologOperatorSet;
30  import jTrolog.engine.Prolog;
31  
32  /**
33   * 
34   * @author Jose Zalacain
35   * @since 1.0
36   */
37  final class JTrologOperatorSet extends AbstractSet<PrologOperator> implements PrologOperatorSet {
38  
39  	private final Set<PrologOperator> operators;
40  
41  	JTrologOperatorSet() {
42  		Prolog engine = Prolog.defaultMachine;
43  		operators = JTrologUtil.getOperatorSet(engine);
44  	}
45  
46  	public boolean currentOp(String opreator) {
47  		for (PrologOperator operatorEntry : operators) {
48  			if (operatorEntry.getOperator().equals(opreator)) {
49  				return true;
50  			}
51  		}
52  		return false;
53  	}
54  
55  	@Override
56  	public Iterator<PrologOperator> iterator() {
57  		return operators.iterator();
58  	}
59  
60  	@Override
61  	public int size() {
62  		return operators.size();
63  	}
64  
65  	@Override
66  	public int hashCode() {
67  		final int prime = 31;
68  		int result = super.hashCode();
69  		result = prime * result + ((operators == null) ? 0 : operators.hashCode());
70  		return result;
71  	}
72  
73  	@Override
74  	public boolean equals(Object obj) {
75  		if (this == obj)
76  			return true;
77  		if (!super.equals(obj))
78  			return false;
79  		if (getClass() != obj.getClass())
80  			return false;
81  		JTrologOperatorSet other = (JTrologOperatorSet) obj;
82  		if (operators == null) {
83  			if (other.operators != null)
84  				return false;
85  		} else if (!operators.equals(other.operators)) {
86  			return false;
87  		}
88  		return true;
89  	}
90  
91  }