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

org.jboss.aerogear.sync.client.DefaultPatchObservable Maven / Gradle / Ivy

The newest version!
package org.jboss.aerogear.sync.client;

import org.jboss.aerogear.sync.ClientDocument;

import java.util.Observable;
import java.util.Observer;

public class DefaultPatchObservable extends Observable implements PatchObservable {

    @Override
    public void addPatchListener(PatchListener listener) {
        addObserver(new PatchListenerAdapter(listener));
    }

    @Override
    public void removePatchListener(PatchListener listener) {
        deleteObserver(new PatchListenerAdapter(listener));
    }

    @Override
    public void removePatchListeners() {
        deleteObservers();
    }

    @Override
    public void notifyPatched(ClientDocument patchedDocument) {
        notifyObservers(patchedDocument);
    }

    @Override
    public int countPatchListeners() {
        return countObservers();
    }

    @Override
    public void changed() {
        setChanged();
    }

    private static class PatchListenerAdapter implements Observer {

        private final PatchListener listener;

        PatchListenerAdapter(final PatchListener listener) {
            this.listener = listener;
        }

        @Override
        @SuppressWarnings("rawtypes")
        public void update(final Observable ignored, final Object arg) {
            if (arg instanceof ClientDocument) {
                listener.patched((ClientDocument) arg);
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy