-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompositeRequirement.java
48 lines (39 loc) · 1.32 KB
/
CompositeRequirement.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
package com.jcp.automation.common.requirements;
import com.jcp.automation.common.ErrorCodes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author ykrasnopolskiy
* @since 3/20/17.
*/
public class CompositeRequirement implements Requirement {
List<Requirement> requirementsList;
public List<Requirement> getRequirementsList() {
return requirementsList;
}
public void setRequirementsList(List<Requirement> requirementsList) {
this.requirementsList = requirementsList;
}
CompositeRequirement(Requirement... requirements){
requirementsList = new ArrayList<>(Arrays.asList(requirements));
}
@Override
public boolean meets(Object objectToCheck) {
boolean result = true;
for (Requirement requirement : requirementsList){
result = result && requirement.meets(objectToCheck);
if (!result) break;
}
return result;
}
@Override
public ErrorCodes getAssociatedError(Object objectToCheck) {
ErrorCodes errorCode = null;
for (Requirement requirement : requirementsList){
errorCode = requirement.getAssociatedError(objectToCheck);
if (errorCode != null) break;
}
return errorCode;
}
}