All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.com.sceyt.chatuikit.presentation.common.SyncArrayList.kt Maven / Gradle / Ivy

There is a newer version: 1.7.2
Show newest version
package com.sceyt.chatuikit.presentation.common

import android.os.Build
import androidx.annotation.RequiresApi
import java.util.*
import java.util.function.Consumer
import java.util.function.Predicate
import java.util.function.UnaryOperator
import java.util.stream.Stream
import kotlin.collections.ArrayList

class SyncArrayList : ArrayList {

    constructor()

    constructor(collection: Collection) {
        addAll(collection)
    }

    private val syncObj = Any()

    override fun add(element: T): Boolean {
        synchronized(syncObj) {
            return super.add(element)
        }
    }

    override fun add(index: Int, element: T) {
        synchronized(syncObj) {
            super.add(index, element)
        }
    }

    override fun addAll(elements: Collection): Boolean {
        synchronized(syncObj) {
            return super.addAll(elements)
        }
    }

    override fun addAll(index: Int, elements: Collection): Boolean {
        synchronized(syncObj) {
            return super.addAll(index, elements)
        }
    }

    override fun get(index: Int): T {
        synchronized(syncObj) {
            return super.get(index)
        }
    }

    override fun set(index: Int, element: T): T {
        synchronized(syncObj) {
            return super.set(index, element)
        }
    }

    override fun contains(element: T): Boolean {
        synchronized(syncObj) {
            return super.contains(element)
        }
    }

    override fun containsAll(elements: Collection): Boolean {
        synchronized(syncObj) {
            return super.containsAll(elements)
        }
    }

    override fun remove(element: T): Boolean {
        synchronized(syncObj) {
            return super.remove(element)
        }
    }

    override fun removeAll(elements: Collection): Boolean {
        synchronized(syncObj) {
            return super.removeAll(elements)
        }
    }

    override fun removeAt(index: Int): T {
        synchronized(syncObj) {
            return super.removeAt(index)
        }
    }

    override fun removeRange(fromIndex: Int, toIndex: Int) {
        synchronized(syncObj) {
            super.removeRange(fromIndex, toIndex)
        }
    }

    override fun clear() {
        synchronized(syncObj) {
            super.clear()
        }
    }

    override fun subList(fromIndex: Int, toIndex: Int): MutableList {
        synchronized(syncObj) {
            return super.subList(fromIndex, toIndex)
        }
    }

    override fun equals(other: Any?): Boolean {
        synchronized(syncObj) {
            return super.equals(other)
        }
    }

    override fun clone(): Any {
        synchronized(syncObj) {
            return super.clone()
        }
    }

    override fun isEmpty(): Boolean {
        synchronized(syncObj) {
            return super.isEmpty()
        }
    }

    override fun indexOf(element: T): Int {
        synchronized(syncObj) {
            return super.indexOf(element)
        }
    }

    override fun listIterator(): MutableListIterator {
        synchronized(syncObj) {
            return super.listIterator()
        }
    }

    override fun iterator(): MutableIterator {
        synchronized(syncObj) {
            return super.iterator()
        }
    }

    override fun ensureCapacity(minCapacity: Int) {
        synchronized(syncObj) {
            super.ensureCapacity(minCapacity)
        }
    }

    override fun toArray(): Array {
        synchronized(syncObj) {
            return super.toArray()
        }
    }

    override fun toString(): String {
        synchronized(syncObj) {
            return super.toString()
        }
    }

    override fun hashCode(): Int {
        synchronized(syncObj) {
            return super.hashCode()
        }
    }

    override fun spliterator(): Spliterator {
        synchronized(syncObj) {
            return super.spliterator()
        }
    }

    override fun trimToSize() {
        synchronized(syncObj) {
            super.trimToSize()
        }
    }

    override fun lastIndexOf(element: T): Int {
        synchronized(syncObj) {
            return super.lastIndexOf(element)
        }
    }

    override fun listIterator(index: Int): MutableListIterator {
        synchronized(syncObj) {
            return super.listIterator(index)
        }
    }

    override fun retainAll(elements: Collection): Boolean {
        synchronized(syncObj) {
            return super.retainAll(elements)
        }
    }

    override fun stream(): Stream {
        synchronized(syncObj) {
            return super.stream()
        }
    }

    override fun  toArray(a: Array): Array {
        synchronized(syncObj) {
            return super.toArray(a)
        }
    }

    override fun parallelStream(): Stream {
        synchronized(syncObj) {
            return super.parallelStream()
        }
    }

    @RequiresApi(Build.VERSION_CODES.N)
    override fun replaceAll(operator: UnaryOperator) {
        synchronized(syncObj) {
            super.replaceAll(operator)
        }
    }

    @RequiresApi(Build.VERSION_CODES.N)
    override fun removeIf(filter: Predicate): Boolean {
        synchronized(syncObj) {
            return super.removeIf(filter)
        }
    }

    @RequiresApi(Build.VERSION_CODES.N)
    override fun forEach(action: Consumer) {
        synchronized(syncObj) {
            super.forEach(action)
        }
    }

    @RequiresApi(Build.VERSION_CODES.N)
    override fun sort(c: Comparator?) {
        synchronized(syncObj) {
            super.sort(c)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy