FileDocCategorySizeDatePackage
MonthDay.javaAPI DocApache Axis 1.45873Sat Apr 22 18:57:28 BST 2006org.apache.axis.types

MonthDay

public class MonthDay extends Object implements Serializable
Implementation of the XML Schema type gMonthDay
author
Tom Jordahl
see
XML Schema 3.2.12

Fields Summary
int
month
int
day
String
timezone
Constructors Summary
public MonthDay(int month, int day)
Constructs a MonthDay with the given values No timezone is specified


                    
        
          
        setValue(month, day);
    
public MonthDay(int month, int day, String timezone)
Constructs a MonthDay with the given values, including a timezone string The timezone is validated but not used.

        setValue(month, day, timezone);
    
public MonthDay(String source)
Construct a MonthDay from a String in the format --MM-DD[timezone]

        if (source.length() < 6) {
            throw new NumberFormatException(
                    Messages.getMessage("badMonthDay00"));
        }

        if (source.charAt(0) != '-" ||
            source.charAt(1) != '-" ||
            source.charAt(4) != '-" ) {
            throw new NumberFormatException(
                    Messages.getMessage("badMonthDay00"));
        }

        setValue(Integer.parseInt(source.substring(2,4)),
                 Integer.parseInt(source.substring(5,7)),
                 source.substring(7));
    
Methods Summary
public booleanequals(java.lang.Object obj)

        if (!(obj instanceof MonthDay)) return false;
        MonthDay other = (MonthDay) obj;
        if (obj == null) return false;
        if (this == obj) return true;

        boolean equals = (this.month == other.month && this.day == other.day);
        if (timezone != null) {
            equals = equals && timezone.equals(other.timezone);
        }
        return equals;
    
public intgetDay()

        return day;
    
public intgetMonth()

        return month;
    
public java.lang.StringgetTimezone()

        return timezone;
    
public inthashCode()
Return the value of (month + day) XORed with the hashCode of timezone iff one is defined.

return
an int value

        return null == timezone
            ? (month + day)
            : (month + day) ^ timezone.hashCode();
    
public voidsetDay(int day)
Set the day NOTE: if the month isn't set yet, the day isn't validated

        // validate day
        if (day < 1 || day > 31) {
            throw new NumberFormatException(
                    Messages.getMessage("badMonthDay00"));
        }
        // 30 days has September... All the rest have 31 (except Feb!)
        // NOTE: if month isn't set, we don't validate day.
        if ((month == 2 && day > 29) ||
           ((month == 9 || month == 4 || month == 6 || month == 11) && day > 30)) {
            throw new NumberFormatException(
                    Messages.getMessage("badMonthDay00"));
        }
        this.day = day;
    
public voidsetMonth(int month)

        // validate month
        if (month < 1 || month > 12) {
            throw new NumberFormatException(
                    Messages.getMessage("badMonthDay00"));
        }
        this.month = month;
    
public voidsetTimezone(java.lang.String timezone)

        // validate timezone
        if (timezone != null && timezone.length() > 0) {
            // Format [+/-]HH:MM
            if (timezone.charAt(0)=='+" || (timezone.charAt(0)=='-")) {
                    if (timezone.length() != 6 ||
                        !Character.isDigit(timezone.charAt(1)) ||
                        !Character.isDigit(timezone.charAt(2)) ||
                        timezone.charAt(3) != ':"              ||
                        !Character.isDigit(timezone.charAt(4)) ||
                        !Character.isDigit(timezone.charAt(5)))
                        throw new NumberFormatException(
                                Messages.getMessage("badTimezone00"));

            } else if (!timezone.equals("Z")) {
                throw new NumberFormatException(
                        Messages.getMessage("badTimezone00"));
            }
            // if we got this far, its good
            this.timezone = timezone;
        }
    
public voidsetValue(int month, int day, java.lang.String timezone)

        setMonth(month);
        setDay(day);
        setTimezone(timezone);
    
public voidsetValue(int month, int day)

        setMonth(month);
        setDay(day);
    
public java.lang.StringtoString()

        // use NumberFormat to ensure leading zeros
        NumberFormat nf = NumberFormat.getInstance();
        nf.setGroupingUsed(false);

        // month & Day: --MM-DD
        nf.setMinimumIntegerDigits(2);
        String s = "--" + nf.format(month) + "-" + nf.format(day);

        // timezone
        if (timezone != null) {
            s = s + timezone;
        }
        return s;