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

YearMonth

public class YearMonth extends Object implements Serializable
Implementation of the XML Schema type gYearMonth
author
Tom Jordahl
see
XML Schema 3.2.10

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


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

        setValue(year, month, timezone);
    
public YearMonth(String source)
Construct a YearMonth from a String in the format [-]CCYY-MM

        int negative = 0;

        if (source.charAt(0) == '-") {
            negative = 1;
        }
        if (source.length() < (7 + negative)) {
            throw new NumberFormatException(
                    Messages.getMessage("badYearMonth00"));
        }

        // look for first '-'
        int pos = source.substring(negative).indexOf('-");
        if (pos < 0) {
            throw new NumberFormatException(
                    Messages.getMessage("badYearMonth00"));
        }
        if (negative > 0) pos++;    //adjust index for orginal string

        setValue(Integer.parseInt(source.substring(0,pos)),
                 Integer.parseInt(source.substring(pos+1,pos+3)),
                 source.substring(pos+3));
    
Methods Summary
public booleanequals(java.lang.Object obj)

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

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

        return month;
    
public java.lang.StringgetTimezone()

        return timezone;
    
public intgetYear()

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

return
an int value

        return null == timezone
            ? (month + year)
            : (month + year) ^ timezone.hashCode();
    
public voidsetMonth(int month)

        // validate month
        if (month < 1 || month > 12) {
            throw new NumberFormatException(
                    Messages.getMessage("badYearMonth00"));
        }
        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 year, int month, java.lang.String timezone)

        setYear(year);
        setMonth(month);
        setTimezone(timezone);
    
public voidsetValue(int year, int month)

        setYear(year);
        setMonth(month);
    
public voidsetYear(int year)

        // validate year, more than 4 digits are allowed!
        if (year == 0) {
            throw new NumberFormatException(
                    Messages.getMessage("badYearMonth00"));
        }

        this.year = year;
    
public java.lang.StringtoString()

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

        // year
        nf.setMinimumIntegerDigits(4);
        String s = nf.format(year) + "-";

        // month
        nf.setMinimumIntegerDigits(2);
        s += nf.format(month);

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