-
Notifications
You must be signed in to change notification settings - Fork 26
/
ConstructorParameters.java
69 lines (58 loc) · 2.08 KB
/
ConstructorParameters.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package pl.pojo.tester.api;
import lombok.Getter;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.util.Arrays;
/**
* Defines constructor parameters and constructor parameter's types.
* <p>
* Constructor parameters's types are used to select constructor.
* <p>
* Constructor parameters are passed to selected constructor
*
* @author Piotr Joński
* @since 0.1.0
*/
@Getter
public class ConstructorParameters {
private final Object[] constructorParameters;
private final Class<?>[] constructorParametersTypes;
/**
* Instantiates {@code ConstructorParameters} with given constructor parameters and constructor parameter's types.
*
* @param constructorParameters constructor parameters
* @param constructorParametersTypes constructor parameter's types
*/
public ConstructorParameters(final Object[] constructorParameters, final Class<?>[] constructorParametersTypes) {
this.constructorParameters = constructorParameters;
this.constructorParametersTypes = constructorParametersTypes;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final ConstructorParameters that = (ConstructorParameters) o;
return new EqualsBuilder().append(constructorParameters, that.constructorParameters)
.append(constructorParametersTypes, that.constructorParametersTypes)
.isEquals();
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return new HashCodeBuilder().append(constructorParameters)
.append(constructorParametersTypes)
.toHashCode();
}
public boolean matches(final Class<?>[] parameterTypes) {
return Arrays.equals(constructorParametersTypes, parameterTypes);
}
}