aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/InputKeyImplication.java
blob: 2a40381026b001b5e287e08511362af6698a0766 (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
/*******************************************************************************
 * Copyright (c) 2010-2015, 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.matchers.context;

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

/**
 * Data object representing the implication of an input key, in use cases including edge supertypes, edge opposites, node type constraints, etc.
 * 
 * <p> Each instance tuple of the <i>implying input key</i> (if given) implies the presence of an instance tuple of the <i>implied input key</i> consisting of elements of the original tuple at given positions.
 * When the input key is null, it is not an input constraint but some other source that implies input keys.
 * 
 * <p> The implication is an immutable data object.
 * 
 * @author Bergmann Gabor
 *
 */
public final class InputKeyImplication {
    private IInputKey implyingKey;
    private IInputKey impliedKey;
    private List<Integer> impliedIndices;

    /**
     * Optional. Instance tuples of this input key imply an instance tuple of another key. 
     * Sometimes it is not an input key that implies other input keys, so this attribute can be null.
     */
    public IInputKey getImplyingKey() {
        return implyingKey;
    }
    /**
     * An instance tuple of this input key is implied by another key.
     */
    public IInputKey getImpliedKey() {
        return impliedKey;
    }
    /**
     * The implied instance tuple consists of the values in the implying tuple at these indices.
     */
    public List<Integer> getImpliedIndices() {
        return impliedIndices;
    }
    /**
     * @param implyingKey instance tuples of this input key imply an instance tuple of the other key.
     * @param impliedKey instance tuple of this input key is implied by the other key.
     * @param implyingIndices the implied instance tuple consists of the values in the implying tuple at these indices.
     */
    public InputKeyImplication(IInputKey implyingKey, IInputKey impliedKey,
            List<Integer> implyingIndices) {
        super();
        this.implyingKey = implyingKey;
        this.impliedKey = impliedKey;
        this.impliedIndices = Collections.unmodifiableList(new ArrayList<>(implyingIndices));
    }
    
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((impliedIndices == null) ? 0 : impliedIndices.hashCode());
        result = prime * result
                + ((impliedKey == null) ? 0 : impliedKey.hashCode());
        result = prime * result
                + ((implyingKey == null) ? 0 : implyingKey.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof InputKeyImplication))
            return false;
        InputKeyImplication other = (InputKeyImplication) obj;
        if (impliedIndices == null) {
            if (other.impliedIndices != null)
                return false;
        } else if (!impliedIndices.equals(other.impliedIndices))
            return false;
        if (impliedKey == null) {
            if (other.impliedKey != null)
                return false;
        } else if (!impliedKey.equals(other.impliedKey))
            return false;
        if (implyingKey == null) {
            if (other.implyingKey != null)
                return false;
        } else if (!implyingKey.equals(other.implyingKey))
            return false;
        return true;
    }


}