📄 valuevalidator.java
字号:
if (i != 3 && end_index == -1)
return false;
else if (i == 3)
end_index = a_IpAddress.length();
String valueString = a_IpAddress.substring(start_index, end_index);
if (debug)
System.out.println(valueString);
if (ValueValidator.isNumeric(valueString) == false)
return false;
if (ValueValidator.rangeCheck(valueString, 0, 255) == false)
return false;
start_index = end_index + 1;
}
return true;
}
/** Check whether the argument value that represents a numeric number is
within a certain range or not. If the argument a_Value does not
represent a numeric number, returns false. If a_LowerLimit is greater
than the a_UpperLimit, also return false. **/
public static boolean rangeCheck(long a_Value, long a_LowerLimit, long a_UpperLimit)
{
if (a_LowerLimit > a_UpperLimit)
return false;
if (a_Value < a_LowerLimit || a_Value > a_UpperLimit)
return false;
return true;
}
/** Check whether the argument value that represents a numeric number is
within a certain range or not. If the argument a_Value does not
represent a numeric number, returns false. If a_LowerLimit is greater
than the a_UpperLimit, also return false. **/
public static boolean rangeCheck(String a_Value, double a_LowerLimit, double a_UpperLimit)
{
if (a_LowerLimit > a_UpperLimit)
return false;
if (ValueValidator.isDouble(a_Value) == false)
return false;;
double number = Double.parseDouble(a_Value);
if (number < a_LowerLimit || number > a_UpperLimit)
return false;
return true;
}
/** Check whether the argument value that represents a numeric number is
within a certain range or not. If the argument value does not
represent a numeric number, returns false. If a_LowerLimit is greater
than the a_UpperLimit, also return false. **/
public static boolean rangeCheck(String a_Value, long a_LowerLimit, long a_UpperLimit)
{
if (a_LowerLimit > a_UpperLimit)
return false;
if (ValueValidator.isNumeric(a_Value) == false)
return false;
long number = Long.parseLong(a_Value);
if (number < a_LowerLimit || number > a_UpperLimit)
return false;
return true;
}
/**
* Check whether the argument a_Value that represents a numeric value is larger
* than a_Limit or not. If a_Equal is true, it is checked for larger than or equal
* to a_Limit. If the argument a_Value does not represent a numeric
* value, returns false.
**/
public static boolean largerThan(String a_Value, long a_Limit, boolean a_Equal)
{
if (ValueValidator.isNumeric(a_Value) == false)
return false;
long number = Long.parseLong(a_Value);
if (a_Equal == true)
{
if (number >= a_Limit)
return true;
else return false;
}
else
{
if (number > a_Limit)
return true;
else return false;
}
}
/**
* Check whether the argument a_Value that represents a numeric value is larger
* than a_Limit or not. If a_Equal is true, it is checked for larger than or equal
* to a_Limit. If the argument a_Value does not represent a numeric
* value, returns false.
**/
public static boolean largerThan(String a_Value, int a_Limit, boolean a_Equal)
{
if (ValueValidator.isNumeric(a_Value) == false)
return false;
long number = Integer.parseInt(a_Value);
if (a_Equal == true)
{
if (number >= a_Limit)
return true;
else return false;
}
else
{
if (number > a_Limit)
return true;
else return false;
}
}
/**
* Check whether the argument a_Value that represents a double value is larger
* than a_Limit or not. If a_Equal is true, it is checked for larger than or equal
* to a_Limit. If the argument a_Value does not represent a double
* value, returns false.
**/
public static boolean largerThan(String a_Value, double a_Limit, boolean a_Equal)
{
if (ValueValidator.isDouble(a_Value) == false)
return false;
double number = Double.parseDouble(a_Value);
if (a_Equal == true)
{
if (number >= a_Limit)
return true;
else return false;
}
else
{
if (number > a_Limit)
return true;
else return false;
}
}
/**
* Check whether the argument a_Value that represents a numeric value is smaller
* than a_Limit or not. If a_Equal is true, it is checked for smaller than or equal
* to a_Limit. If the argument a_Value does not represent a numeric
* value, returns false.
**/
public static boolean smallerThan(String a_Value, long a_Limit, boolean a_Equal)
{
if (ValueValidator.isNumeric(a_Value) == false)
return false;
long number = Long.parseLong(a_Value);
if (a_Equal == true)
{
if (number <= a_Limit)
return true;
else return false;
}
else
{
if (number < a_Limit)
return true;
else return false;
}
}
/**
* Check whether the argument a_Value that represents a double value is smaller
* than a_Limit or not. If a_Equal is true, it is checked for smaller than or equal
* to a_Limit. If the argument a_Value does not represent a double
* value, returns false.
**/
public static boolean smallerThan(String a_Value, double a_Limit, boolean a_Equal)
{
if (ValueValidator.isDouble(a_Value) == false)
return false;
double number = Double.parseDouble(a_Value);
if (a_Equal == true)
{
if (number <= a_Limit)
return true;
else return false;
}
else
{
if (number < a_Limit)
return true;
else return false;
}
}
public static String escapeParam(Vector a_InputParams) throws NullPointerException{
String param = "";
for (int i=0; i<a_InputParams.size(); i++){
param += escapeParam((String)a_InputParams.get(i));
if(i<a_InputParams.size()-1)
param += ",";
}
return param;
}
public static String escapeParam(String a_InputParam){
String param = "";
if(a_InputParam==null || a_InputParam.trim().length()==0)
param = "";
else{
System.out.println(a_InputParam.indexOf(","));
System.out.println(a_InputParam.replaceAll(",", "\\\\,"));
param = a_InputParam.replaceAll(",", "\\\\,");
}
return param;
}
public static Vector<String> unescapeParam(String a_Param){
int fromIndex = 0;
int lastIndex = 0;
int index = 0;
int length = a_Param.length();
Vector<String> unescaped = new Vector<String>();
if(length>0){
while (fromIndex <=length){
index = a_Param.indexOf(',', fromIndex);
if(index ==-1){
unescaped.add(a_Param.substring(lastIndex, length).replaceAll("\\\\,", ",").trim());
break;
}
if(index>0 && a_Param.charAt(index-1)== '\\'){
fromIndex = index+1;
}
else{
unescaped.add(a_Param.substring(lastIndex, index).replaceAll("\\,", ","));
lastIndex = index +1;
fromIndex = index +1;
}
}
return unescaped;
}
else
return new Vector<String>(0);
}
public static boolean containSpecialChar(String a_String)
{
char[] chars = a_String.toCharArray();
for (int i=0;i<chars.length;i++)
{
if (chars[i]<48)
{
return true;
}
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -