* fixed some Findbugs / Checkstyle issues

* introduced helper methods to minimize necessary @@SuppressWarnings("unchecked")@ scope

git-svn-id: svn+ssh://svn.synyx.de/var/svn/synyx/opensource/hera/trunk@7555 5a64d73e-33d6-4ccc-9058-23f8668ecac9
This commit is contained in:
Oliver Gierke
2009-10-23 07:30:25 +00:00
parent 032849a858
commit 22068e325a
7 changed files with 26 additions and 19 deletions

View File

@@ -4,14 +4,13 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.annotation.Order;
/**
* {@link PluginRegistry} implementation that can handle {@link Plugin}s using
* the {@link Ordered} interface or {@link Order} annotation.
* the {@link org.springframework.core.Ordered} interface or
* {@link org.springframework.core.annotation.Order} annotation.
*
* @author Oliver Gierke - gierke@synyx.de
*/

View File

@@ -118,10 +118,10 @@ public class SimplePluginRegistry<T extends Plugin<S>, S> implements
*/
public T getPluginFor(S delimiter) {
List<T> plugins = getPluginsFor(delimiter);
List<T> result = getPluginsFor(delimiter);
if (0 < plugins.size()) {
return plugins.get(0);
if (0 < result.size()) {
return result.get(0);
}
return null;
@@ -172,13 +172,13 @@ public class SimplePluginRegistry<T extends Plugin<S>, S> implements
public <E extends Exception> List<T> getPluginsFor(S delimiter, E ex)
throws E {
List<T> plugins = getPluginsFor(delimiter);
List<T> result = getPluginsFor(delimiter);
if (0 == plugins.size()) {
if (0 == result.size()) {
throw ex;
}
return plugins;
return result;
}

View File

@@ -15,7 +15,6 @@
*/
package org.synyx.hera.core.config;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
@@ -35,8 +34,9 @@ public class PluginListDefinitionParser extends AbstractBeanDefinitionParser {
/**
* Returns the name of the {@link BeanFactoryPostProcessor} to be
* registered.
* Returns the name of the
* {@link org.springframework.beans.factory.config.BeanFactoryPostProcessor}
* to be registered.
*
* @return
*/

View File

@@ -20,19 +20,20 @@ import java.util.Comparator;
import java.util.List;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
/**
* Factory to create bean lists for a given type. Exposes all beans of the
* configured type that can be found in the {@link ApplicationContext}.
* configured type that can be found in the
* {@link org.springframework.context.ApplicationContext}.
*
* @author Oliver Gierke - gierke@synyx.de
*/
public class BeanListFactoryBean<T> extends AbstractTypeAwareSupport<T>
implements FactoryBean {
@SuppressWarnings("unchecked")
private static final Comparator<Object> COMPARATOR =
new AnnotationAwareOrderComparator();
@@ -42,7 +43,7 @@ public class BeanListFactoryBean<T> extends AbstractTypeAwareSupport<T>
*
* @see org.springframework.beans.factory.FactoryBean#getObject()
*/
public Object getObject() throws Exception {
public Object getObject() {
List<T> beans = getBeans();
Collections.sort(beans, COMPARATOR);

View File

@@ -35,7 +35,7 @@ public class PluginRegistryFactoryBean<T extends Plugin<S>, S> extends
*
* @see org.springframework.beans.factory.FactoryBean#getObject()
*/
public Object getObject() throws Exception {
public Object getObject() {
return OrderAwarePluginRegistry.create(getBeans());
}

View File

@@ -53,7 +53,7 @@ public class BeanListFactoryBeanUnitTest {
Object result = factory.getObject();
assertTrue(result instanceof List<?>);
List<Ordered> members = (List) result;
List<Ordered> members = type(result);
assertEquals(0, members.indexOf(second));
assertEquals(1, members.indexOf(first));
@@ -70,11 +70,18 @@ public class BeanListFactoryBeanUnitTest {
Object result = factory.getObject();
assertTrue(result instanceof List<?>);
List<Ordered> members = (List) result;
List<Ordered> members = type(result);
assertTrue(members.isEmpty());
}
@SuppressWarnings("unchecked")
private <T> List<T> type(Object list) {
return (List<T>) list;
}
/**
* Returns an {@link Ordered} with the given order.
*

View File

@@ -28,5 +28,5 @@ public interface MetadataProvider {
*
* @return the plugins metadata
*/
public PluginMetadata getMetadata();
PluginMetadata getMetadata();
}