001    /**
002     * Copyright 2007 Mike Kroutikov.
003     *
004     * This program is free software; you can redistribute it and/or modify
005     *   it under the terms of the Lesser GNU General Public License as 
006     *   published by the Free Software Foundation; either version 3 of
007     *   the License, or (at your option) any later version.
008     *
009     *   This program is distributed in the hope that it will be useful,
010     *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011     *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     *   Lesser GNU General Public License for more details.
013     *
014     *   You should have received a copy of the Lesser GNU General Public License
015     *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
016     */
017    
018    package org.otfeed.command;
019    
020    import java.io.Serializable;
021    
022    /**
023     * Composite, encapsulating month and year values.
024     * It is used to specify option expiration date.
025     * <p/>
026     * This class is immutable.
027     */
028    public final class MonthAndYear implements Serializable {
029            private static final long serialVersionUID = -2007014191489778814L;
030    
031            /**
032             * Month.
033             * Jan = 1, Feb = 2, ... Dec = 12.
034             */
035            public final int month;
036    
037            /**
038             * Year.
039             */
040            public final int year;
041    
042            /**
043             * Constructor of the composite object.
044             */
045            public MonthAndYear(int month, int year) {
046    
047                    this.month = month;
048                    this.year = year;
049    
050                    if(month < 1 || month > 12) {
051                            throw new IllegalArgumentException(
052                                    "invalid month value: " + month);
053                    }
054    
055                    if(year <= 0) {
056                            throw new IllegalArgumentException(
057                                    "invalid year value: " + year);
058                    }
059            }
060    
061            @Override
062            public String toString() {
063                    return "MonthAndYear: month=" + month + ", year=" + year;
064            }
065    }