1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package io.github.prolobjectlink.prolog;
27
28
29
30
31
32
33
34 public abstract class AbstractOperator implements PrologOperator {
35
36 private final int priority;
37 private final String specifier;
38 private final String operator;
39
40 public AbstractOperator(int priority, String specifier, String operator) {
41 this.priority = priority;
42 this.specifier = specifier;
43 this.operator = operator;
44 }
45
46 public final int getPriority() {
47 return priority;
48 }
49
50 public final String getSpecifier() {
51 return specifier;
52 }
53
54 public final String getOperator() {
55 return operator;
56 }
57
58 @Override
59 public final String toString() {
60 return "op(" + priority + "," + specifier + "," + operator + ")";
61 }
62
63 @Override
64 public final int hashCode() {
65 final int prime = 31;
66 int result = 1;
67 result = prime * result + ((operator == null) ? 0 : operator.hashCode());
68 result = prime * result + priority;
69 result = prime * result + ((specifier == null) ? 0 : specifier.hashCode());
70 return result;
71 }
72
73 @Override
74 public final boolean equals(Object object) {
75 if (this == object)
76 return true;
77 if (object == null)
78 return false;
79 if (getClass() != object.getClass())
80 return false;
81 AbstractOperator other = (AbstractOperator) object;
82 if (operator == null) {
83 if (other.operator != null)
84 return false;
85 } else if (!operator.equals(other.operator)) {
86 return false;
87 }
88 if (priority != other.priority)
89 return false;
90 if (specifier == null) {
91 if (other.specifier != null)
92 return false;
93 } else if (!specifier.equals(other.specifier)) {
94 return false;
95 }
96 return true;
97 }
98
99 public int compareTo(PrologOperator o) {
100 if (operator != null) {
101 if (priority > o.getPriority()) {
102 return 1;
103 } else if (priority < o.getPriority()) {
104 return -1;
105 }
106 }
107 return 0;
108 }
109
110 }