package com.nbusy.capacitor;

import java.util.ArrayList;
import java.util.List;

/**
 * Container for an immutable state object.
 */
public abstract class Container<T> {
    private T state;
    private List<Subscriber<T>> subscribers;

    public Container(T state) {
        this.state = state;
        subscribers = new ArrayList<>();
    }

    public void setState(T state) {
        this.state = state;
        for (Subscriber<T> s : subscribers) {
            s.onStateChange(state);
        }
    }

    public T getState() {
        return state;
    }

    public void subscribe(Subscriber<T> s) {
        subscribers.add(s);
    }
}

@@ -40,21 +40,16 @@
 va.util.
-Array
 List;%0Aim
@@ -59,24 +59,51 @@
 t java.util.
+concurrent.CopyOnWriteArray
 List;%0A%0A/**%0A 
@@ -339,16 +339,27 @@
 s = new 
+CopyOnWrite
 ArrayLis
@@ -631,24 +631,24 @@
 ber%3CT%3E s) %7B%0A
-
         subs
@@ -668,11 +668,96 @@
 );%0A    %7D
+%0A%0A    public void unsubscribe(Subscriber%3CT%3E s) %7B%0A        subscribers.remove(s);%0A    %7D
 %0A%7D%0A

Container list is concurrent