View Javadoc

1   /*-
2    * #%L
3    * prolobjectlink-jpi-jpl
4    * %%
5    * Copyright (C) 2020 - 2021 Prolobjectlink Project
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as
9    * published by the Free Software Foundation, either version 2.1 of the
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20   * #L%
21   */
22  package io.github.prolobjectlink.prolog.jpl;
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 JplClauses extends AbstractList<PrologClause> implements PrologClauses {
32  
33  	private final int arity;
34  	private final String functor;
35  	private final List<PrologClause> list;
36  
37  	JplClauses(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 		JplClauses other = (JplClauses) 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 }