Java Calendar Year getYearList(Calendar currDate)

Here you can find the source of getYearList(Calendar currDate)

Description

get Year List

License

Apache License

Declaration

public static ArrayList<LinkedHashMap<String, String>> getYearList(Calendar currDate) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.Calendar;

import java.util.LinkedHashMap;

public class Main {
    public static ArrayList<LinkedHashMap<String, String>> getYearList(Calendar currDate) {
        int prmBeforeCnt = 5;
        int prmAfterCnt = 5;
        return getYearList(currDate, prmBeforeCnt, prmAfterCnt);
    }/*  www .j  a  va  2s  .  c o m*/

    @SuppressWarnings("serial")
    public static ArrayList<LinkedHashMap<String, String>> getYearList(Calendar currDate, int prmBeforeCnt,
            int prmAfterCnt) {
        ArrayList<LinkedHashMap<String, String>> rtnYearList = new ArrayList<LinkedHashMap<String, String>>();
        Calendar startDate = (Calendar) currDate.clone();
        startDate.add(Calendar.YEAR, -1 * prmBeforeCnt);
        int startYear = startDate.get(Calendar.YEAR);

        Calendar endDate = (Calendar) currDate.clone();
        endDate.add(Calendar.YEAR, prmAfterCnt);
        int endYear = endDate.get(Calendar.YEAR);
        for (int i = startYear; i <= endYear; i++) {
            final String year = Integer.toString(i);
            rtnYearList.add(new LinkedHashMap<String, String>() {
                {
                    put("label", year);
                    put("value", year);
                }
            });
        }
        return rtnYearList;
    }

    public static String toString(Object stringObject) {
        return toString(stringObject, "");
    }

    public static String toString(Object stringObject, String value2) {
        if (stringObject != null) {
            return stringObject.toString();
        } else {
            return value2;
        }
    }
}

Related

  1. getYear(Calendar calendar)
  2. getYear(Calendar calendar)
  3. getYear(Calendar calendar)
  4. getYear(Date date, Calendar cal)
  5. getYearForWeek(final Calendar cal)
  6. isBeforeDay(Calendar date1, Calendar date2, boolean ignoreYear)
  7. isSameDay(Calendar date1, Calendar date2, boolean ignoreYear)
  8. isSameDayOfYear(Calendar calendar1, Calendar calendar2)
  9. isSameWeekOfYear(Calendar calendar1, Calendar calendar2)