1 10 package org.mmbase.storage.search.implementation; 11 12 import org.mmbase.storage.search.*; 13 14 21 public class BasicSortOrder implements SortOrder { 22 23 24 private StepField field = null; 25 26 27 private int direction = SortOrder.ORDER_ASCENDING; 28 29 private boolean caseSensitive = true; 30 31 39 public BasicSortOrder(StepField field) { 40 if (field == null) { 41 throw new IllegalArgumentException ("Invalid field value: " + field); 42 } 43 this.field = field; 44 } 45 46 53 public BasicSortOrder setDirection(int direction) { 54 if (direction != SortOrder.ORDER_ASCENDING 55 && direction != SortOrder.ORDER_DESCENDING) { 56 throw new IllegalArgumentException ("Invalid direction value: " + direction); 57 } 58 this.direction = direction; 59 return this; 60 } 61 62 public StepField getField() { 64 return field; 65 } 66 67 public int getDirection() { 69 return direction; 70 } 71 72 75 public String getDirectionDescription() { 76 try { 77 return SortOrder.ORDER_DESCRIPTIONS[direction]; 78 } catch (IndexOutOfBoundsException ioobe) { 79 return null; 80 } 81 } 82 83 public boolean isCaseSensitive() { 84 return caseSensitive; 85 } 86 89 public BasicSortOrder setCaseSensitive(boolean c) { 90 caseSensitive = c; 91 return this; 92 } 93 94 public boolean equals(Object 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 public int hashCode() { 111 String 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 public String toString() { 119 return "SortOrder(field:" + BasicStepField.getFieldName(getField()) + ", dir:" + getDirectionDescription() + ")"; 120 } 121 122 } 123 | Popular Tags |