Skip to content

Commit

Permalink
Added base classes for event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Sep 14, 2023
1 parent b222ab9 commit cdc44a0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.ical4j.connector;

import org.ical4j.connector.event.ListenerList;
import org.ical4j.connector.event.ObjectCollectionListener;

public abstract class AbstractObjectCollection<T> implements ObjectCollection<T> {

private final ListenerList<ObjectCollectionListener<T>> listenerList;

public AbstractObjectCollection() {
this(new ListenerList<>());
}

public AbstractObjectCollection(ListenerList<ObjectCollectionListener<T>> listenerList) {
this.listenerList = listenerList;
}

@Override
public ListenerList<ObjectCollectionListener<T>> getObjectCollectionListeners() {
return listenerList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.ical4j.connector;

import org.ical4j.connector.event.ListenerList;
import org.ical4j.connector.event.ObjectStoreListener;

public abstract class AbstractObjectStore<T, C extends ObjectCollection<T>> implements ObjectStore<T, C> {

/**
* Registered event listeners.
*/
private final ListenerList<ObjectStoreListener<T>> listenerList;

public AbstractObjectStore() {
this(new ListenerList<>());
}

public AbstractObjectStore(ListenerList<ObjectStoreListener<T>> listenerList) {
this.listenerList = listenerList;
}

@Override
public ListenerList<ObjectStoreListener<T>> getObjectStoreListeners() {
return listenerList;
}
}
Original file line number Diff line number Diff line change
@@ -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<T> implements ObjectCollection<T> {
public abstract class AbstractLocalObjectCollection<T> extends AbstractObjectCollection<T> {

private final File root;

private final LocalCollectionConfiguration configuration;

private final ListenerList<ObjectCollectionListener<T>> listenerList;

public AbstractLocalObjectCollection(File root) throws IOException {
this.root = Objects.requireNonNull(root);
if (!root.isDirectory()) {
Expand All @@ -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() {
Expand Down Expand Up @@ -81,11 +76,6 @@ public void delete() throws ObjectStoreException {
}
}

@Override
public ListenerList<ObjectCollectionListener<T>> getObjectCollectionListeners() {
return listenerList;
}

@Override
public String toString() {
return String.format("LocalCollection[%s]", getDisplayName());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,20 +12,17 @@
import java.util.Objects;
import java.util.stream.Collectors;

public abstract class AbstractLocalObjectStore<T, C extends AbstractLocalObjectCollection<T>> implements ObjectStore<T, C> {
public abstract class AbstractLocalObjectStore<T, C extends AbstractLocalObjectCollection<T>> extends AbstractObjectStore<T, C> {

private final File root;

private final ListenerList<ObjectStoreListener<T>> listenerList;

AbstractLocalObjectStore(File root) {
this.root = Objects.requireNonNull(root);
if (root.exists() && !root.isDirectory()) {
throw new IllegalArgumentException("Root must be a directory");
} else if (!root.exists() && !root.mkdirs()) {
throw new IllegalArgumentException("Unable to initialise root directory");
}
listenerList = new ListenerList<>();
}

protected File getRoot() {
Expand Down Expand Up @@ -132,9 +127,4 @@ public List<C> getCollections() {
}
}).collect(Collectors.toList());
}

@Override
public ListenerList<ObjectStoreListener<T>> getObjectStoreListeners() {
return listenerList;
}
}

0 comments on commit cdc44a0

Please sign in to comment.