1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.tomgibara.pronto.state.impl;
20
21 import com.tomgibara.pronto.state.StateTransition;
22 import com.tomgibara.pronto.util.Arguments;
23
24 public class StateTransitionImpl<S, L> implements StateTransition<S, L> {
25
26
27
28 private final S source;
29
30 private final L label;
31
32 private final S target;
33
34 private final int hashCode;
35
36
37
38 public StateTransitionImpl(final StateTransition<S, L> transition) {
39 this(transition.getSource(), transition.getLabel(), transition.getTarget());
40 }
41
42 public StateTransitionImpl(final S source, final L label, final S target) {
43 Arguments.notNull(source, "source");
44 Arguments.notNull(label, "label");
45 Arguments.notNull(target, "target");
46
47 this.source = source;
48 this.label = label;
49 this.target = target;
50
51 hashCode = source.hashCode() ^ label.hashCode() ^ 7 * target.hashCode();
52 }
53
54
55
56 public S getSource() {
57 return source;
58 }
59
60 public L getLabel() {
61 return label;
62 }
63
64 public S getTarget() {
65 return target;
66 }
67
68
69
70 @SuppressWarnings("unchecked")
71 @Override
72 public boolean equals(final Object obj) {
73 if (obj == this) return true;
74 if (!(obj instanceof StateTransitionImpl)) return false;
75 StateTransitionImpl<S, L> that = (StateTransitionImpl<S, L>) obj;
76 if (!this.source.equals(that.source)) return false;
77 if (!this.label.equals(that.label)) return false;
78 if (!this.target.equals(that.target)) return false;
79 return true;
80 }
81
82 @Override
83 public int hashCode() {
84 return hashCode;
85 }
86
87 @Override
88 public String toString() {
89 return "[transition from " + source + " to " + target + " via " + label + "]";
90 }
91
92 }