Simplied the object graph, removed AbstractCollectionConverter. All
collection conversions now have proper generification. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@835453 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*******************************************************************************/
|
||||
package org.ofbiz.base.conversion;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.ofbiz.base.util.ObjectType;
|
||||
|
||||
/** Abstract Set Converter class. This class handles converter registration
|
||||
* and it implements the <code>canConvert</code> method.
|
||||
*/
|
||||
public abstract class AbstractCollectionConverter<S, T extends Collection<S>> implements Converter<S, T> {
|
||||
private final Class<S> sourceClass;
|
||||
private final Class<? super T> targetClass;
|
||||
|
||||
protected AbstractCollectionConverter(Class<S> sourceClass, Class<? super T> targetClass) {
|
||||
this.sourceClass = sourceClass;
|
||||
this.targetClass = targetClass;
|
||||
Converters.registerConverter(this);
|
||||
}
|
||||
|
||||
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
|
||||
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && ObjectType.instanceOf(targetClass, this.getTargetClass());
|
||||
}
|
||||
|
||||
public final Class<S> getSourceClass() {
|
||||
return sourceClass;
|
||||
}
|
||||
|
||||
public final Class<? super T> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,10 @@ import org.ofbiz.base.util.ObjectType;
|
||||
* and it implements the <code>canConvert</code> method.
|
||||
*/
|
||||
public abstract class AbstractConverter<S, T> implements Converter<S, T> {
|
||||
private final Class<S> sourceClass;
|
||||
private final Class<T> targetClass;
|
||||
private final Class<? super S> sourceClass;
|
||||
private final Class<? super T> targetClass;
|
||||
|
||||
protected AbstractConverter(Class<S> sourceClass, Class<T> targetClass) {
|
||||
protected AbstractConverter(Class<? super S> sourceClass, Class<? super T> targetClass) {
|
||||
this.sourceClass = sourceClass;
|
||||
this.targetClass = targetClass;
|
||||
Converters.registerConverter(this);
|
||||
@@ -37,11 +37,11 @@ public abstract class AbstractConverter<S, T> implements Converter<S, T> {
|
||||
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && ObjectType.instanceOf(targetClass, this.getTargetClass());
|
||||
}
|
||||
|
||||
public final Class<S> getSourceClass() {
|
||||
public final Class<? super S> getSourceClass() {
|
||||
return sourceClass;
|
||||
}
|
||||
|
||||
public final Class<T> getTargetClass() {
|
||||
public final Class<? super T> getTargetClass() {
|
||||
return targetClass;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import javolution.util.FastSet;
|
||||
|
||||
/** Collection Converter classes. */
|
||||
public class CollectionConverters implements ConverterLoader {
|
||||
public static class ArrayToList extends AbstractConverter<Object[], List> {
|
||||
public static class ArrayToList<T> extends AbstractConverter<T[], List<T>> {
|
||||
public ArrayToList() {
|
||||
super(Object[].class, List.class);
|
||||
}
|
||||
@@ -42,56 +42,56 @@ public class CollectionConverters implements ConverterLoader {
|
||||
return sourceClass.isArray() && ObjectType.instanceOf(targetClass, this.getTargetClass());
|
||||
}
|
||||
|
||||
public List<?> convert(Object[] obj) throws ConversionException {
|
||||
public List<T> convert(T[] obj) throws ConversionException {
|
||||
return Arrays.asList(obj);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ListToString extends AbstractConverter<List, String> {
|
||||
public static class ListToString<T> extends AbstractConverter<List<T>, String> {
|
||||
public ListToString() {
|
||||
super(List.class, String.class);
|
||||
}
|
||||
|
||||
public String convert(List obj) throws ConversionException {
|
||||
public String convert(List<T> obj) throws ConversionException {
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MapToList extends AbstractCollectionConverter<Map, List<Map>> {
|
||||
public static class MapToList<K, V> extends AbstractConverter<Map<K, V>, List<Map<K, V>>> {
|
||||
public MapToList() {
|
||||
super(Map.class, List.class);
|
||||
}
|
||||
|
||||
public List<Map> convert(Map obj) throws ConversionException {
|
||||
List<Map> tempList = FastList.newInstance();
|
||||
public List<Map<K, V>> convert(Map<K, V> obj) throws ConversionException {
|
||||
List<Map<K, V>> tempList = FastList.newInstance();
|
||||
tempList.add(obj);
|
||||
return tempList;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MapToSet extends AbstractCollectionConverter<Map, Set<Map>> {
|
||||
public static class MapToSet<K, V> extends AbstractConverter<Map<K, V>, Set<Map<K, V>>> {
|
||||
public MapToSet() {
|
||||
super(Map.class, Set.class);
|
||||
}
|
||||
|
||||
public Set<Map> convert(Map obj) throws ConversionException {
|
||||
Set<Map> tempSet = FastSet.newInstance();
|
||||
public Set<Map<K, V>> convert(Map<K, V> obj) throws ConversionException {
|
||||
Set<Map<K, V>> tempSet = FastSet.newInstance();
|
||||
tempSet.add(obj);
|
||||
return tempSet;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MapToString extends AbstractConverter<Map, String> {
|
||||
public static class MapToString<K, V> extends AbstractConverter<Map<K, V>, String> {
|
||||
public MapToString() {
|
||||
super(Map.class, String.class);
|
||||
}
|
||||
|
||||
public String convert(Map obj) throws ConversionException {
|
||||
public String convert(Map<K, V> obj) throws ConversionException {
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringToList extends AbstractCollectionConverter<String, List<String>> {
|
||||
public static class StringToList extends AbstractConverter<String, List<String>> {
|
||||
public StringToList() {
|
||||
super(String.class, List.class);
|
||||
}
|
||||
@@ -107,12 +107,12 @@ public class CollectionConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringToMap extends AbstractConverter<String, Map> {
|
||||
public static class StringToMap extends AbstractConverter<String, Map<String, String>> {
|
||||
public StringToMap() {
|
||||
super(String.class, Map.class);
|
||||
}
|
||||
|
||||
public Map convert(String obj) throws ConversionException {
|
||||
public Map<String, String> convert(String obj) throws ConversionException {
|
||||
if (obj.startsWith("{") && obj.endsWith("}")) {
|
||||
return StringUtil.toMap(obj);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class CollectionConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class StringToSet extends AbstractCollectionConverter<String, Set<String>> {
|
||||
public static class StringToSet extends AbstractConverter<String, Set<String>> {
|
||||
public StringToSet() {
|
||||
super(String.class, Set.class);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class NumberConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class BigDecimalToList extends AbstractCollectionConverter<BigDecimal, List<BigDecimal>> {
|
||||
public static class BigDecimalToList extends AbstractConverter<BigDecimal, List<BigDecimal>> {
|
||||
public BigDecimalToList() {
|
||||
super(BigDecimal.class, List.class);
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class NumberConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class BigDecimalToSet extends AbstractCollectionConverter<BigDecimal, Set<BigDecimal>> {
|
||||
public static class BigDecimalToSet extends AbstractConverter<BigDecimal, Set<BigDecimal>> {
|
||||
public BigDecimalToSet() {
|
||||
super(BigDecimal.class, Set.class);
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public class NumberConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class DoubleToList extends AbstractCollectionConverter<Double, List<Double>> {
|
||||
public static class DoubleToList extends AbstractConverter<Double, List<Double>> {
|
||||
public DoubleToList() {
|
||||
super(Double.class, List.class);
|
||||
}
|
||||
@@ -191,7 +191,7 @@ public class NumberConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class DoubleToSet extends AbstractCollectionConverter<Double, Set<Double>> {
|
||||
public static class DoubleToSet extends AbstractConverter<Double, Set<Double>> {
|
||||
public DoubleToSet() {
|
||||
super(Double.class, Set.class);
|
||||
}
|
||||
@@ -244,7 +244,7 @@ public class NumberConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class FloatToList extends AbstractCollectionConverter<Float, List<Float>> {
|
||||
public static class FloatToList extends AbstractConverter<Float, List<Float>> {
|
||||
public FloatToList() {
|
||||
super(Float.class, List.class);
|
||||
}
|
||||
@@ -266,7 +266,7 @@ public class NumberConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class FloatToSet extends AbstractCollectionConverter<Float, Set<Float>> {
|
||||
public static class FloatToSet extends AbstractConverter<Float, Set<Float>> {
|
||||
public FloatToSet() {
|
||||
super(Float.class, Set.class);
|
||||
}
|
||||
@@ -319,7 +319,7 @@ public class NumberConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class IntegerToList extends AbstractCollectionConverter<Integer, List<Integer>> {
|
||||
public static class IntegerToList extends AbstractConverter<Integer, List<Integer>> {
|
||||
public IntegerToList() {
|
||||
super(Integer.class, List.class);
|
||||
}
|
||||
@@ -341,7 +341,7 @@ public class NumberConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class IntegerToSet extends AbstractCollectionConverter<Integer, Set<Integer>> {
|
||||
public static class IntegerToSet extends AbstractConverter<Integer, Set<Integer>> {
|
||||
public IntegerToSet() {
|
||||
super(Integer.class, Set.class);
|
||||
}
|
||||
@@ -404,7 +404,7 @@ public class NumberConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class LongToList extends AbstractCollectionConverter<Long, List<Long>> {
|
||||
public static class LongToList extends AbstractConverter<Long, List<Long>> {
|
||||
public LongToList() {
|
||||
super(Long.class, List.class);
|
||||
}
|
||||
@@ -416,7 +416,7 @@ public class NumberConverters implements ConverterLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public static class LongToSet extends AbstractCollectionConverter<Long, Set<Long>> {
|
||||
public static class LongToSet extends AbstractConverter<Long, Set<Long>> {
|
||||
public LongToSet() {
|
||||
super(Long.class, Set.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user