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