<commit_before>package de.gesellix.docker.compose.adapters

import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonReader
import com.squareup.moshi.ToJson
import de.gesellix.docker.compose.types.ServiceNetwork

class StringToServiceNetworksAdapter {

    @ToJson
    List<String> toJson(@ServiceNetworksType Map<String, ServiceNetwork> networks) {
        throw new UnsupportedOperationException()
    }

    @FromJson
    @ServiceNetworksType
    Map<String, ServiceNetwork> fromJson(JsonReader reader) {
        def result = [:]
        def token = reader.peek()
        if (token == JsonReader.Token.BEGIN_OBJECT) {
            reader.beginObject()
            while (reader.hasNext()) {
                def name = reader.nextName()
                def valueType = reader.peek()
                if (valueType == JsonReader.Token.NULL) {
                    result[name] = reader.nextNull()
                } else if (valueType == JsonReader.Token.STRING) {
                    result[name] = reader.nextString()
                } else if (valueType == JsonReader.Token.BEGIN_OBJECT) {
                    def serviceNetwork = new ServiceNetwork()
                    reader.beginObject()
                    while (reader.hasNext()) {
                        def attr = reader.nextName()
                        if (attr == "ipv4_address") {
                            serviceNetwork.ipv4Address = reader.nextString()
                        } else if (attr == "ipv6_address") {
                            serviceNetwork.ipv6Address = reader.nextString()
                        } else if (attr == "aliases") {
                            def aliases = []
                            reader.beginArray()
                            while (reader.hasNext()) {
                                aliases.add(reader.nextString())
                            }
                            reader.endArray()
                            serviceNetwork.aliases = aliases
                        } else {
                            // ...
                        }
                    }
                    reader.endObject()
                    result[name] = serviceNetwork
                } else {
                    // ...
                }
            }
            reader.endObject()
        } else if (token == JsonReader.Token.BEGIN_ARRAY) {
            reader.beginArray()
            def name = reader.nextString()
//            def value = reader.nextNull()
            result[name] = null
            reader.endArray()
        } else {
            // ...
        }
        return result
    }
}<commit_msg>allow multiple service network references<commit_after>package de.gesellix.docker.compose.adapters

import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonReader
import com.squareup.moshi.ToJson
import de.gesellix.docker.compose.types.ServiceNetwork

class StringToServiceNetworksAdapter {

    @ToJson
    List<String> toJson(@ServiceNetworksType Map<String, ServiceNetwork> networks) {
        throw new UnsupportedOperationException()
    }

    @FromJson
    @ServiceNetworksType
    Map<String, ServiceNetwork> fromJson(JsonReader reader) {
        def result = [:]
        def token = reader.peek()
        if (token == JsonReader.Token.BEGIN_OBJECT) {
            reader.beginObject()
            while (reader.hasNext()) {
                def name = reader.nextName()
                def valueType = reader.peek()
                if (valueType == JsonReader.Token.NULL) {
                    result[name] = reader.nextNull()
                } else if (valueType == JsonReader.Token.STRING) {
                    result[name] = reader.nextString()
                } else if (valueType == JsonReader.Token.BEGIN_OBJECT) {
                    def serviceNetwork = new ServiceNetwork()
                    reader.beginObject()
                    while (reader.hasNext()) {
                        def attr = reader.nextName()
                        if (attr == "ipv4_address") {
                            serviceNetwork.ipv4Address = reader.nextString()
                        } else if (attr == "ipv6_address") {
                            serviceNetwork.ipv6Address = reader.nextString()
                        } else if (attr == "aliases") {
                            def aliases = []
                            reader.beginArray()
                            while (reader.hasNext()) {
                                aliases.add(reader.nextString())
                            }
                            reader.endArray()
                            serviceNetwork.aliases = aliases
                        } else {
                            // ...
                        }
                    }
                    reader.endObject()
                    result[name] = serviceNetwork
                } else {
                    // ...
                }
            }
            reader.endObject()
        } else if (token == JsonReader.Token.BEGIN_ARRAY) {
            reader.beginArray()
            while (reader.hasNext()) {
                def name = reader.nextString()
//            def value = reader.nextNull()
                result[name] = null
            }
            reader.endArray()
        } else {
            // ...
        }
        return result
    }
}
{'fraction_non_alphanumeric': 0.09387296233839236, 'fraction_numerical': 0.001498969458497283, 'mean_word_length': 1.207609594706369, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1798838', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1240, 'n_words': 238}