<commit_before>package edu.csh.chase.sprint.json

import java.io.IOException
import java.io.StringWriter
import java.io.Writer
import java.util.*

class JsonArray() : JsonBase() {


    private val array = ArrayList<Any?>()

    override val size: Int
        get() {
            return array.size()
        }

    constructor(tokener: JsonTokener) : this() {
        if (tokener.nextClean() != '[') {
            throw tokener.syntaxError("A JSONArray text must start with '['")
        }
        if (tokener.nextClean() != ']') {
            tokener.back()
            while (true) {
                if (tokener.nextClean() == ',') {
                    tokener.back()
                    array.add(null)
                } else {
                    tokener.back()
                    array.add(tokener.nextValue())
                }
                when (tokener.nextClean()) {
                    ',' -> {
                        if (tokener.nextClean() == ']') {
                            return
                        }
                        tokener.back()
                    }
                    ']' -> return
                    else -> throw tokener.syntaxError("Expected a ',' or ']'")
                }
            }
        }
    }

    constructor(jsonString: String) : this(JsonTokener(jsonString))

    constructor(list: Collection<Any?>) : this() {
        array.addAll(list.filter { it.isValidJsonType() })
    }

    private fun getValue(index: Int): Any? {
        if (index !in array.indices) {
            return null
        }
        return array[index]
    }

    private fun setValue(index: Int, value: Any?) {
        if (index !in array.indices) {
            return//Throws exception?
        }
        if (!value.isValidJsonType()) {
            throw JsonException("$value is not a valid JsonException")
        }
        array [index] = value

    }

    //Setters

    fun set(index: Int, value: Any?) {
        //TODO check the type of value
        setValue(index, value)
    }

    //Putters

    fun put(value: Any?): JsonArray {
        //TODO check the type of value
        array.add(value)
        return this
    }

    //Getters<commit_msg>Added a check to make sure set values are valid JsonTypes<commit_after>package edu.csh.chase.sprint.json

import java.io.IOException
import java.io.StringWriter
import java.io.Writer
import java.util.*

class JsonArray() : JsonBase() {


    private val array = ArrayList<Any?>()

    override val size: Int
        get() {
            return array.size()
        }

    constructor(tokener: JsonTokener) : this() {
        if (tokener.nextClean() != '[') {
            throw tokener.syntaxError("A JSONArray text must start with '['")
        }
        if (tokener.nextClean() != ']') {
            tokener.back()
            while (true) {
                if (tokener.nextClean() == ',') {
                    tokener.back()
                    array.add(null)
                } else {
                    tokener.back()
                    array.add(tokener.nextValue())
                }
                when (tokener.nextClean()) {
                    ',' -> {
                        if (tokener.nextClean() == ']') {
                            return
                        }
                        tokener.back()
                    }
                    ']' -> return
                    else -> throw tokener.syntaxError("Expected a ',' or ']'")
                }
            }
        }
    }

    constructor(jsonString: String) : this(JsonTokener(jsonString))

    constructor(list: Collection<Any?>) : this() {
        array.addAll(list.filter { it.isValidJsonType() })
    }

    private fun getValue(index: Int): Any? {
        if (index !in array.indices) {
            return null
        }
        return array[index]
    }

    private fun setValue(index: Int, value: Any?) {
        if (index !in array.indices) {
            return//Throws exception?
        }
        if (!value.isValidJsonType()) {
            throw JsonException("$value is not a valid JsonException")
        }
        array [index] = value
    }

    //Setters

    fun set(index: Int, value: Any?) {
        //TODO check the type of value
        setValue(index, value)
    }

    //Putters

    fun put(value: Any?): JsonArray {
        if (!value.isValidJsonType()) {
            throw JsonException("$value is not a valid JsonException")
        }
        array.add(value)
        return this
    }

    //Getters
{'fraction_non_alphanumeric': 0.12058627581612258, 'fraction_numerical': 0.0, 'mean_word_length': 1.3855932203389831, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '252045', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1199, 'n_words': 280}