|
1 | | - |
2 | | -package org.scijava.ops.api; |
3 | | - |
4 | | -import java.lang.reflect.Type; |
5 | | -import java.util.Objects; |
6 | | - |
7 | | -import org.scijava.types.GenericTyped; |
8 | | - |
9 | | -/** |
10 | | - * An instance of an {@link OpInfo} |
11 | | - * |
12 | | - * @author Gabriel Selzer |
13 | | - */ |
14 | | -public class OpInstance<T> implements GenericTyped { |
15 | | - |
16 | | - private final T op; |
17 | | - private final InfoChain info; |
18 | | - private final Type reifiedType; |
19 | | - |
20 | | - public OpInstance(final T op, final InfoChain backingInfo, |
21 | | - final Type reifiedType) |
22 | | - { |
23 | | - this.op = op; |
24 | | - this.info = backingInfo; |
25 | | - this.reifiedType = reifiedType; |
26 | | - } |
27 | | - |
28 | | - public static <T> OpInstance<T> of(T op, InfoChain backingInfo, |
29 | | - final Type reifiedType) |
30 | | - { |
31 | | - return new OpInstance<>(op, backingInfo, reifiedType); |
32 | | - } |
33 | | - |
34 | | - public T op() { |
35 | | - return op; |
36 | | - } |
37 | | - |
38 | | - public InfoChain infoChain() { |
39 | | - return info; |
40 | | - } |
41 | | - |
42 | | - @Override |
43 | | - public boolean equals(Object that) { |
44 | | - if (!(that instanceof OpInstance)) return false; |
45 | | - OpInstance<?> thatInstance = (OpInstance<?>) that; |
46 | | - boolean infosEqual = infoChain().equals(thatInstance.infoChain()); |
47 | | - boolean objectsEqual = op().equals(thatInstance.op()); |
48 | | - boolean typesEqual = getType().equals(thatInstance.getType()); |
49 | | - return infosEqual && objectsEqual && typesEqual; |
50 | | - } |
51 | | - |
52 | | - @Override |
53 | | - public int hashCode() { |
54 | | - return Objects.hash(infoChain(), op(), getType()); |
55 | | - } |
56 | | - |
57 | | - @Override |
58 | | - public Type getType() { |
59 | | - return reifiedType; |
60 | | - } |
61 | | - |
62 | | -} |
| 1 | + |
| 2 | +package org.scijava.ops.api; |
| 3 | + |
| 4 | +import java.lang.reflect.Type; |
| 5 | +import java.util.Objects; |
| 6 | + |
| 7 | +import org.scijava.types.GenericTyped; |
| 8 | + |
| 9 | +/** |
| 10 | + * An instance of an {@link OpInfo}. They can be constructed directly, but are |
| 11 | + * easily generated from {@link InfoChain}s. |
| 12 | + * <p> |
| 13 | + * Each {@link OpInstance} has an Op and its corresponding {@link OpInfo}. |
| 14 | + * </p> |
| 15 | + * |
| 16 | + * @author Gabriel Selzer |
| 17 | + */ |
| 18 | +public class OpInstance<T> implements GenericTyped { |
| 19 | + |
| 20 | + private final T op; |
| 21 | + private final InfoChain info; |
| 22 | + private final Type reifiedType; |
| 23 | + |
| 24 | + public OpInstance(final T op, final InfoChain backingInfo, |
| 25 | + final Type reifiedType) |
| 26 | + { |
| 27 | + this.op = op; |
| 28 | + this.info = backingInfo; |
| 29 | + this.reifiedType = reifiedType; |
| 30 | + } |
| 31 | + |
| 32 | + public static <T> OpInstance<T> of(T op, InfoChain backingInfo, |
| 33 | + final Type reifiedType) |
| 34 | + { |
| 35 | + return new OpInstance<>(op, backingInfo, reifiedType); |
| 36 | + } |
| 37 | + |
| 38 | + public T op() { |
| 39 | + return op; |
| 40 | + } |
| 41 | + |
| 42 | + public InfoChain infoChain() { |
| 43 | + return info; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public boolean equals(Object that) { |
| 48 | + if (!(that instanceof OpInstance)) return false; |
| 49 | + OpInstance<?> thatInstance = (OpInstance<?>) that; |
| 50 | + boolean infosEqual = infoChain().equals(thatInstance.infoChain()); |
| 51 | + boolean objectsEqual = op().equals(thatInstance.op()); |
| 52 | + boolean typesEqual = getType().equals(thatInstance.getType()); |
| 53 | + return infosEqual && objectsEqual && typesEqual; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public int hashCode() { |
| 58 | + return Objects.hash(infoChain(), op(), getType()); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public Type getType() { |
| 63 | + return reifiedType; |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments