* 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:
Oliver Gierke
2010-01-11 14:23:20 +00:00
parent 4944e4259c
commit 68efadea79
2 changed files with 33 additions and 10 deletions

View File

@@ -67,11 +67,7 @@ public class OrderAwarePluginRegistry<T extends Plugin<S>, S> extends
Comparator<? super T> comparator) {
super(plugins);
this.comparator = DEFAULT_COMPARATOR;
if (comparator != null) {
this.comparator = comparator;
}
setComparator(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)
*
@@ -173,7 +189,7 @@ public class OrderAwarePluginRegistry<T extends Plugin<S>, S> extends
public OrderAwarePluginRegistry<T, S> addPlugin(T plugin) {
super.addPlugin(plugin);
Collections.sort(getPlugins(), comparator);
Collections.sort(plugins, comparator);
return this;
}
@@ -187,7 +203,7 @@ public class OrderAwarePluginRegistry<T extends Plugin<S>, S> extends
@SuppressWarnings("unchecked")
public OrderAwarePluginRegistry<T, S> reverse() {
return create(getPlugins(), new RevertingComparator(comparator));
return create(plugins, new RevertingComparator(comparator));
}
/**

View File

@@ -17,6 +17,7 @@
package org.synyx.hera.core;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -32,8 +33,7 @@ import java.util.List;
public class SimplePluginRegistry<T extends Plugin<S>, S> implements
MutablePluginRegistry<T, S> {
// Registered plugins
private List<T> plugins;
protected List<T> plugins;
/**
@@ -84,7 +84,10 @@ public class SimplePluginRegistry<T extends Plugin<S>, S> implements
public void setPlugins(List<? extends T> plugins) {
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) {
if (null == plugin) {
throw new IllegalArgumentException("Plugin must not be null!");
}
this.plugins.add(plugin);
return this;
}