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

Year

public class Year extends Object implements Serializable
Implementation of the XML Schema type gYear
author
Tom Jordahl
see
XML Schema 3.2.11

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


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

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

        int negative = 0;

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

        // calculate how many more than 4 digits (if any) in the year
        int pos = 4 + negative;  // skip minus sign if present
        while (pos < source.length() && Character.isDigit(source.charAt(pos))) {
            ++pos;
        }

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

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

        boolean equals = (this.year == other.year);
        if (timezone != null) {
            equals = equals && timezone.equals(other.timezone);
        }
        return equals;
    
public java.lang.StringgetTimezone()

        return timezone;
    
public intgetYear()

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

return
an int value

        return null == timezone ? year : year ^ timezone.hashCode();
    
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, java.lang.String timezone)

        setYear(year);
        setTimezone(timezone);
    
public voidsetValue(int year)

        setYear(year);
    
public voidsetYear(int year)

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

        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);

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