diff --git a/ical4j-connector-api/src/main/java/org/ical4j/connector/AbstractObjectCollection.java b/ical4j-connector-api/src/main/java/org/ical4j/connector/AbstractObjectCollection.java new file mode 100644 index 0000000..102066a --- /dev/null +++ b/ical4j-connector-api/src/main/java/org/ical4j/connector/AbstractObjectCollection.java @@ -0,0 +1,22 @@ +package org.ical4j.connector; + +import org.ical4j.connector.event.ListenerList; +import org.ical4j.connector.event.ObjectCollectionListener; + +public abstract class AbstractObjectCollection implements ObjectCollection { + + private final ListenerList> listenerList; + + public AbstractObjectCollection() { + this(new ListenerList<>()); + } + + public AbstractObjectCollection(ListenerList> listenerList) { + this.listenerList = listenerList; + } + + @Override + public ListenerList> getObjectCollectionListeners() { + return listenerList; + } +} diff --git a/ical4j-connector-api/src/main/java/org/ical4j/connector/AbstractObjectStore.java b/ical4j-connector-api/src/main/java/org/ical4j/connector/AbstractObjectStore.java new file mode 100644 index 0000000..798c1cd --- /dev/null +++ b/ical4j-connector-api/src/main/java/org/ical4j/connector/AbstractObjectStore.java @@ -0,0 +1,25 @@ +package org.ical4j.connector; + +import org.ical4j.connector.event.ListenerList; +import org.ical4j.connector.event.ObjectStoreListener; + +public abstract class AbstractObjectStore> implements ObjectStore { + + /** + * Registered event listeners. + */ + private final ListenerList> listenerList; + + public AbstractObjectStore() { + this(new ListenerList<>()); + } + + public AbstractObjectStore(ListenerList> listenerList) { + this.listenerList = listenerList; + } + + @Override + public ListenerList> getObjectStoreListeners() { + return listenerList; + } +} diff --git a/ical4j-connector-api/src/main/java/org/ical4j/connector/local/AbstractLocalObjectCollection.java b/ical4j-connector-api/src/main/java/org/ical4j/connector/local/AbstractLocalObjectCollection.java index f69fd8a..552633d 100644 --- a/ical4j-connector-api/src/main/java/org/ical4j/connector/local/AbstractLocalObjectCollection.java +++ b/ical4j-connector-api/src/main/java/org/ical4j/connector/local/AbstractLocalObjectCollection.java @@ -1,23 +1,19 @@ package org.ical4j.connector.local; import net.fortuna.ical4j.model.Calendar; -import org.ical4j.connector.ObjectCollection; +import org.ical4j.connector.AbstractObjectCollection; import org.ical4j.connector.ObjectStoreException; -import org.ical4j.connector.event.ListenerList; -import org.ical4j.connector.event.ObjectCollectionListener; import java.io.File; import java.io.IOException; import java.util.Objects; -public abstract class AbstractLocalObjectCollection implements ObjectCollection { +public abstract class AbstractLocalObjectCollection extends AbstractObjectCollection { private final File root; private final LocalCollectionConfiguration configuration; - private final ListenerList> listenerList; - public AbstractLocalObjectCollection(File root) throws IOException { this.root = Objects.requireNonNull(root); if (!root.isDirectory()) { @@ -29,7 +25,6 @@ public AbstractLocalObjectCollection(File root) throws IOException { throw new IOException("Unable to initialise collection config"); } this.configuration = new LocalCollectionConfiguration(configRoot); - this.listenerList = new ListenerList<>(); } protected File getRoot() { @@ -81,11 +76,6 @@ public void delete() throws ObjectStoreException { } } - @Override - public ListenerList> getObjectCollectionListeners() { - return listenerList; - } - @Override public String toString() { return String.format("LocalCollection[%s]", getDisplayName()); diff --git a/ical4j-connector-api/src/main/java/org/ical4j/connector/local/AbstractLocalObjectStore.java b/ical4j-connector-api/src/main/java/org/ical4j/connector/local/AbstractLocalObjectStore.java index 30799b1..62020d7 100644 --- a/ical4j-connector-api/src/main/java/org/ical4j/connector/local/AbstractLocalObjectStore.java +++ b/ical4j-connector-api/src/main/java/org/ical4j/connector/local/AbstractLocalObjectStore.java @@ -1,11 +1,9 @@ package org.ical4j.connector.local; import net.fortuna.ical4j.model.Calendar; +import org.ical4j.connector.AbstractObjectStore; import org.ical4j.connector.ObjectNotFoundException; -import org.ical4j.connector.ObjectStore; import org.ical4j.connector.ObjectStoreException; -import org.ical4j.connector.event.ListenerList; -import org.ical4j.connector.event.ObjectStoreListener; import java.io.File; import java.io.IOException; @@ -14,12 +12,10 @@ import java.util.Objects; import java.util.stream.Collectors; -public abstract class AbstractLocalObjectStore> implements ObjectStore { +public abstract class AbstractLocalObjectStore> extends AbstractObjectStore { private final File root; - private final ListenerList> listenerList; - AbstractLocalObjectStore(File root) { this.root = Objects.requireNonNull(root); if (root.exists() && !root.isDirectory()) { @@ -27,7 +23,6 @@ public abstract class AbstractLocalObjectStore(); } protected File getRoot() { @@ -132,9 +127,4 @@ public List getCollections() { } }).collect(Collectors.toList()); } - - @Override - public ListenerList> getObjectStoreListeners() { - return listenerList; - } }