aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/psystem/basicenumerables/BinaryReflexiveTransitiveClosure.java
blob: e3dae240a625cfcec541cfc824fdf6d960f1fd37 (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
/*******************************************************************************
 * Copyright (c) 2004-2010 Zoltan Ujhelyi, Gabor Bergmann, IncQuery Labs Ltd.
 * 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.psystem.basicenumerables;

import tools.refinery.viatra.runtime.matchers.context.IInputKey;
import tools.refinery.viatra.runtime.matchers.planning.QueryProcessingException;
import tools.refinery.viatra.runtime.matchers.psystem.PBody;
import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery;
import tools.refinery.viatra.runtime.matchers.tuple.Tuple;

/**
 * For a binary base pattern over an enumerable universe type, computes the reflexive transitive closure (base)*
 * 
 * @author Gabor Bergmann, Zoltan Ujhelyi
 * @since 2.0
 */
public class BinaryReflexiveTransitiveClosure extends AbstractTransitiveClosure {

    private final IInputKey universeType;

    public BinaryReflexiveTransitiveClosure(PBody pBody, Tuple variablesTuple,
            PQuery pattern, IInputKey universeType) {
        super(pBody, variablesTuple, pattern);
        this.universeType = universeType;
    }

    @Override
    protected String keyToString() {
        return supplierKey.getFullyQualifiedName() + "*";
    }

    /**
     * Returns the type whose instances should be returned as 0-long paths. 
     * @since 2.0
     */
    public IInputKey getUniverseType() {
        return universeType;
    }

    @Override
    public void checkSanity() {
        if (!universeType.isEnumerable() || universeType.getArity() != 1) {
            throw new QueryProcessingException(
                    String.format("Invalid universe type %s - it should be enumerable and must have an arity of 1.",
                            universeType.getPrettyPrintableName()),
                    pBody.getPattern());
        }
    }
    
}