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 Month implements java.io.Serializable { 29 int month; 30 String timezone = null; 31 32 36 public Month(int month) throws NumberFormatException { 37 setValue(month); 38 } 39 40 44 public Month(int month, String timezone) 45 throws NumberFormatException { 46 setValue(month, timezone); 47 } 48 49 52 public Month(String source) throws NumberFormatException { 53 if (source.length() < (6)) { 54 throw new NumberFormatException ( 55 Messages.getMessage("badMonth00")); 56 } 57 58 if (source.charAt(0) != '-' || 59 source.charAt(1) != '-' || 60 source.charAt(4) != '-' || 61 source.charAt(5) != '-' ) { 62 throw new NumberFormatException ( 63 Messages.getMessage("badMonth00")); 64 } 65 66 setValue(Integer.parseInt(source.substring(2,4)), 67 source.substring(6)); 68 } 69 70 public int getMonth() { 71 return month; 72 } 73 74 public void setMonth(int month) { 75 if (month < 1 || month > 12) { 77 throw new NumberFormatException ( 78 Messages.getMessage("badMonth00")); 79 } 80 this.month = month; 81 } 82 83 public String getTimezone() { 84 return timezone; 85 } 86 87 public void setTimezone(String timezone) { 88 if (timezone != null && timezone.length() > 0) { 90 if (timezone.charAt(0)=='+' || (timezone.charAt(0)=='-')) { 92 if (timezone.length() != 6 || 93 !Character.isDigit(timezone.charAt(1)) || 94 !Character.isDigit(timezone.charAt(2)) || 95 timezone.charAt(3) != ':' || 96 !Character.isDigit(timezone.charAt(4)) || 97 !Character.isDigit(timezone.charAt(5))) 98 throw new NumberFormatException ( 99 Messages.getMessage("badTimezone00")); 100 101 } else if (!timezone.equals("Z")) { 102 throw new NumberFormatException ( 103 Messages.getMessage("badTimezone00")); 104 } 105 this.timezone = timezone; 107 } 108 } 109 110 public void setValue(int month, String timezone) throws NumberFormatException { 111 setMonth(month); 112 setTimezone(timezone); 113 } 114 115 public void setValue(int month) throws NumberFormatException { 116 setMonth(month); 117 } 118 119 public String toString() { 120 NumberFormat nf = NumberFormat.getInstance(); 122 nf.setGroupingUsed(false); 123 124 nf.setMinimumIntegerDigits(2); 126 String s = "--" + nf.format(month) + "--"; 127 128 if (timezone != null) { 130 s = s + timezone; 131 } 132 return s; 133 } 134 135 public boolean equals(Object obj) { 136 if (!(obj instanceof Month)) return false; 137 Month other = (Month) obj; 138 if (obj == null) return false; 139 if (this == obj) return true; 140 141 boolean equals = (this.month == other.month); 142 if (timezone != null) { 143 equals = equals && timezone.equals(other.timezone); 144 } 145 return equals; 146 } 147 148 154 public int hashCode() { 155 return null == timezone ? month : month ^ timezone.hashCode(); 156 } 157 } 158 | Popular Tags |