Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TermSpecification |
|
| 3.857142857142857;3.857 |
1 | package org.kuali.rice.krms.api.engine; | |
2 | ||
3 | import java.io.Serializable; | |
4 | ||
5 | import org.apache.commons.lang.builder.CompareToBuilder; | |
6 | ||
7 | /** | |
8 | * Specifies name and type for Terms. | |
9 | * @author gilesp | |
10 | */ | |
11 | 0 | public final class TermSpecification implements Comparable<TermSpecification>, Serializable { |
12 | ||
13 | private static final long serialVersionUID = 1L; | |
14 | ||
15 | private final String name; | |
16 | private final String type; | |
17 | ||
18 | /** | |
19 | * This constructs a TermSpecification, which defines a (blech) type of data that is most likely obtainable | |
20 | * through the {@link TermResolutionEngine}. Or perhaps more accurately, it maps a kind of data item to a | |
21 | * specific service (a {@link TermResolver}) to resolve instances of it. | |
22 | * | |
23 | * @param name | |
24 | * @param type | |
25 | */ | |
26 | 0 | public TermSpecification(String name, String type) { |
27 | 0 | if (name == null) throw new IllegalArgumentException("name is required"); |
28 | 0 | if (name.contains("!")) throw new IllegalArgumentException("name contains illegal character '!'"); |
29 | 0 | if (type == null) throw new IllegalArgumentException("type is required"); |
30 | 0 | if (type.contains("!")) throw new IllegalArgumentException("type contains illegal character '!'"); |
31 | 0 | this.name = name; |
32 | 0 | this.type = type; |
33 | 0 | } |
34 | ||
35 | 0 | public String getName() { return name; } |
36 | 0 | public String getType() { return type; } |
37 | ||
38 | /* (non-Javadoc) | |
39 | * @see java.lang.Object#hashCode() | |
40 | */ | |
41 | @Override | |
42 | public int hashCode() { | |
43 | 0 | final int prime = 31; |
44 | 0 | int result = 1; |
45 | 0 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
46 | 0 | result = prime * result + ((type == null) ? 0 : type.hashCode()); |
47 | 0 | return result; |
48 | } | |
49 | ||
50 | /* (non-Javadoc) | |
51 | * @see java.lang.Object#equals(java.lang.Object) | |
52 | */ | |
53 | @Override | |
54 | public boolean equals(Object obj) { | |
55 | 0 | if (this == obj) |
56 | 0 | return true; |
57 | 0 | if (obj == null) |
58 | 0 | return false; |
59 | 0 | if (getClass() != obj.getClass()) |
60 | 0 | return false; |
61 | 0 | TermSpecification other = (TermSpecification) obj; |
62 | 0 | return this.compareTo(other) == 0; |
63 | } | |
64 | ||
65 | @Override | |
66 | public int compareTo(TermSpecification o) { | |
67 | 0 | if (o == null) return 1; |
68 | 0 | if (this == o) return 0; |
69 | ||
70 | 0 | return new CompareToBuilder() |
71 | .append(this.name, o.name) | |
72 | .append(this.type, o.type) | |
73 | .toComparison(); | |
74 | } | |
75 | ||
76 | @Override | |
77 | public String toString() { | |
78 | 0 | return getClass().getSimpleName() + "(name: " + name + ", type: " + type + ")"; |
79 | } | |
80 | ||
81 | } |