1 16 17 package org.springframework.beans.support; 18 19 import java.io.Serializable ; 20 21 import org.springframework.util.StringUtils; 22 23 32 public class MutableSortDefinition implements SortDefinition, Serializable { 33 34 private String property = ""; 35 36 private boolean ignoreCase = true; 37 38 private boolean ascending = true; 39 40 private boolean toggleAscendingOnProperty = false; 41 42 43 50 public MutableSortDefinition() { 51 } 52 53 58 public MutableSortDefinition(SortDefinition source) { 59 this.property = source.getProperty(); 60 this.ignoreCase = source.isIgnoreCase(); 61 this.ascending = source.isAscending(); 62 } 63 64 70 public MutableSortDefinition(String property, boolean ignoreCase, boolean ascending) { 71 this.property = property; 72 this.ignoreCase = ignoreCase; 73 this.ascending = ascending; 74 } 75 76 82 public MutableSortDefinition(boolean toggleAscendingOnSameProperty) { 83 this.toggleAscendingOnProperty = toggleAscendingOnSameProperty; 84 } 85 86 87 93 public void setProperty(String property) { 94 if (!StringUtils.hasLength(property)) { 95 this.property = ""; 96 } 97 else { 98 if (isToggleAscendingOnProperty()) { 100 this.ascending = (!property.equals(this.property) || !this.ascending); 101 } 102 this.property = property; 103 } 104 } 105 106 public String getProperty() { 107 return this.property; 108 } 109 110 113 public void setIgnoreCase(boolean ignoreCase) { 114 this.ignoreCase = ignoreCase; 115 } 116 117 public boolean isIgnoreCase() { 118 return this.ignoreCase; 119 } 120 121 124 public void setAscending(boolean ascending) { 125 this.ascending = ascending; 126 } 127 128 public boolean isAscending() { 129 return this.ascending; 130 } 131 132 139 public void setToggleAscendingOnProperty(boolean toggleAscendingOnProperty) { 140 this.toggleAscendingOnProperty = toggleAscendingOnProperty; 141 } 142 143 147 public boolean isToggleAscendingOnProperty() { 148 return this.toggleAscendingOnProperty; 149 } 150 151 152 public boolean equals(Object other) { 153 if (this == other) { 154 return true; 155 } 156 if (!(other instanceof SortDefinition)) { 157 return false; 158 } 159 SortDefinition otherSd = (SortDefinition) other; 160 return (getProperty().equals(otherSd.getProperty()) && 161 isAscending() == otherSd.isAscending() && isIgnoreCase() == otherSd.isIgnoreCase()); 162 } 163 164 public int hashCode() { 165 int hashCode = getProperty().hashCode(); 166 hashCode = 29 * hashCode + (isIgnoreCase() ? 1 : 0); 167 hashCode = 29 * hashCode + (isAscending() ? 1 : 0); 168 return hashCode; 169 } 170 171 } 172 | Popular Tags |