Java Year Format isYear(String str, boolean nullCheck)

Here you can find the source of isYear(String str, boolean nullCheck)

Description

is Year

License

Apache License

Declaration

public static boolean isYear(String str, boolean nullCheck) 

Method Source Code

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

public class Main {
    public static boolean isYear(String str, boolean nullCheck) {
        if (nullCheck == false || isRequired(str)) {

            if (str == null) {
                return true;
            }/*w ww .jav a2s . co m*/

            if (isNumber(str, false)) {
                int year = Integer.parseInt(str.trim());

                if (year < 1500 && year > 2999) {
                    return false;
                }
            }
        } else {
            return false;
        }

        return true;
    }

    public static boolean isRequired(String str) {
        if (str == null || str.trim().length() == 0) {
            return false;
        }

        return true;
    }

    public static boolean isNumber(String str, boolean nullCheck) {
        if (nullCheck == false || isRequired(str)) {

            if (str == null) {
                return true;
            }

            try {
                Integer.parseInt(str.trim());
            } catch (NumberFormatException nfe) {
                return false;
            }
        } else {
            return false;
        }

        return true;
    }
}

Related

  1. getYYYYMMDDHHMMSS(Date date)
  2. getYyyyMMddWithoutDate()
  3. isPartialYear(String s, String yearFormat)
  4. isValidDateMMddyyyy(String theString)
  5. isYear(int y)
  6. isYearOnly(String input)
  7. isYYYY(String strDate)
  8. lastDayOfWeek(String year, int week, String format)
  9. stringYYYYmmDDhhMMssToDate(String value)