Skip to content

Instantly share code, notes, and snippets.

@swapnil-kotwal-sp
Last active August 29, 2015 14:14
Show Gist options
  • Save swapnil-kotwal-sp/8bec8b6c73283f048be5 to your computer and use it in GitHub Desktop.
Save swapnil-kotwal-sp/8bec8b6c73283f048be5 to your computer and use it in GitHub Desktop.
Code Snippets for conditions check
if ((parserFailureConditions != null)
&& (parserFailureConditions.length != 0)) {
numberOfParserFailureConditions = getNumberOfFailureConditions(parserFailureConditions[0]);
}
/*
* As the the passed array holds JSON String at first location,
* this method initialize the 'number_failureConditions' based on no. of JSON elements.
*/
public int getNumberOfFailureConditions(String condition) {
int number_failureConditions = 0;
if ((condition != null) && (condition.startsWith("["))) {
try {
JSONArray temp_object_array = new JSONArray(condition);
for (int i = 0; i < temp_object_array.length(); i++) {
number_failureConditions++;
}
} catch (JSONException ex) {
System.out.println("Could not create JSONArray");
}
} else if ((condition != null) && (condition.startsWith("{"))) {
for (@SuppressWarnings("unused")
String retval : condition.split("}")) {
if (number_failureConditions < 50) {
number_failureConditions++;
}
}
} else {
if (condition != null) {
System.out.println("Invalid condition");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment