1 12 package org.displaytag.properties; 13 14 import java.util.Iterator ; 15 16 import org.apache.commons.collections.iterators.ArrayIterator; 17 import org.apache.commons.lang.builder.HashCodeBuilder; 18 19 20 25 public final class SortOrderEnum 26 { 27 28 31 public static final SortOrderEnum DESCENDING = new SortOrderEnum(1, "descending"); 33 36 public static final SortOrderEnum ASCENDING = new SortOrderEnum(2, "ascending"); 38 41 static final SortOrderEnum[] ALL = {DESCENDING, ASCENDING}; 42 43 46 private final int enumCode; 47 48 51 private final String enumName; 52 53 58 private SortOrderEnum(int code, String name) 59 { 60 this.enumCode = code; 61 this.enumName = name; 62 } 63 64 68 public int getCode() 69 { 70 return this.enumCode; 71 } 72 73 77 public String getName() 78 { 79 return this.enumName; 80 } 81 82 87 public static SortOrderEnum fromCode(int key) 88 { 89 for (int i = 0; i < ALL.length; i++) 90 { 91 if (key == ALL[i].getCode()) 92 { 93 return ALL[i]; 94 } 95 } 96 return null; 98 } 99 100 105 public static SortOrderEnum fromCode(Integer key) 106 { 107 if (key == null) 108 { 109 return null; 110 } 111 112 return fromCode(key.intValue()); 113 } 114 115 121 public static SortOrderEnum fromIntegerCode(Integer key) 122 { 123 return fromCode(key); 124 } 125 126 131 public static SortOrderEnum fromName(String code) 132 { 133 for (int i = 0; i < ALL.length; i++) 134 { 135 if (ALL[i].getName().equals(code)) 136 { 137 return ALL[i]; 138 } 139 } 140 return null; 142 } 143 144 148 public static Iterator iterator() 149 { 150 return new ArrayIterator(ALL); 151 } 152 153 157 public String toString() 158 { 159 return getName(); 160 } 161 162 167 public boolean equals(Object o) 168 { 169 if (this == o) 170 { 171 return true; 172 } 173 174 return false; 175 } 176 177 180 public int hashCode() 181 { 182 return new HashCodeBuilder(1123997057, -1289836553).append(this.enumCode).toHashCode(); 183 } 184 185 } | Popular Tags |