ristianNHenriksen.KotlinJson.1.0.source-code.JsonArray.kt Maven / Gradle / Ivy
/**
* Created by Christian on 17/09/2016.
*/
data class JsonArray(private val values: List): Collection {
val jsonValues: List
/**
* @param index The index to get the element form.
* @return The Json element at index. If index out of bounds an empty Json element is returned.
*/
operator fun get(index: Int): Json {
if (index >= jsonValues.size) return Json()
return jsonValues[index]
}
/**
* The size of the json array.
*/
override val size: Int
get() = values.size
init {
jsonValues = values.map { Json(it) }
}
/**
* @param element The element to look for.
* @return True if the element is contained in the json array.
*/
override fun contains(element: Json): Boolean = jsonValues.contains(element)
/**
* @param elements The elements to look for.
* @return True if all the elements are contained in the json array.
*/
override fun containsAll(elements: Collection): Boolean = jsonValues.containsAll(elements)
/**
* @return True if json array is empty.
*/
override fun isEmpty(): Boolean = jsonValues.isEmpty()
/**
* @return An iterator for the json array.
*/
override fun iterator(): Iterator = jsonValues.iterator()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy