|
1
|
|
|
package it.cnr.istc.pst.platinum.ai.framework.microkernel.lang.flaw; |
|
2
|
|
|
|
|
3
|
|
|
import java.util.ArrayList; |
|
4
|
|
|
import java.util.List; |
|
5
|
|
|
|
|
6
|
|
|
import it.cnr.istc.pst.platinum.ai.framework.domain.component.DomainComponent; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* |
|
10
|
|
|
* @author anacleto |
|
11
|
|
|
* |
|
12
|
|
|
*/ |
|
13
|
|
|
public abstract class Flaw |
|
14
|
|
|
{ |
|
15
|
|
|
private int id; |
|
16
|
|
|
private FlawType type; // the type of flaw |
|
17
|
|
|
private DomainComponent component; // the component the flaw belongs to |
|
18
|
|
|
private List<FlawSolution> solutions; // the list of available solutions |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* |
|
22
|
|
|
* @param id |
|
23
|
|
|
* @param component |
|
24
|
|
|
* @param type |
|
25
|
|
|
*/ |
|
26
|
|
|
protected Flaw(int id, DomainComponent component, FlawType type) { |
|
27
|
|
|
this.id = id; |
|
28
|
|
|
this.type = type; |
|
29
|
|
|
this.solutions = new ArrayList<>(); |
|
30
|
|
|
this.component = component; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* |
|
35
|
|
|
* @return |
|
36
|
|
|
*/ |
|
37
|
|
|
public final int getId() { |
|
38
|
|
|
return id; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* |
|
43
|
|
|
* @return |
|
44
|
|
|
*/ |
|
45
|
|
|
public final FlawType getType() { |
|
46
|
|
|
return type; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* |
|
51
|
|
|
* @return |
|
52
|
|
|
*/ |
|
53
|
|
|
public final FlawCategoryType getCategory() { |
|
54
|
|
|
return this.type.getCategory(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* |
|
59
|
|
|
* @return |
|
60
|
|
|
*/ |
|
61
|
|
|
public DomainComponent getComponent() { |
|
62
|
|
|
return component; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* |
|
67
|
|
|
* @return |
|
68
|
|
|
*/ |
|
69
|
|
|
public boolean isSolvable() { |
|
70
|
|
|
return !this.solutions.isEmpty(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* |
|
75
|
|
|
* @return |
|
76
|
|
|
*/ |
|
77
|
|
|
public final List<FlawSolution> getSolutions() { |
|
78
|
|
|
return new ArrayList<>(this.solutions); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* |
|
83
|
|
|
* @param sols |
|
84
|
|
|
*/ |
|
85
|
|
|
public final void setSolutions(List<FlawSolution> sols) { |
|
86
|
|
|
this.solutions = new ArrayList<>(sols); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* |
|
91
|
|
|
* @param solution |
|
92
|
|
|
*/ |
|
93
|
|
|
public final void addSolution(FlawSolution solution) { |
|
94
|
|
|
this.solutions.add(solution); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* |
|
99
|
|
|
* @return |
|
100
|
|
|
*/ |
|
101
|
|
|
public final int getDegree() { |
|
102
|
|
|
return this.solutions.size(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
@Override |
|
106
|
|
|
public int hashCode() { |
|
107
|
|
|
final int prime = 31; |
|
108
|
|
|
int result = 1; |
|
109
|
|
|
result = prime * result + ((component == null) ? 0 : component.hashCode()); |
|
110
|
|
|
result = prime * result + id; |
|
111
|
|
|
result = prime * result + ((type == null) ? 0 : type.hashCode()); |
|
112
|
|
|
return result; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
View Code Duplication |
@Override |
|
|
|
|
|
|
116
|
|
|
public boolean equals(Object obj) { |
|
117
|
|
|
if (this == obj) |
|
118
|
|
|
return true; |
|
119
|
|
|
if (obj == null) |
|
120
|
|
|
return false; |
|
121
|
|
|
if (getClass() != obj.getClass()) |
|
122
|
|
|
return false; |
|
123
|
|
|
Flaw other = (Flaw) obj; |
|
124
|
|
|
if (component == null) { |
|
125
|
|
|
if (other.component != null) |
|
126
|
|
|
return false; |
|
127
|
|
|
} else if (!component.equals(other.component)) |
|
128
|
|
|
return false; |
|
129
|
|
|
if (id != other.id) |
|
130
|
|
|
return false; |
|
131
|
|
|
if (type != other.type) |
|
132
|
|
|
return false; |
|
133
|
|
|
return true; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|