diff options
author | Kristóf Marussy <kris7topher@gmail.com> | 2019-02-16 00:43:11 +0100 |
---|---|---|
committer | Kristóf Marussy <kris7topher@gmail.com> | 2019-02-19 19:18:25 +0100 |
commit | d90bedacaafe87e06fddaa05a6ff9b7b796e97e7 (patch) | |
tree | 3631e27854b40de3bce7606f60113054c77bd391 /Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.java | |
parent | Ecore2Cft transformation (diff) | |
download | VIATRA-Generator-d90bedacaafe87e06fddaa05a6ff9b7b796e97e7.tar.gz VIATRA-Generator-d90bedacaafe87e06fddaa05a6ff9b7b796e97e7.tar.zst VIATRA-Generator-d90bedacaafe87e06fddaa05a6ff9b7b796e97e7.zip |
Two-valued fault tree analyzer WIP
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.java')
-rw-r--r-- | Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.java | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.java new file mode 100644 index 00000000..dceef9f8 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.java | |||
@@ -0,0 +1,188 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft; | ||
2 | |||
3 | import com.google.common.collect.ImmutableSet; | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantEvent; | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Event; | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent; | ||
7 | import java.util.Set; | ||
8 | import org.eclipse.xtend.lib.annotations.Data; | ||
9 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
10 | import org.eclipse.xtext.xbase.lib.Pure; | ||
11 | import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; | ||
12 | |||
13 | @Data | ||
14 | @SuppressWarnings("all") | ||
15 | public class EventCollection { | ||
16 | public static class Builder { | ||
17 | private int falseEventCount = 0; | ||
18 | |||
19 | private int trueEventCount = 0; | ||
20 | |||
21 | private final ImmutableSet.Builder<RandomEvent> randomEventsBuilder = ImmutableSet.<RandomEvent>builder(); | ||
22 | |||
23 | private Builder() { | ||
24 | } | ||
25 | |||
26 | public EventCollection.Builder add(final Event event) { | ||
27 | EventCollection.Builder _xblockexpression = null; | ||
28 | { | ||
29 | boolean _matched = false; | ||
30 | if (event instanceof ConstantEvent) { | ||
31 | _matched=true; | ||
32 | boolean _isFailed = ((ConstantEvent)event).isFailed(); | ||
33 | if (_isFailed) { | ||
34 | this.trueEventCount++; | ||
35 | } else { | ||
36 | this.falseEventCount++; | ||
37 | } | ||
38 | } | ||
39 | if (!_matched) { | ||
40 | if (event instanceof RandomEvent) { | ||
41 | _matched=true; | ||
42 | this.randomEventsBuilder.add(((RandomEvent)event)); | ||
43 | } | ||
44 | } | ||
45 | if (!_matched) { | ||
46 | throw new IllegalArgumentException(("Unknown event: " + event)); | ||
47 | } | ||
48 | _xblockexpression = this; | ||
49 | } | ||
50 | return _xblockexpression; | ||
51 | } | ||
52 | |||
53 | public EventCollection.Builder addAll(final EventCollection materializedEvens) { | ||
54 | EventCollection.Builder _xblockexpression = null; | ||
55 | { | ||
56 | int _falseEventCount = this.falseEventCount; | ||
57 | this.falseEventCount = (_falseEventCount + materializedEvens.falseEventCount); | ||
58 | int _trueEventCount = this.trueEventCount; | ||
59 | this.trueEventCount = (_trueEventCount + materializedEvens.trueEventCount); | ||
60 | this.randomEventsBuilder.addAll(materializedEvens.randomEvents); | ||
61 | _xblockexpression = this; | ||
62 | } | ||
63 | return _xblockexpression; | ||
64 | } | ||
65 | |||
66 | public EventCollection build() { | ||
67 | ImmutableSet<RandomEvent> _build = this.randomEventsBuilder.build(); | ||
68 | return new EventCollection(this.falseEventCount, this.trueEventCount, _build); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | private final int falseEventCount; | ||
73 | |||
74 | private final int trueEventCount; | ||
75 | |||
76 | private final Set<RandomEvent> randomEvents; | ||
77 | |||
78 | public boolean containsFalseEvent() { | ||
79 | return (this.falseEventCount >= 1); | ||
80 | } | ||
81 | |||
82 | public boolean containsTrueEvent() { | ||
83 | return (this.trueEventCount >= 1); | ||
84 | } | ||
85 | |||
86 | public int getVariableEventCount() { | ||
87 | return this.randomEvents.size(); | ||
88 | } | ||
89 | |||
90 | public boolean containsRandomEvent() { | ||
91 | int _variableEventCount = this.getVariableEventCount(); | ||
92 | return (_variableEventCount >= 1); | ||
93 | } | ||
94 | |||
95 | public int getCount() { | ||
96 | int _variableEventCount = this.getVariableEventCount(); | ||
97 | return ((this.falseEventCount + this.trueEventCount) + _variableEventCount); | ||
98 | } | ||
99 | |||
100 | public boolean isEmpty() { | ||
101 | return (((!this.containsFalseEvent()) && (!this.containsTrueEvent())) && (!this.containsRandomEvent())); | ||
102 | } | ||
103 | |||
104 | public boolean containsExactlyOneRandomEvent() { | ||
105 | return (((!this.containsFalseEvent()) && (!this.containsTrueEvent())) && (this.getVariableEventCount() == 1)); | ||
106 | } | ||
107 | |||
108 | public RandomEvent toSingleRandomEvent() { | ||
109 | RandomEvent _xblockexpression = null; | ||
110 | { | ||
111 | boolean _containsExactlyOneRandomEvent = this.containsExactlyOneRandomEvent(); | ||
112 | boolean _not = (!_containsExactlyOneRandomEvent); | ||
113 | if (_not) { | ||
114 | throw new IllegalStateException("Input collection is not a single random event"); | ||
115 | } | ||
116 | _xblockexpression = IterableExtensions.<RandomEvent>head(this.randomEvents); | ||
117 | } | ||
118 | return _xblockexpression; | ||
119 | } | ||
120 | |||
121 | public static EventCollection.Builder builder() { | ||
122 | return new EventCollection.Builder(); | ||
123 | } | ||
124 | |||
125 | public EventCollection(final int falseEventCount, final int trueEventCount, final Set<RandomEvent> randomEvents) { | ||
126 | super(); | ||
127 | this.falseEventCount = falseEventCount; | ||
128 | this.trueEventCount = trueEventCount; | ||
129 | this.randomEvents = randomEvents; | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | @Pure | ||
134 | public int hashCode() { | ||
135 | final int prime = 31; | ||
136 | int result = 1; | ||
137 | result = prime * result + this.falseEventCount; | ||
138 | result = prime * result + this.trueEventCount; | ||
139 | return prime * result + ((this.randomEvents== null) ? 0 : this.randomEvents.hashCode()); | ||
140 | } | ||
141 | |||
142 | @Override | ||
143 | @Pure | ||
144 | public boolean equals(final Object obj) { | ||
145 | if (this == obj) | ||
146 | return true; | ||
147 | if (obj == null) | ||
148 | return false; | ||
149 | if (getClass() != obj.getClass()) | ||
150 | return false; | ||
151 | EventCollection other = (EventCollection) obj; | ||
152 | if (other.falseEventCount != this.falseEventCount) | ||
153 | return false; | ||
154 | if (other.trueEventCount != this.trueEventCount) | ||
155 | return false; | ||
156 | if (this.randomEvents == null) { | ||
157 | if (other.randomEvents != null) | ||
158 | return false; | ||
159 | } else if (!this.randomEvents.equals(other.randomEvents)) | ||
160 | return false; | ||
161 | return true; | ||
162 | } | ||
163 | |||
164 | @Override | ||
165 | @Pure | ||
166 | public String toString() { | ||
167 | ToStringBuilder b = new ToStringBuilder(this); | ||
168 | b.add("falseEventCount", this.falseEventCount); | ||
169 | b.add("trueEventCount", this.trueEventCount); | ||
170 | b.add("randomEvents", this.randomEvents); | ||
171 | return b.toString(); | ||
172 | } | ||
173 | |||
174 | @Pure | ||
175 | public int getFalseEventCount() { | ||
176 | return this.falseEventCount; | ||
177 | } | ||
178 | |||
179 | @Pure | ||
180 | public int getTrueEventCount() { | ||
181 | return this.trueEventCount; | ||
182 | } | ||
183 | |||
184 | @Pure | ||
185 | public Set<RandomEvent> getRandomEvents() { | ||
186 | return this.randomEvents; | ||
187 | } | ||
188 | } | ||