Change obsolete collections, remove redundant imports
[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     public String toXCQL(int level, List<CQLPrefix> prefixes,
46                          List<ModifierSet> sortkeys) {
47         if (sortkeys != null)
48             throw new Error("CQLSortNode.toXCQL() called with sortkeys");
49         return subtree.toXCQL(level, prefixes, keys);
50     }
51
52     public String toCQL() {
53         StringBuffer buf = new StringBuffer(subtree.toCQL());
54
55         if (keys != null) {
56             buf.append(" sortby");
57             for (int i = 0; i < keys.size(); i++) {
58                 ModifierSet key = keys.get(i);
59                 buf.append(" " + key.toCQL());
60             }
61         }
62
63         return buf.toString();
64     }
65
66     public String toPQF(Properties config) throws PQFTranslationException {
67         return "@attr 1=oops \"###\"";
68     }
69
70     public byte[] toType1BER(Properties config)
71         throws PQFTranslationException {
72         // There is no way to represent sorting in a standard Z39.50
73         // Type-1 query, so the best we can do is return the
74         // underlying query and ignore the sort-specification.
75         return subtree.toType1BER(config);
76     }
77 }