Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: nectar/data/OrderByPostElement.java


1   /*
2        Copyright (C) 2003  Kai Schutte
3    
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8    
9       This program is distributed in the hope that it will be useful,
10      but WITHOUT ANY WARRANTY; without even the implied warranty of
11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12      GNU General Public License for more details.
13   
14      You should have received a copy of the GNU General Public License
15      along with this program; if not, write to the Free Software
16      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   
18   * OrderByPostElement.java
19   *
20   * Created on March 31, 2003, 7:32 PM
21   */
22  
23  package nectar.data;
24  
25  import java.util.List;
26  import java.util.LinkedList;
27  import java.util.Iterator;
28  
29  /**
30   *  Analogous to the SQL "order by field_name [asc|desc]" clause. You can append several sorting fields by using the append method.
31   *
32   * @author  Kai Schutte skander@skander.com
33   */
34  public class OrderByPostElement implements PostElement {
35      /** Ascending order direction. */    
36      public static final byte ASC = 1;
37      /** Descending order direction. */    
38      public static final byte DESC = 2;
39      List list = new LinkedList();
40  
41      /** Creates an empty OrderByPostElement */
42      public OrderByPostElement() {}
43      
44      /** Creates an OrderByPostElement with the given FieldElement sorted in ASCending direction.
45       * @param fe The FieldElement to sort the results around.
46       */
47      public OrderByPostElement(FieldElement fe) {
48          append(fe);
49      }
50  
51      /** Creates an OrderByPostElement with the given FieldElement sorted in the given direction.
52       * @param sort the sorting direction
53       * @param fe the FieldElement to sort results around.
54       */
55      public OrderByPostElement(byte sort, FieldElement fe) {
56          append(sort, fe);
57      }
58  
59      /** creates an identical copies of this instance.
60       * @return the copy of this instance.
61       */    
62      public Object clone() {
63          OrderByPostElement clone = new OrderByPostElement();
64          for (Iterator i=list.iterator(); i.hasNext();) {
65              clone.append( (OrderByElm) ((OrderByElm)i.next()).clone());
66          }
67          return clone;
68      }
69      
70      /** creates and returns an iterator to the internal list of {@link OrderByElm} objects.
71       * @return the iterator to the internal list of data elements.
72       */    
73      public Iterator getListIterator() {
74          return list.iterator();
75      }
76  
77      /** does this object define any fieldElements for sorting?
78       * @return true if this object contains any fieldElement to sort by.
79       */    
80      public boolean isEmpty() {
81          return list.isEmpty();
82      }
83      
84      /** append a field to sort by.
85       * @param sorting sorting direction
86       *
87       * @param fe field to sort by.
88       */    
89      public void append(byte sorting, FieldElement fe) {
90          list.add(new OrderByElm(fe, sorting));
91      }
92  
93      /** append a field to sort by.
94       * @param fe the field to sort by.
95       *
96       */    
97      public void append(FieldElement fe) {
98          append(ASC, fe);
99      }
100     
101     /** append a field to sort by.
102      * @param e element to append.
103      */    
104     public void append(OrderByElm e) {
105         list.add(e);
106     }
107     
108     /** Internal data element defining the order by element. */    
109     public class OrderByElm {
110         public OrderByElm(FieldElement fe, byte sort) {
111             this.fe = fe;
112             this.sortDirection = sort;
113         }
114             
115         public FieldElement fe;
116         public byte sortDirection;
117         public Object clone() { return new OrderByElm( (FieldElement)fe.clone(), sortDirection); }
118     }
119 }