1 16 package org.joda.time.field; 17 18 import java.io.Serializable ; 19 import java.util.HashMap ; 20 import org.joda.time.DurationField; 21 import org.joda.time.DurationFieldType; 22 23 31 public final class UnsupportedDurationField extends DurationField implements Serializable { 32 33 34 private static final long serialVersionUID = -6390301302770925357L; 35 36 37 private static HashMap cCache; 38 39 46 public static synchronized UnsupportedDurationField getInstance(DurationFieldType type) { 47 UnsupportedDurationField field; 48 if (cCache == null) { 49 cCache = new HashMap (7); 50 field = null; 51 } else { 52 field = (UnsupportedDurationField) cCache.get(type); 53 } 54 if (field == null) { 55 field = new UnsupportedDurationField(type); 56 cCache.put(type, field); 57 } 58 return field; 59 } 60 61 62 private final DurationFieldType iType; 63 64 69 private UnsupportedDurationField(DurationFieldType type) { 70 iType = type; 71 } 72 73 77 public final DurationFieldType getType() { 78 return iType; 79 } 80 81 public String getName() { 82 return iType.getName(); 83 } 84 85 90 public boolean isSupported() { 91 return false; 92 } 93 94 99 public boolean isPrecise() { 100 return true; 101 } 102 103 108 public int getValue(long duration) { 109 throw unsupported(); 110 } 111 112 117 public long getValueAsLong(long duration) { 118 throw unsupported(); 119 } 120 121 126 public int getValue(long duration, long instant) { 127 throw unsupported(); 128 } 129 130 135 public long getValueAsLong(long duration, long instant) { 136 throw unsupported(); 137 } 138 139 144 public long getMillis(int value) { 145 throw unsupported(); 146 } 147 148 153 public long getMillis(long value) { 154 throw unsupported(); 155 } 156 157 162 public long getMillis(int value, long instant) { 163 throw unsupported(); 164 } 165 166 171 public long getMillis(long value, long instant) { 172 throw unsupported(); 173 } 174 175 180 public long add(long instant, int value) { 181 throw unsupported(); 182 } 183 184 189 public long add(long instant, long value) { 190 throw unsupported(); 191 } 192 193 198 public int getDifference(long minuendInstant, long subtrahendInstant) { 199 throw unsupported(); 200 } 201 202 207 public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) { 208 throw unsupported(); 209 } 210 211 216 public long getUnitMillis() { 217 return 0; 218 } 219 220 225 public int compareTo(Object durationField) { 226 return 0; 227 } 228 229 236 public boolean equals(Object obj) { 237 if (this == obj) { 238 return true; 239 } else if (obj instanceof UnsupportedDurationField) { 240 UnsupportedDurationField other = (UnsupportedDurationField) obj; 241 if (other.getName() == null) { 242 return (getName() == null); 243 } 244 return (other.getName().equals(getName())); 245 } 246 return false; 247 } 248 249 254 public int hashCode() { 255 return getName().hashCode(); 256 } 257 258 263 public String toString() { 264 return "UnsupportedDurationField[" + getName() + ']'; 265 } 266 267 270 private Object readResolve() { 271 return getInstance(iType); 272 } 273 274 private UnsupportedOperationException unsupported() { 275 return new UnsupportedOperationException (iType + " field is unsupported"); 276 } 277 278 } 279 | Popular Tags |