1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
35
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 }