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
|
/*******************************************************************************
* Copyright (c) 2010-2014, Zoltan Ujhelyi, 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.psystem.queries;
import java.util.Objects;
import tools.refinery.viatra.runtime.matchers.context.IInputKey;
/**
* A descriptor for declared PQuery parameters. A parameter has a name, a declared type and a direction constraint
*
* @author Zoltan Ujhelyi
*
*/
public class PParameter {
private final String name;
private final String typeName;
private final IInputKey declaredUnaryType;
private final PParameterDirection direction;
public PParameter(String name) {
this(name, (String) null);
}
public PParameter(String name, String typeName) {
this(name, typeName, (IInputKey) null);
}
public PParameter(String name, String typeName, IInputKey declaredUnaryType) {
this(name, typeName, declaredUnaryType, PParameterDirection.INOUT);
}
/**
* @since 1.4
*/
public PParameter(String name, String typeName, IInputKey declaredUnaryType, PParameterDirection direction) {
super();
this.name = name;
this.typeName = typeName;
this.declaredUnaryType = declaredUnaryType;
this.direction = direction;
if (declaredUnaryType != null && declaredUnaryType.getArity() != 1) {
throw new IllegalArgumentException(
"PParameter declared type must be unary instead of " + declaredUnaryType.getPrettyPrintableName());
}
}
/**
* @return the direction
* @since 1.4
*/
public PParameterDirection getDirection() {
return direction;
}
/**
* @return the name of the parameter
*/
public String getName() {
return name;
}
/**
* Returns a textual representation of the declared type of the parameter
*
* @return the type description, or null if not available
*/
public String getTypeName() {
return typeName;
}
/**
* Yield an {@link IInputKey} representation of the type declared for this parameter.
*
* @return the unary type that was declared on this parameter in the query header, or null if not available
*/
public IInputKey getDeclaredUnaryType() {
return declaredUnaryType;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof PParameter) {
return Objects.equals(name, ((PParameter) obj).name)
&& Objects.equals(typeName, ((PParameter) obj).typeName)
&& Objects.equals(declaredUnaryType, ((PParameter) obj).declaredUnaryType)
&& Objects.equals(direction, ((PParameter) obj).direction);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(name, typeName, declaredUnaryType);
}
}
|