kr.debop4j.timeperiod.timerange.YearRangeCollection.java Source code

Java tutorial

Introduction

Here is the source code for kr.debop4j.timeperiod.timerange.YearRangeCollection.java

Source

/*
 * Copyright 2011-2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package kr.debop4j.timeperiod.timerange;

import com.google.common.collect.Lists;
import kr.debop4j.timeperiod.ITimeCalendar;
import kr.debop4j.timeperiod.TimeCalendar;
import kr.debop4j.timeperiod.tools.Times;
import org.joda.time.DateTime;

import java.util.List;

/**
 * (Year)? ? ? .
 *
 * @author ? sunghyouk.bae@gmail.com
 * @since 13. 5. 14.  12:02
 */
public class YearRangeCollection extends YearTimeRange {

    private static final long serialVersionUID = 6717411713272815855L;

    /**
     * Instantiates a new Year range collection.
     *
     * @param moment    the moment
     * @param yearCount the year count
     */
    public YearRangeCollection(DateTime moment, int yearCount) {
        this(moment, yearCount, TimeCalendar.getDefault());
    }

    /**
     * Instantiates a new Year range collection.
     *
     * @param moment    the moment
     * @param yearCount the year count
     * @param calendar  the calendar
     */
    public YearRangeCollection(DateTime moment, int yearCount, ITimeCalendar calendar) {
        this(Times.getYearOf(moment, calendar), yearCount, calendar);
    }

    /**
     * Instantiates a new Year range collection.
     *
     * @param year      the year
     * @param yearCount the year count
     */
    public YearRangeCollection(int year, int yearCount) {
        this(year, yearCount, TimeCalendar.getDefault());
    }

    /**
     * Instantiates a new Year range collection.
     *
     * @param year      the year
     * @param yearCount the year count
     * @param calendar  the calendar
     */
    public YearRangeCollection(int year, int yearCount, ITimeCalendar calendar) {
        super(year, yearCount, calendar);
    }

    /** Year ? ? . */
    public List<YearRange> getYears() {
        int start = getStartYear();

        List<YearRange> years = Lists.newArrayListWithCapacity(getYearCount());
        for (int y = 0; y < getYearCount(); y++)
            years.add(new YearRange(start + y, getTimeCalendar()));

        return years;
    }
}