source: josm/trunk/src/org/openstreetmap/josm/tools/template_engine/SearchExpressionCondition.java@ 16488

Last change on this file since 16488 was 16488, checked in by simon04, 4 years ago

fix #19281, see #19174 - Use Objects.hash where it is not used (patch by hiddewie, modified)

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools.template_engine;
3
4import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
5
6import java.util.Objects;
7
8/**
9 * Conditional {@link TemplateEntry} that executes another template in case a search expression applies
10 * to the given data provider.
11 */
12public class SearchExpressionCondition implements TemplateEntry {
13
14 private final Match condition;
15 private final TemplateEntry text;
16
17 /**
18 * Creates a new {@link SearchExpressionCondition}.
19 * @param condition the match condition that is checked before applying the child template
20 * @param text the child template to execute in case the condition is fulfilled
21 */
22 public SearchExpressionCondition(Match condition, TemplateEntry text) {
23 this.condition = condition;
24 this.text = text;
25 }
26
27 @Override
28 public void appendText(StringBuilder result, TemplateEngineDataProvider dataProvider) {
29 text.appendText(result, dataProvider);
30 }
31
32 @Override
33 public boolean isValid(TemplateEngineDataProvider dataProvider) {
34 return dataProvider.evaluateCondition(condition);
35 }
36
37 @Override
38 public String toString() {
39 return condition + " '" + text + '\'';
40 }
41
42 @Override
43 public int hashCode() {
44 return Objects.hash(condition, text);
45 }
46
47 @Override
48 public boolean equals(Object obj) {
49 if (this == obj)
50 return true;
51 if (obj == null || getClass() != obj.getClass())
52 return false;
53 SearchExpressionCondition other = (SearchExpressionCondition) obj;
54 if (condition == null) {
55 if (other.condition != null)
56 return false;
57 } else if (!condition.equals(other.condition))
58 return false;
59 if (text == null) {
60 if (other.text != null)
61 return false;
62 } else if (!text.equals(other.text))
63 return false;
64 return true;
65 }
66}
Note: See TracBrowser for help on using the repository browser.