aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/RecipeTraceInfo.java
blob: 8f6105504a7df53a2bc7971d94bb8b7c8842d8f9 (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
/*******************************************************************************
 * Copyright (c) 2010-2014, Bergmann Gabor, Istvan Rath and Daniel Varro
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-v20.html.
 * 
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package tools.refinery.viatra.runtime.rete.traceability;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import tools.refinery.viatra.runtime.rete.network.Node;
import tools.refinery.viatra.runtime.rete.recipes.ReteNodeRecipe;

/**
 * A trace marker that indicates the recipe for which the node was built.
 * @author Bergmann Gabor
 */
public class RecipeTraceInfo implements TraceInfo {
    public ReteNodeRecipe getRecipe() {return recipe;}
    /**
     * For cloning in case of recursion cut-off points, use {@link #getParentRecipeTracesForCloning()} instead.
     * @return an unmodifiable view on parent traces, to be constructed before this node (or alongside, in case of recursion)
     */
    public List<RecipeTraceInfo> getParentRecipeTraces() {return Collections.unmodifiableList(new ArrayList<>(parentRecipeTraces));}
    /**
     * Directly return the underlying collection so that changes to it will be transparent. Use only for recursion-tolerant cloning.
     * @noreference This method is not intended to be referenced by clients.
     */
    public Collection<? extends RecipeTraceInfo> getParentRecipeTracesForCloning() {return parentRecipeTraces;}
    @Override 
    public Node getNode() {return node;}
    
    private Node node;
    ReteNodeRecipe recipe;
    ReteNodeRecipe shadowedRecipe;
    Collection<? extends RecipeTraceInfo> parentRecipeTraces;
    
    
    public RecipeTraceInfo(ReteNodeRecipe recipe, Collection<? extends RecipeTraceInfo> parentRecipeTraces) {
        super();
        this.recipe = recipe;
        this.parentRecipeTraces = parentRecipeTraces; //ParentTraceList.from(parentRecipeTraces); 
    }
    public RecipeTraceInfo(ReteNodeRecipe recipe, RecipeTraceInfo... parentRecipeTraces) {
        this(recipe, Arrays.asList(parentRecipeTraces));
    }
    
    @Override
    public boolean propagateToIndexerParent() {return false;}
    @Override
    public boolean propagateFromIndexerToSupplierParent() {return false;}
    @Override
    public boolean propagateFromStandardNodeToSupplierParent() {return false;}
    @Override
    public boolean propagateToProductionNodeParentAlso() {return false;}
    @Override 
    public void assignNode(Node node) {this.node = node;}
    
    /**
     * @param knownRecipe a known recipe that is equivalent to the current recipe
     */
    public void shadowWithEquivalentRecipe(ReteNodeRecipe knownRecipe) {
        this.shadowedRecipe = this.recipe;
        this.recipe = knownRecipe;
    }
    
    /**
     * Get original recipe shadowed by an equivalent
     */
    public ReteNodeRecipe getShadowedRecipe() {
        return shadowedRecipe;
    }
    
    
}