- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
public static boolean checkInt(String value, SocketMessage message,
int min, int max, boolean isNullCheck, Settings settings) {
if (value == null) {
if (!isNullCheck)
return true;
if (message != null && settings != null)
message.addSubMessage(ErrorSubElement.createErrorSubMessage(
ErrorSubElement.INVALID_ARGUMENT, "Invalid Int value",
settings));
return false;
}
if (value.length() > 9) {
if (message != null && settings != null)
message.addSubMessage(ErrorSubElement.createErrorSubMessage(
ErrorSubElement.INVALID_ARGUMENT, "Invalid Int value: "
+ value, settings));
return false;
}
try {
int val = Integer.parseInt(value);
MyLog.d(LOG_TAG, "Check Val:" + val);
if (val < min) {
if (message != null && settings != null)
message.addSubMessage(ErrorSubElement
.createErrorSubMessage(
ErrorSubElement.INVALID_ARGUMENT,
"Invalid Int value: " + value
+ " lower than " + min, settings));
return false;
}
if (val > max) {
if (message != null && settings != null)
message.addSubMessage(ErrorSubElement
.createErrorSubMessage(
ErrorSubElement.INVALID_ARGUMENT,
"Invalid Int value: " + value
+ " bigger than " + max, settings));
return false;
}
return true;
} catch (NumberFormatException e) {
if (message != null && settings != null)
message.addSubMessage(ErrorSubElement.createErrorSubMessage(
ErrorSubElement.INVALID_ARGUMENT, "Invalid Int value: "
+ value, settings));
return false;
}
}
roman-kashitsyn 10.08.2011 11:11 # +3