1 | /** |
---|
2 | * This software is copyright (c) 2013-2016 by |
---|
3 | * - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
4 | * This is free software. You can redistribute it |
---|
5 | * and/or modify it under the terms described in |
---|
6 | * the GNU General Public License v3 of which you |
---|
7 | * should have received a copy. Otherwise you can download |
---|
8 | * it from |
---|
9 | * |
---|
10 | * http://www.gnu.org/licenses/gpl-3.0.txt |
---|
11 | * |
---|
12 | * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
13 | * |
---|
14 | * @license http://www.gnu.org/licenses/gpl-3.0.txt |
---|
15 | * GNU General Public License v3 |
---|
16 | */ |
---|
17 | package eu.clarin.sru.server.fcs.parser; |
---|
18 | |
---|
19 | |
---|
20 | /** |
---|
21 | * A FCS-QL expression tree GROUP query node. |
---|
22 | */ |
---|
23 | public class QueryGroup extends QueryNode { |
---|
24 | private final int minOccurs; |
---|
25 | private final int maxOccurs; |
---|
26 | |
---|
27 | |
---|
28 | /** |
---|
29 | * Constructor. |
---|
30 | * |
---|
31 | * @param content |
---|
32 | * the child |
---|
33 | * @param minOccurs |
---|
34 | * the minimum occurrence |
---|
35 | * @param maxOccurs |
---|
36 | * the maximum occurrence |
---|
37 | */ |
---|
38 | QueryGroup(QueryNode content, int minOccurs, int maxOccurs) { |
---|
39 | super(QueryNodeType.QUERY_GROUP, content); |
---|
40 | this.minOccurs = minOccurs; |
---|
41 | this.maxOccurs = maxOccurs; |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | /** |
---|
46 | * Get the group content. |
---|
47 | * |
---|
48 | * @return the content of the GROUP query |
---|
49 | */ |
---|
50 | public QueryNode getContent() { |
---|
51 | return children.get(0); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | /** |
---|
56 | * Get the minimum occurrence of group content. |
---|
57 | * |
---|
58 | * @return the minimum occurrence |
---|
59 | * |
---|
60 | */ |
---|
61 | public int getMinOccurs() { |
---|
62 | return minOccurs; |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | /** |
---|
67 | * Get the maximum occurrence of group content. |
---|
68 | * |
---|
69 | * @return the maximum occurrence |
---|
70 | * |
---|
71 | */ |
---|
72 | public int getMaxOccurs() { |
---|
73 | return maxOccurs; |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | @Override |
---|
78 | public String toString() { |
---|
79 | StringBuilder sb = new StringBuilder(); |
---|
80 | sb.append("(") |
---|
81 | .append(nodeType.toDisplayString()) |
---|
82 | .append(" "); |
---|
83 | if (minOccurs != 1) { |
---|
84 | sb.append("@min="); |
---|
85 | if (minOccurs == QueryNode.OCCURS_UNBOUNDED) { |
---|
86 | sb.append("*"); |
---|
87 | } else { |
---|
88 | sb.append(minOccurs); |
---|
89 | } |
---|
90 | sb.append(" "); |
---|
91 | } |
---|
92 | if (maxOccurs != 1) { |
---|
93 | sb.append("@max="); |
---|
94 | if (maxOccurs == QueryNode.OCCURS_UNBOUNDED) { |
---|
95 | sb.append("*"); |
---|
96 | } else { |
---|
97 | sb.append(maxOccurs); |
---|
98 | } |
---|
99 | sb.append(" "); |
---|
100 | |
---|
101 | } |
---|
102 | sb.append(children.get(0)); |
---|
103 | sb.append(")"); |
---|
104 | return sb.toString(); |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | @Override |
---|
109 | public void accept(QueryVisitor visitor) { |
---|
110 | if (!children.isEmpty()) { |
---|
111 | for (QueryNode child : children) { |
---|
112 | child.accept(visitor); |
---|
113 | } |
---|
114 | } |
---|
115 | visitor.visit(this); |
---|
116 | } |
---|
117 | |
---|
118 | } // class QueryGroup |
---|