package ru.dbotthepony.mc.otm.core.collect

import com.google.gson.JsonArray
import com.google.gson.JsonElement
import java.util.function.BiConsumer
import java.util.function.BinaryOperator
import java.util.function.Function
import java.util.function.Supplier
import java.util.stream.Collector

object JsonArrayCollector : Collector<JsonElement, JsonArray, JsonArray> {
	override fun supplier(): Supplier<JsonArray> {
		return Supplier { JsonArray() }
	}

	override fun accumulator(): BiConsumer<JsonArray, JsonElement> {
		return BiConsumer { t, u -> t.add(u) }
	}

	override fun combiner(): BinaryOperator<JsonArray> {
		return BinaryOperator { t, u -> t.addAll(u); t }
	}

	override fun finisher(): Function<JsonArray, JsonArray> {
		return Function.identity()
	}

	override fun characteristics(): Set<Collector.Characteristics> {
		return setOf(Collector.Characteristics.IDENTITY_FINISH)
	}
}
