diff options
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/MatcherReference.java')
-rw-r--r-- | subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/MatcherReference.java | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/MatcherReference.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/MatcherReference.java new file mode 100644 index 00000000..6bf25192 --- /dev/null +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/MatcherReference.java | |||
@@ -0,0 +1,97 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Zoltan Ujhelyi, Marton Bur, Istvan Rath and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.matcher; | ||
10 | |||
11 | import java.util.Set; | ||
12 | |||
13 | import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint; | ||
14 | import tools.refinery.viatra.runtime.matchers.psystem.queries.PParameter; | ||
15 | import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery; | ||
16 | |||
17 | public class MatcherReference { | ||
18 | final PQuery query; | ||
19 | final Set<PParameter> adornment; | ||
20 | |||
21 | /** | ||
22 | * Hints that can override the callee's own hints. This field is intentionally left out from hashCode and equals | ||
23 | */ | ||
24 | final QueryEvaluationHint hints; | ||
25 | |||
26 | /** | ||
27 | * @since 1.4 | ||
28 | */ | ||
29 | public MatcherReference(PQuery query, Set<PParameter> adornment, QueryEvaluationHint hints) { | ||
30 | super(); | ||
31 | this.query = query; | ||
32 | this.adornment = adornment; | ||
33 | this.hints = hints; | ||
34 | } | ||
35 | |||
36 | public MatcherReference(PQuery query, Set<PParameter> adornment){ | ||
37 | this(query, adornment, null); | ||
38 | } | ||
39 | |||
40 | public PQuery getQuery() { | ||
41 | return query; | ||
42 | } | ||
43 | public Set<PParameter> getAdornment() { | ||
44 | return adornment; | ||
45 | } | ||
46 | @Override | ||
47 | public int hashCode() { | ||
48 | final int prime = 31; | ||
49 | int result = 1; | ||
50 | |||
51 | result = prime * result + ((adornment == null) ? 0 : adornment.hashCode()); | ||
52 | result = prime * result + ((query == null) ? 0 : query.hashCode()); | ||
53 | return result; | ||
54 | } | ||
55 | @Override | ||
56 | public boolean equals(Object obj) { | ||
57 | if (this == obj) | ||
58 | return true; | ||
59 | if (obj == null) | ||
60 | return false; | ||
61 | if (getClass() != obj.getClass()) | ||
62 | return false; | ||
63 | MatcherReference other = (MatcherReference) obj; | ||
64 | if (adornment == null) { | ||
65 | if (other.adornment != null) | ||
66 | return false; | ||
67 | } else if (!adornment.equals(other.adornment)) | ||
68 | return false; | ||
69 | if (query == null) { | ||
70 | if (other.query != null) | ||
71 | return false; | ||
72 | } else if (!query.equals(other.query)) | ||
73 | return false; | ||
74 | return true; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * @return the hints to override the called reference's own hints with. Can be null. | ||
79 | * @since 1.4 | ||
80 | */ | ||
81 | public QueryEvaluationHint getHints() { | ||
82 | return hints; | ||
83 | } | ||
84 | |||
85 | @Override | ||
86 | public String toString() { | ||
87 | StringBuilder sb = new StringBuilder(); | ||
88 | sb.append(query.getFullyQualifiedName()); | ||
89 | sb.append("("); | ||
90 | for(PParameter p : query.getParameters()){ | ||
91 | sb.append(adornment.contains(p) ? "b" : "f"); | ||
92 | } | ||
93 | sb.append(")"); | ||
94 | return sb.toString(); | ||
95 | } | ||
96 | |||
97 | } \ No newline at end of file | ||