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
27
28
29 package io.github.prolobjectlink.prolog.jpl7;
30
31 import java.util.Map.Entry;
32
33 import io.github.prolobjectlink.prolog.AbstractCompounds;
34 import io.github.prolobjectlink.prolog.PrologEntry;
35 import io.github.prolobjectlink.prolog.PrologProvider;
36 import io.github.prolobjectlink.prolog.PrologTerm;
37 import io.github.prolobjectlink.prolog.PrologTermType;
38
39
40
41
42
43
44
45
46 public final class JplEntry extends AbstractCompounds implements PrologEntry {
47
48 private final PrologTerm key;
49 private PrologTerm value;
50
51 JplEntry(PrologProvider provider, PrologTerm key, PrologTerm value) {
52 super(PrologTermType.MAP_ENTRY_TYPE, provider);
53 this.value = value;
54 this.key = key;
55 }
56
57 public PrologTerm getKey() {
58 return key;
59 }
60
61 public PrologTerm getValue() {
62 return value;
63 }
64
65 public PrologTerm setValue(PrologTerm value) {
66 this.value = value;
67 return value;
68 }
69
70 public boolean isList() {
71 return false;
72 }
73
74 public boolean isStructure() {
75 return true;
76 }
77
78 public boolean isEmptyList() {
79 return false;
80 }
81
82 public String getFunctor() {
83 return "-";
84 }
85
86 public int getArity() {
87 return 2;
88 }
89
90 public PrologTerm[] getArguments() {
91 return new PrologTerm[] { key, value };
92 }
93
94 @Override
95 public int hashCode() {
96 int result = 0;
97 final int prime = 31;
98 result = prime * result + ((key == null) ? 0 : key.hashCode());
99 result = prime * result + ((value == null) ? 0 : value.hashCode());
100 return result;
101 }
102
103 @Override
104 public boolean equals(Object obj) {
105 if (this == obj)
106 return true;
107 if (obj == null)
108 return false;
109 if (getClass() != obj.getClass())
110 return false;
111 JplEntry other = (JplEntry) obj;
112 if (key == null) {
113 if (other.key != null)
114 return false;
115 } else if (!key.equals(other.key)) {
116 return false;
117 }
118 if (value == null) {
119 if (other.value != null)
120 return false;
121 } else if (!value.equals(other.value)) {
122 return false;
123 }
124 return true;
125 }
126
127 @Override
128 public String toString() {
129 return "" + key + "-" + value + "";
130 }
131
132 }