Cisco Cisco Prime Home 6.5 개발자 가이드
Cisco Prime Home – Integration Guide
OL-28557-01 v5.0.1
37
* gets a value from the 'fields' object
*
* @param field the field name
* @return the string value of the field specified by the key,
*
* @param field the field name
* @return the string value of the field specified by the key,
or null
*/
def getString(key: String): String = {
def getString(key: String): String = {
json.getOrUpdateJSONObject("fields", new
JSONObject).optString(key)
}
/**
* gets a value from the 'fields' object
*
* @param field the field name
* @return the long value of the field specified by the key,
or null
*/
def getLong(key: String): Long = {
/**
* gets a value from the 'fields' object
*
* @param field the field name
* @return the long value of the field specified by the key,
or null
*/
def getLong(key: String): Long = {
json.getOrUpdateJSONObject("fields", new
JSONObject).optLong(key)
}
}
class SearchResults(val json: JSONArray) extends JSONHelpers with
Traversable[SearchResult] {
class SearchResults(val json: JSONArray) extends JSONHelpers with
Traversable[SearchResult] {
/**
* @return the underlying json array
*/
* @return the underlying json array
*/
def getJSON(): JSONArray = json
/**
/**
* @return the number of items in the result set. this does not
account for pagination!
*/
def resultCount(): Int = json.length
/**
/**
* searches the result set for results matching the given key
and value
*
* @param key the field to query
* @param value the value of the field to check
*
* @return a collection of matching SearchResults
*/
* @param key the field to query
* @param value the value of the field to check
*
* @return a collection of matching SearchResults
*/
def findResultByFieldValue(key: String, value: String):
java.util.Collection[SearchResult] = {
java.util.Collection[SearchResult] = {
val found = new java.util.LinkedList[SearchResult]
for (i <- 0 until json.length) {
for (i <- 0 until json.length) {
val result = new SearchResult(json.getJSONObject(i))
if (result.getString(key) == value)
found.add(result)
if (result.getString(key) == value)
found.add(result)
}
return found
return found
}
/**
* @return the first result, wrapped in a SearchResult. handy
for unique queries
*/
def first(): SearchResult = {
/**
* @return the first result, wrapped in a SearchResult. handy
for unique queries
*/
def first(): SearchResult = {
new SearchResult(json.getJSONObject(0))
}
def foreach[U](f: (SearchResult) => U): Unit = {
def foreach[U](f: (SearchResult) => U): Unit = {
val results = json.toJSONObjectList().map(j => new
SearchResult(j))