aboutsummaryrefslogtreecommitdiffstats
path: root/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.java
blob: dceef9f8260090e5595e6ac7242000b0bf0a96be (plain) (blame)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft;

import com.google.common.collect.ImmutableSet;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantEvent;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Event;
import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent;
import java.util.Set;
import org.eclipse.xtend.lib.annotations.Data;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

@Data
@SuppressWarnings("all")
public class EventCollection {
  public static class Builder {
    private int falseEventCount = 0;
    
    private int trueEventCount = 0;
    
    private final ImmutableSet.Builder<RandomEvent> randomEventsBuilder = ImmutableSet.<RandomEvent>builder();
    
    private Builder() {
    }
    
    public EventCollection.Builder add(final Event event) {
      EventCollection.Builder _xblockexpression = null;
      {
        boolean _matched = false;
        if (event instanceof ConstantEvent) {
          _matched=true;
          boolean _isFailed = ((ConstantEvent)event).isFailed();
          if (_isFailed) {
            this.trueEventCount++;
          } else {
            this.falseEventCount++;
          }
        }
        if (!_matched) {
          if (event instanceof RandomEvent) {
            _matched=true;
            this.randomEventsBuilder.add(((RandomEvent)event));
          }
        }
        if (!_matched) {
          throw new IllegalArgumentException(("Unknown event: " + event));
        }
        _xblockexpression = this;
      }
      return _xblockexpression;
    }
    
    public EventCollection.Builder addAll(final EventCollection materializedEvens) {
      EventCollection.Builder _xblockexpression = null;
      {
        int _falseEventCount = this.falseEventCount;
        this.falseEventCount = (_falseEventCount + materializedEvens.falseEventCount);
        int _trueEventCount = this.trueEventCount;
        this.trueEventCount = (_trueEventCount + materializedEvens.trueEventCount);
        this.randomEventsBuilder.addAll(materializedEvens.randomEvents);
        _xblockexpression = this;
      }
      return _xblockexpression;
    }
    
    public EventCollection build() {
      ImmutableSet<RandomEvent> _build = this.randomEventsBuilder.build();
      return new EventCollection(this.falseEventCount, this.trueEventCount, _build);
    }
  }
  
  private final int falseEventCount;
  
  private final int trueEventCount;
  
  private final Set<RandomEvent> randomEvents;
  
  public boolean containsFalseEvent() {
    return (this.falseEventCount >= 1);
  }
  
  public boolean containsTrueEvent() {
    return (this.trueEventCount >= 1);
  }
  
  public int getVariableEventCount() {
    return this.randomEvents.size();
  }
  
  public boolean containsRandomEvent() {
    int _variableEventCount = this.getVariableEventCount();
    return (_variableEventCount >= 1);
  }
  
  public int getCount() {
    int _variableEventCount = this.getVariableEventCount();
    return ((this.falseEventCount + this.trueEventCount) + _variableEventCount);
  }
  
  public boolean isEmpty() {
    return (((!this.containsFalseEvent()) && (!this.containsTrueEvent())) && (!this.containsRandomEvent()));
  }
  
  public boolean containsExactlyOneRandomEvent() {
    return (((!this.containsFalseEvent()) && (!this.containsTrueEvent())) && (this.getVariableEventCount() == 1));
  }
  
  public RandomEvent toSingleRandomEvent() {
    RandomEvent _xblockexpression = null;
    {
      boolean _containsExactlyOneRandomEvent = this.containsExactlyOneRandomEvent();
      boolean _not = (!_containsExactlyOneRandomEvent);
      if (_not) {
        throw new IllegalStateException("Input collection is not a single random event");
      }
      _xblockexpression = IterableExtensions.<RandomEvent>head(this.randomEvents);
    }
    return _xblockexpression;
  }
  
  public static EventCollection.Builder builder() {
    return new EventCollection.Builder();
  }
  
  public EventCollection(final int falseEventCount, final int trueEventCount, final Set<RandomEvent> randomEvents) {
    super();
    this.falseEventCount = falseEventCount;
    this.trueEventCount = trueEventCount;
    this.randomEvents = randomEvents;
  }
  
  @Override
  @Pure
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + this.falseEventCount;
    result = prime * result + this.trueEventCount;
    return prime * result + ((this.randomEvents== null) ? 0 : this.randomEvents.hashCode());
  }
  
  @Override
  @Pure
  public boolean equals(final Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    EventCollection other = (EventCollection) obj;
    if (other.falseEventCount != this.falseEventCount)
      return false;
    if (other.trueEventCount != this.trueEventCount)
      return false;
    if (this.randomEvents == null) {
      if (other.randomEvents != null)
        return false;
    } else if (!this.randomEvents.equals(other.randomEvents))
      return false;
    return true;
  }
  
  @Override
  @Pure
  public String toString() {
    ToStringBuilder b = new ToStringBuilder(this);
    b.add("falseEventCount", this.falseEventCount);
    b.add("trueEventCount", this.trueEventCount);
    b.add("randomEvents", this.randomEvents);
    return b.toString();
  }
  
  @Pure
  public int getFalseEventCount() {
    return this.falseEventCount;
  }
  
  @Pure
  public int getTrueEventCount() {
    return this.trueEventCount;
  }
  
  @Pure
  public Set<RandomEvent> getRandomEvents() {
    return this.randomEvents;
  }
}