* made @plugins@ property protected to allow mutable access for sorting
* created dedicated method for setting a @Comparator@ to clean up internal code * use @plugins@ property for sorting access instead of @getPlugins@ which returns an immutable @List@ now git-svn-id: svn+ssh://svn.synyx.de/var/svn/synyx/opensource/hera/trunk@8543 5a64d73e-33d6-4ccc-9058-23f8668ecac9
This commit is contained in:
@@ -67,11 +67,7 @@ public class OrderAwarePluginRegistry<T extends Plugin<S>, S> extends
|
|||||||
Comparator<? super T> comparator) {
|
Comparator<? super T> comparator) {
|
||||||
|
|
||||||
super(plugins);
|
super(plugins);
|
||||||
|
setComparator(comparator);
|
||||||
this.comparator = DEFAULT_COMPARATOR;
|
|
||||||
if (comparator != null) {
|
|
||||||
this.comparator = comparator;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -150,6 +146,26 @@ public class OrderAwarePluginRegistry<T extends Plugin<S>, S> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the comparator to use. Resorts the contained {@link Plugin}s if any
|
||||||
|
* available.
|
||||||
|
*
|
||||||
|
* @param comparator the comparator to set
|
||||||
|
*/
|
||||||
|
private void setComparator(Comparator<? super T> comparator) {
|
||||||
|
|
||||||
|
this.comparator = DEFAULT_COMPARATOR;
|
||||||
|
|
||||||
|
if (comparator != null) {
|
||||||
|
this.comparator = comparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugins != null) {
|
||||||
|
Collections.sort(plugins, comparator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
@@ -173,7 +189,7 @@ public class OrderAwarePluginRegistry<T extends Plugin<S>, S> extends
|
|||||||
public OrderAwarePluginRegistry<T, S> addPlugin(T plugin) {
|
public OrderAwarePluginRegistry<T, S> addPlugin(T plugin) {
|
||||||
|
|
||||||
super.addPlugin(plugin);
|
super.addPlugin(plugin);
|
||||||
Collections.sort(getPlugins(), comparator);
|
Collections.sort(plugins, comparator);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +203,7 @@ public class OrderAwarePluginRegistry<T extends Plugin<S>, S> extends
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public OrderAwarePluginRegistry<T, S> reverse() {
|
public OrderAwarePluginRegistry<T, S> reverse() {
|
||||||
|
|
||||||
return create(getPlugins(), new RevertingComparator(comparator));
|
return create(plugins, new RevertingComparator(comparator));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.synyx.hera.core;
|
package org.synyx.hera.core;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -32,8 +33,7 @@ import java.util.List;
|
|||||||
public class SimplePluginRegistry<T extends Plugin<S>, S> implements
|
public class SimplePluginRegistry<T extends Plugin<S>, S> implements
|
||||||
MutablePluginRegistry<T, S> {
|
MutablePluginRegistry<T, S> {
|
||||||
|
|
||||||
// Registered plugins
|
protected List<T> plugins;
|
||||||
private List<T> plugins;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +84,10 @@ public class SimplePluginRegistry<T extends Plugin<S>, S> implements
|
|||||||
public void setPlugins(List<? extends T> plugins) {
|
public void setPlugins(List<? extends T> plugins) {
|
||||||
|
|
||||||
this.plugins = new ArrayList<T>();
|
this.plugins = new ArrayList<T>();
|
||||||
this.plugins.addAll(plugins);
|
|
||||||
|
if (plugins != null) {
|
||||||
|
this.plugins.addAll(plugins);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -97,6 +100,10 @@ public class SimplePluginRegistry<T extends Plugin<S>, S> implements
|
|||||||
*/
|
*/
|
||||||
public SimplePluginRegistry<T, S> addPlugin(T plugin) {
|
public SimplePluginRegistry<T, S> addPlugin(T plugin) {
|
||||||
|
|
||||||
|
if (null == plugin) {
|
||||||
|
throw new IllegalArgumentException("Plugin must not be null!");
|
||||||
|
}
|
||||||
|
|
||||||
this.plugins.add(plugin);
|
this.plugins.add(plugin);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user