1 55 package org.jboss.axis.types; 56 57 import org.jboss.axis.utils.Messages; 58 59 import java.text.NumberFormat ; 60 61 67 public class Day 68 { 69 int day; 70 String timezone = null; 71 72 76 public Day(int day) throws NumberFormatException 77 { 78 setValue(day); 79 } 80 81 85 public Day(int day, String timezone) 86 throws NumberFormatException 87 { 88 setValue(day, timezone); 89 } 90 91 94 public Day(String source) throws NumberFormatException 95 { 96 if (source.length() < 5) 97 { 98 throw new NumberFormatException (Messages.getMessage("badDay00")); 99 } 100 101 if (source.charAt(0) != '-' || 102 source.charAt(1) != '-' || 103 source.charAt(2) != '-') 104 { 105 throw new NumberFormatException (Messages.getMessage("badDay00")); 106 } 107 108 setValue(Integer.parseInt(source.substring(3, 5)), 109 source.substring(5)); 110 } 111 112 public int getDay() 113 { 114 return day; 115 } 116 117 120 public void setDay(int day) 121 { 122 if (day < 1 || day > 31) 124 { 125 throw new NumberFormatException (Messages.getMessage("badDay00")); 126 } 127 this.day = day; 128 } 129 130 public String getTimezone() 131 { 132 return timezone; 133 } 134 135 public void setTimezone(String timezone) 136 { 137 if (timezone != null && timezone.length() > 0) 139 { 140 if (timezone.charAt(0) == '+' || (timezone.charAt(0) == '-')) 142 { 143 if (timezone.length() != 6 || 144 !Character.isDigit(timezone.charAt(1)) || 145 !Character.isDigit(timezone.charAt(2)) || 146 timezone.charAt(3) != ':' || 147 !Character.isDigit(timezone.charAt(4)) || 148 !Character.isDigit(timezone.charAt(5))) 149 throw new NumberFormatException (Messages.getMessage("badTimezone00")); 150 151 } 152 else if (!timezone.equals("Z")) 153 { 154 throw new NumberFormatException (Messages.getMessage("badTimezone00")); 155 } 156 this.timezone = timezone; 158 } 159 } 160 161 public void setValue(int day, String timezone) 162 throws NumberFormatException 163 { 164 setDay(day); 165 setTimezone(timezone); 166 } 167 168 public void setValue(int day) throws NumberFormatException 169 { 170 setDay(day); 171 } 172 173 public String toString() 174 { 175 NumberFormat nf = NumberFormat.getInstance(); 177 nf.setGroupingUsed(false); 178 179 nf.setMinimumIntegerDigits(2); 181 String s = "---" + nf.format(day); 182 183 if (timezone != null) 185 { 186 s = s + timezone; 187 } 188 return s; 189 } 190 191 public boolean equals(Object obj) 192 { 193 if (!(obj instanceof Day)) return false; 194 Day other = (Day)obj; 195 if (obj == null) return false; 196 if (this == obj) return true; 197 198 boolean equals = (this.day == other.day); 199 if (timezone != null) 200 { 201 equals = equals && timezone.equals(other.timezone); 202 } 203 return equals; 204 } 205 } 206 | Popular Tags |