Java Regex Int Validate parseInteger(String inStr, Integer def)

Here you can find the source of parseInteger(String inStr, Integer def)

Description

parse Integer

License

Apache License

Declaration

public static Integer parseInteger(String inStr, Integer def) 

Method Source Code

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

import java.util.regex.Pattern;

public class Main {
    public static final String EMPTY = "";

    public static Integer parseInteger(String inStr, Integer def) {
        if (isEmpty(inStr) || !isNumeric(inStr)) {
            return def;
        } else {/*from   w ww . j  av  a2 s.c o  m*/
            return Integer.valueOf(inStr);
        }
    }

    public static Integer parseInteger(Object obj, Integer def) {
        return parseInteger(String.valueOf(obj), def);
    }

    public static boolean isEmpty(String inStr) {
        if (null == inStr || EMPTY.equals(inStr.trim())) {
            return true;
        }
        return false;
    }

    public static boolean isNumeric(String inStr) {
        if (null == inStr || EMPTY.equals(inStr.trim())) {
            return false;
        }
        Pattern pattern = Pattern.compile("[0-9]*");
        return pattern.matcher(inStr).matches();
    }

    public static boolean equals(CharSequence cs1, CharSequence cs2) {
        return cs1 == null ? cs2 == null : cs1.equals(cs2);
    }
}

Related

  1. parseInt(Object str)
  2. parseInt(String value)
  3. parseInt(String[] strs)
  4. parseInteger(String attrVal)
  5. parseInteger(String key, String sourceString)
  6. parseInteger(String str)
  7. parseIntegerList(String var0, int var1, int var2)
  8. parseIntegers(String integerString)