KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > storage > search > implementation > BasicSortOrder


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.storage.search.implementation;
11
12 import org.mmbase.storage.search.*;
13
14 /**
15  * Basic implementation.
16  *
17  * @author Rob van Maris
18  * @version $Id: BasicSortOrder.java,v 1.8 2005/05/26 07:51:48 michiel Exp $
19  * @since MMBase-1.7
20  */

21 public class BasicSortOrder implements SortOrder {
22
23     /** Associated stepfield. */
24     private StepField field = null;
25
26     /** Direction property. */
27     private int direction = SortOrder.ORDER_ASCENDING;
28
29     private boolean caseSensitive = true;
30
31     /**
32      * Constructor.
33      * Creates new BasicSortOrder instance, with
34      * direction <code>SortOrder.ORDER_ASCENDING</code>.
35      *
36      * @param field The associated stepfield.
37      * @throws IllegalArgumentException when an invalid argument is supplied.
38      */

39     public BasicSortOrder(StepField field) {
40         if (field == null) {
41             throw new IllegalArgumentException JavaDoc("Invalid field value: " + field);
42         }
43         this.field = field;
44     }
45
46     /**
47      * Sets direction.
48      *
49      * @param direction The direction.
50      * @return This <code>BasicSortOrder</code> instance.
51      * @throws IllegalArgumentException when an invalid argument is supplied.
52      */

53     public BasicSortOrder setDirection(int direction) {
54         if (direction != SortOrder.ORDER_ASCENDING
55             && direction != SortOrder.ORDER_DESCENDING) {
56             throw new IllegalArgumentException JavaDoc("Invalid direction value: " + direction);
57         }
58         this.direction = direction;
59         return this;
60     }
61
62     // javadoc is inherited
63
public StepField getField() {
64         return field;
65     }
66
67     // javadoc is inherited
68
public int getDirection() {
69         return direction;
70     }
71
72     /**
73      * Returns a description of the direction of the sort order
74      */

75     public String JavaDoc getDirectionDescription() {
76         try {
77             return SortOrder.ORDER_DESCRIPTIONS[direction];
78         } catch (IndexOutOfBoundsException JavaDoc ioobe) {
79             return null;
80         }
81     }
82
83     public boolean isCaseSensitive() {
84         return caseSensitive;
85     }
86     /**
87      * @since MMBase-1.8
88      */

89     public BasicSortOrder setCaseSensitive(boolean c) {
90         caseSensitive = c;
91         return this;
92     }
93
94     // javadoc is inherited
95
public boolean equals(Object JavaDoc obj) {
96         if (obj instanceof SortOrder) {
97             SortOrder order = (SortOrder) obj;
98             return
99                 field.getFieldName().equals(order.getField().getFieldName())
100                 && BasicStepField.compareSteps(field.getStep(), order.getField().getStep())
101                 && direction == order.getDirection()
102                 && caseSensitive == order.isCaseSensitive()
103                 ;
104         } else {
105             return false;
106         }
107     }
108
109     // javadoc is inherited
110
public int hashCode() {
111         String JavaDoc alias = field.getStep().getAlias();
112         return
113             61 * field.getFieldName().hashCode()
114             + 67 * (alias != null ? alias.hashCode() : 1) + 103 * direction + (caseSensitive ? 13 : 0);
115     }
116
117     // javadoc is inherited
118
public String JavaDoc toString() {
119         return "SortOrder(field:" + BasicStepField.getFieldName(getField()) + ", dir:" + getDirectionDescription() + ")";
120     }
121
122 }
123
Popular Tags