1 16 package org.apache.axis.types; 17 18 import org.apache.axis.utils.Messages; 19 20 import java.text.NumberFormat ; 21 22 28 public class Day implements java.io.Serializable { 29 int day; 30 String timezone = null; 31 32 36 public Day(int day) throws NumberFormatException { 37 setValue(day); 38 } 39 40 44 public Day(int day, String timezone) 45 throws NumberFormatException { 46 setValue(day, timezone); 47 } 48 49 52 public Day(String source) throws NumberFormatException { 53 if (source.length() < 5) { 54 throw new NumberFormatException ( 55 Messages.getMessage("badDay00")); 56 } 57 58 if (source.charAt(0) != '-' || 59 source.charAt(1) != '-' || 60 source.charAt(2) != '-' ) { 61 throw new NumberFormatException ( 62 Messages.getMessage("badDay00")); 63 } 64 65 setValue(Integer.parseInt(source.substring(3,5)), 66 source.substring(5)); 67 } 68 69 public int getDay() { 70 return day; 71 } 72 73 76 public void setDay(int day) { 77 if (day < 1 || day > 31) { 79 throw new NumberFormatException ( 80 Messages.getMessage("badDay00")); 81 } 82 this.day = day; 83 } 84 85 public String getTimezone() { 86 return timezone; 87 } 88 89 public void setTimezone(String timezone) { 90 if (timezone != null && timezone.length() > 0) { 92 if (timezone.charAt(0)=='+' || (timezone.charAt(0)=='-')) { 94 if (timezone.length() != 6 || 95 !Character.isDigit(timezone.charAt(1)) || 96 !Character.isDigit(timezone.charAt(2)) || 97 timezone.charAt(3) != ':' || 98 !Character.isDigit(timezone.charAt(4)) || 99 !Character.isDigit(timezone.charAt(5))) 100 throw new NumberFormatException ( 101 Messages.getMessage("badTimezone00")); 102 103 } else if (!timezone.equals("Z")) { 104 throw new NumberFormatException ( 105 Messages.getMessage("badTimezone00")); 106 } 107 this.timezone = timezone; 109 } 110 } 111 112 public void setValue(int day, String timezone) 113 throws NumberFormatException { 114 setDay(day); 115 setTimezone(timezone); 116 } 117 118 public void setValue(int day) throws NumberFormatException { 119 setDay(day); 120 } 121 122 public String toString() { 123 NumberFormat nf = NumberFormat.getInstance(); 125 nf.setGroupingUsed(false); 126 127 nf.setMinimumIntegerDigits(2); 129 String s = "---" + nf.format(day); 130 131 if (timezone != null) { 133 s = s + timezone; 134 } 135 return s; 136 } 137 138 public boolean equals(Object obj) { 139 if (!(obj instanceof Day)) return false; 140 Day other = (Day) obj; 141 if (obj == null) return false; 142 if (this == obj) return true; 143 144 boolean equals = (this.day == other.day); 145 if (timezone != null) { 146 equals = equals && timezone.equals(other.timezone); 147 } 148 return equals; 149 } 150 151 157 public int hashCode() { 158 return null == timezone ? day : day ^ timezone.hashCode(); 159 } 160 } 161 | Popular Tags |