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

import com.google.common.collect.ImmutableList
import com.google.common.collect.ImmutableSet
import java.util.*
import kotlin.collections.RandomAccess

class ListSet<T>(private val list: ImmutableList<T>) : List<T>, Set<T>, RandomAccess {
	constructor(list: Collection<T>) : this(ImmutableList.copyOf(list))

	private val set: ImmutableSet<T> by lazy { ImmutableSet.copyOf(list) }

	override val size: Int
		get() = list.size

	override fun contains(element: T): Boolean {
		return set.contains(element)
	}

	override fun containsAll(elements: Collection<T>): Boolean {
		return set.containsAll(elements)
	}

	override fun get(index: Int): T {
		return list[index]
	}

	override fun indexOf(element: T): Int {
		return list.indexOf(element)
	}

	override fun isEmpty(): Boolean {
		return list.isEmpty()
	}

	override fun iterator(): Iterator<T> {
		return list.iterator()
	}

	override fun lastIndexOf(element: T): Int {
		return list.lastIndexOf(element)
	}

	override fun listIterator(): ListIterator<T> {
		return list.listIterator()
	}

	override fun listIterator(index: Int): ListIterator<T> {
		return list.listIterator(index)
	}

	override fun spliterator(): Spliterator<T> {
		return list.spliterator()
	}

	override fun subList(fromIndex: Int, toIndex: Int): List<T> {
		return list.subList(fromIndex, toIndex)
	}
}
