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.AbstractList;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import io.github.prolobjectlink.prolog.PrologClause;
29 import io.github.prolobjectlink.prolog.PrologClauses;
30
31 class JTrologClauses extends AbstractList<PrologClause> implements PrologClauses {
32
33 private final int arity;
34 private final String functor;
35 private final List<PrologClause> list;
36
37 JTrologClauses(String functor, int arity) {
38 list = new ArrayList<PrologClause>();
39 this.functor = functor;
40 this.arity = arity;
41 }
42
43 public void add(int index, PrologClause element) {
44 list.add(index, element);
45 }
46
47 public PrologClause remove(int index) {
48 return list.remove(index);
49 }
50
51 public PrologClause get(int index) {
52 return list.get(index);
53 }
54
55 public int size() {
56 return list.size();
57 }
58
59 public boolean isDynamic() {
60 for (PrologClause prologClause : list) {
61 if (!prologClause.isDynamic()) {
62 return false;
63 }
64 }
65 return true;
66 }
67
68 public boolean isMultifile() {
69 for (PrologClause prologClause : list) {
70 if (!prologClause.isMultifile()) {
71 return false;
72 }
73 }
74 return true;
75 }
76
77 public boolean isDiscontiguous() {
78 for (PrologClause prologClause : list) {
79 if (!prologClause.isDiscontiguous()) {
80 return false;
81 }
82 }
83 return true;
84 }
85
86 public String getIndicator() {
87 return functor + "/" + arity;
88 }
89
90 @Override
91 public int hashCode() {
92 final int prime = 31;
93 int result = super.hashCode();
94 result = prime * result + ((list == null) ? 0 : list.hashCode());
95 return result;
96 }
97
98 @Override
99 public boolean equals(Object obj) {
100 if (this == obj)
101 return true;
102 if (!super.equals(obj))
103 return false;
104 if (getClass() != obj.getClass())
105 return false;
106 JTrologClauses other = (JTrologClauses) obj;
107 if (list == null) {
108 if (other.list != null)
109 return false;
110 } else if (!list.equals(other.list)) {
111 return false;
112 }
113 return true;
114 }
115
116 }