Add override annotations
[cql-java-moved-to-github.git] / src / main / java / org / z3950 / zing / cql / CQLSortNode.java
1 // $Id: CQLSortNode.java,v 1.2 2008-04-11 12:05:15 mike Exp $
2
3 package org.z3950.zing.cql;
4 import java.util.ArrayList;
5 import java.util.List;
6 import java.util.Properties;
7
8
9 /**
10  * Represents a sort node in a CQL parse-tree.
11  *
12  * @version     $Id: CQLSortNode.java,v 1.2 2008-04-11 12:05:15 mike Exp $
13  */
14 public class CQLSortNode extends CQLNode {
15     /**
16      * The root of a subtree representing the query whose result is to
17      * be sorted.
18      */ 
19     private CQLNode subtree;
20
21     /**
22      * The set of sort keys by which results are to be sorted,
23      * each expressed as an index together with zero or more
24      * modifiers.
25      */ 
26     List<ModifierSet> keys;
27
28     public CQLNode getSubtree() {
29         return subtree;
30     }
31
32     public CQLSortNode(CQLNode subtree) {
33         this.subtree = subtree;
34         keys = new ArrayList<ModifierSet>();
35     }
36
37     public void addSortIndex(ModifierSet key) {
38         keys.add(key);
39     }
40
41     public List<ModifierSet> getSortIndexes() {
42         return keys;
43     }
44
45     @Override
46     public String toXCQL(int level, List<CQLPrefix> prefixes,
47                          List<ModifierSet> sortkeys) {
48         if (sortkeys != null)
49             throw new Error("CQLSortNode.toXCQL() called with sortkeys");
50         return subtree.toXCQL(level, prefixes, keys);
51     }
52
53     @Override
54     public String toCQL() {
55         StringBuffer buf = new StringBuffer(subtree.toCQL());
56
57         if (keys != null) {
58             buf.append(" sortby");
59             for (int i = 0; i < keys.size(); i++) {
60                 ModifierSet key = keys.get(i);
61                 buf.append(" " + key.toCQL());
62             }
63         }
64
65         return buf.toString();
66     }
67
68     @Override
69     public String toPQF(Properties config) throws PQFTranslationException {
70         return "@attr 1=oops \"###\"";
71     }
72
73     @Override
74     public byte[] toType1BER(Properties config)
75         throws PQFTranslationException {
76         // There is no way to represent sorting in a standard Z39.50
77         // Type-1 query, so the best we can do is return the
78         // underlying query and ignore the sort-specification.
79         return subtree.toType1BER(config);
80     }
81 }