01: /**
02: * Copyright 2007 Jens Dietrich Licensed under the Apache License, Version 2.0 (the "License");
03: * you may not use this file except in compliance with the License.
04: * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
05: * Unless required by applicable law or agreed to in writing, software distributed under the
06: * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
07: * either express or implied. See the License for the specific language governing permissions
08: * and limitations under the License.
09: */package nz.org.take;
10:
11: /**
12: * Typed variable.
13: * @author <a href="http://www-ist.massey.ac.nz/JBDietrich/">Jens Dietrich</a>
14: */
15:
16: public class Variable extends AbstractAnnotatable implements Term {
17:
18: private String name = null;
19: private Class type = null;
20:
21: public String getName() {
22: return name;
23: }
24:
25: public void setName(String name) {
26: this .name = name;
27: }
28:
29: public Class getType() {
30: return type;
31: }
32:
33: public void setType(Class type) {
34: this .type = type;
35: }
36:
37: public String toString() {
38: StringBuffer b = new StringBuffer();
39: b.append('<');
40: b.append(name);
41: b.append('>');
42: return b.toString();
43: }
44:
45: public void accept(KnowledgeBaseVisitor visitor) {
46: visitor.visit(this );
47: visitor.endVisit(this );
48: }
49:
50: @Override
51: public int hashCode() {
52: final int prime = 31;
53: int result = 1;
54: result = prime * result
55: + ((name == null) ? 0 : name.hashCode());
56: result = prime * result
57: + ((type == null) ? 0 : type.hashCode());
58: return result;
59: }
60:
61: @Override
62: public boolean equals(Object obj) {
63: if (this == obj)
64: return true;
65: if (obj == null)
66: return false;
67: if (getClass() != obj.getClass())
68: return false;
69: final Variable other = (Variable) obj;
70: if (name == null) {
71: if (other.name != null)
72: return false;
73: } else if (!name.equals(other.name))
74: return false;
75: if (type == null) {
76: if (other.type != null)
77: return false;
78: } else if (!type.equals(other.type))
79: return false;
80: return true;
81: }
82:
83: }
|