View Javadoc

1   /*-
2    * #%L
3    * prolobjectlink-jpi
4    * %%
5    * Copyright (C) 2012 - 2019 Prolobjectlink Project
6    * %%
7    * Permission is hereby granted, free of charge, to any person obtaining a copy
8    * of this software and associated documentation files (the "Software"), to deal
9    * in the Software without restriction, including without limitation the rights
10   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11   * copies of the Software, and to permit persons to whom the Software is
12   * furnished to do so, subject to the following conditions:
13   * 
14   * The above copyright notice and this permission notice shall be included in
15   * all copies or substantial portions of the Software.
16   * 
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23   * THE SOFTWARE.
24   * #L%
25   */
26  package io.github.prolobjectlink.prolog;
27  
28  /**
29   * Partial implementation of {@link PrologIndicator} interface.
30   * 
31   * @author Jose Zalacain
32   * @since 1.0
33   */
34  public class AbstractIndicator implements PrologIndicator {
35  
36  	private final String functor;
37  	private final int arity;
38  
39  	protected AbstractIndicator(String functor, int arity) {
40  		this.functor = functor;
41  		this.arity = arity;
42  	}
43  
44  	public final String getIndicator() {
45  		return functor + "/" + arity;
46  	}
47  
48  	public final String getFunctor() {
49  		return functor;
50  	}
51  
52  	public final int getArity() {
53  		return arity;
54  	}
55  
56  	@Override
57  	public final String toString() {
58  		return getIndicator();
59  	}
60  
61  	@Override
62  	public final int hashCode() {
63  		final int prime = 31;
64  		int result = 1;
65  		result = prime * result + arity;
66  		result = prime * result + ((functor == null) ? 0 : functor.hashCode());
67  		return result;
68  	}
69  
70  	@Override
71  	public final boolean equals(Object object) {
72  		if (this == object)
73  			return true;
74  		if (object == null)
75  			return false;
76  //		if (getClass() != object.getClass())
77  //			return false;
78  		AbstractIndicator other = (AbstractIndicator) object;
79  		if (arity != other.arity)
80  			return false;
81  		if (functor == null) {
82  			if (other.functor != null)
83  				return false;
84  		} else if (!functor.equals(other.functor)) {
85  			return false;
86  		}
87  		return true;
88  	}
89  
90  }