aboutsummaryrefslogtreecommitdiffstats
path: root/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/ComponentFaultTreeTrace.java
blob: 46e711d90a06e9e8f563346262da5e70d2414bff (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
package hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft;

import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.CftFactory;
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentDefinition;
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentFaultTree;
import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Output;
import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft.ComponentInstanceTrace;
import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft.ComponentNameGenerator;
import java.util.Map;
import org.eclipse.emf.common.util.EList;
import org.eclipse.viatra.query.runtime.api.IPatternMatch;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pure;

@SuppressWarnings("all")
public class ComponentFaultTreeTrace {
  @Accessors
  private final ComponentFaultTree componentFaultTree = CftFactory.eINSTANCE.createComponentFaultTree();
  
  private final ComponentNameGenerator nameGenerator = new ComponentNameGenerator();
  
  private final Map<IPatternMatch, ComponentInstanceTrace> componentInstancesMap = CollectionLiterals.<IPatternMatch, ComponentInstanceTrace>newHashMap();
  
  public ComponentInstanceTrace instantiateComponent(final IPatternMatch patternMatch, final ComponentDefinition componenDefinition) {
    ComponentInstanceTrace _xblockexpression = null;
    {
      boolean _containsKey = this.componentInstancesMap.containsKey(patternMatch);
      if (_containsKey) {
        throw new IllegalArgumentException(("Already instantiated component for match: " + patternMatch));
      }
      final ComponentInstanceTrace componentTrace = new ComponentInstanceTrace(this.componentFaultTree, componenDefinition, this.nameGenerator);
      this.componentInstancesMap.put(patternMatch, componentTrace);
      _xblockexpression = componentTrace;
    }
    return _xblockexpression;
  }
  
  public void setTopLevel(final ComponentInstanceTrace trace) {
    Output _topEvent = this.componentFaultTree.getTopEvent();
    boolean _tripleNotEquals = (_topEvent != null);
    if (_tripleNotEquals) {
      throw new IllegalArgumentException("Top level component already set");
    }
    final EList<Output> outputs = trace.getOutputs();
    int _size = outputs.size();
    boolean _tripleNotEquals_1 = (_size != 1);
    if (_tripleNotEquals_1) {
      int _size_1 = outputs.size();
      String _plus = ("Top level component must have 1 output, got " + Integer.valueOf(_size_1));
      String _plus_1 = (_plus + 
        " instead");
      throw new IllegalArgumentException(_plus_1);
    }
    this.componentFaultTree.setTopEvent(IterableExtensions.<Output>head(outputs));
  }
  
  public ComponentInstanceTrace lookup(final IPatternMatch patternMatch) {
    return this.componentInstancesMap.get(patternMatch);
  }
  
  @Pure
  public ComponentFaultTree getComponentFaultTree() {
    return this.componentFaultTree;
  }
}