Author: adrianc
Date: Sun Nov 8 05:08:26 2009 New Revision: 833827 URL: http://svn.apache.org/viewvc?rev=833827&view=rev Log: Added Collection Converters. Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/BooleanConverters.java ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/BooleanConverters.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/BooleanConverters.java?rev=833827&r1=833826&r2=833827&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/BooleanConverters.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/BooleanConverters.java Sun Nov 8 05:08:26 2009 @@ -24,7 +24,7 @@ public static class BooleanToInteger extends AbstractConverter<Boolean, Integer> { public Integer convert(Boolean obj) throws ConversionException { - return obj.booleanValue() ? Integer.valueOf(1) : Integer.valueOf(0); + return obj.booleanValue() ? 1 : 0; } public Class<Boolean> getSourceClass() { @@ -56,7 +56,7 @@ public static class IntegerToBoolean extends AbstractConverter<Integer, Boolean> { public Boolean convert(Integer obj) throws ConversionException { - return obj.intValue() == 0 ? Boolean.FALSE : Boolean.TRUE; + return obj.intValue() == 0 ? false : true; } public Class<Integer> getSourceClass() { Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java?rev=833827&r1=833826&r2=833827&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java Sun Nov 8 05:08:26 2009 @@ -30,8 +30,9 @@ import javolution.util.FastSet; import org.ofbiz.base.conversion.BooleanConverters.*; -import org.ofbiz.base.conversion.NumberConverters.*; +import org.ofbiz.base.conversion.CollectionConverters.*; import org.ofbiz.base.conversion.DateTimeConverters.*; +import org.ofbiz.base.conversion.NumberConverters.*; import org.ofbiz.base.conversion.MiscConverters.*; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.ObjectType; @@ -48,8 +49,10 @@ protected static final Set<String> noConversions = FastSet.newInstance(); protected static final Converter<Object, Object> nullConverter = new NullConverter(); - public static final Converter<BigDecimal, Double> BigDecimalToDouble = new BigDecimalToDouble(); - public static final Converter<BigDecimal, Float> BigDecimalToFloat = new BigDecimalToFloat(); + // If Arrays aren't converted when using RMI, then comment out the next line + public static final Converter<Object[], List<?>> ArrayToList = new ArrayToList(); + public static final Converter<BigDecimal, Double> BigDecimalToDouble = new BigDecimalToDouble(); + public static final Converter<BigDecimal, Float> BigDecimalToFloat = new BigDecimalToFloat(); public static final Converter<BigDecimal, Integer> BigDecimalToInteger = new BigDecimalToInteger(); public static final Converter<BigDecimal, List<BigDecimal>> BigDecimalToList = new BigDecimalToList(); public static final Converter<BigDecimal, Long> BigDecimalToLong = new BigDecimalToLong(); @@ -84,6 +87,7 @@ public static final Converter<Integer, Long> IntegerToLong = new IntegerToLong(); public static final Converter<Integer, Set<Integer>> IntegerToSet = new IntegerToSet(); public static final LocalizedConverter<Integer, String> IntegerToString = new IntegerToString(); + public static final Converter<List<?>, String> ListToString = new ListToString(); public static final Converter<Locale, String> LocaleToString = new LocaleToString(); public static final Converter<Long, BigDecimal> LongToBigDecimal = new LongToBigDecimal(); public static final Converter<Long, Calendar> LongToCalendar = new LongToCalendar(); @@ -93,29 +97,37 @@ public static final Converter<Long, List<Long>> LongToList = new LongToList(); public static final Converter<Long, Set<Long>> LongToSet = new LongToSet(); public static final LocalizedConverter<Long, String> LongToString = new LongToString(); + public static final Converter<Map<?, ?>, List<Map<?,?>>> MapToList = new MapToList(); + public static final Converter<Map<?, ?>, Set<Map<?,?>>> MapToSet = new MapToSet(); + public static final Converter<Map<?, ?>, String> MapToString = new MapToString(); public static final Converter<Number, java.util.Date> NumberToDate = new NumberToDate(); public static final Converter<Number, TimeDuration> NumberToDuration = new NumberToDuration(); public static final Converter<Number, java.sql.Date> NumberToSqlDate = new NumberToSqlDate(); public static final Converter<Number, java.sql.Time> NumberToSqlTime = new NumberToSqlTime(); public static final Converter<Number, java.sql.Timestamp> NumberToTimestamp = new NumberToTimestamp(); public static final LocalizedConverter<java.sql.Date, String> SqlDateToString = new SqlDateToString(); - public static final LocalizedConverter<java.sql.Time, String> SqlTimeToString = new SqlTimeToString(); - public static final LocalizedConverter<String, BigDecimal> StringToBigDecimal = new StringToBigDecimal(); - public static final Converter<String, Boolean> StringToBoolean = new StringToBoolean(); - public static final LocalizedConverter<String, Calendar> StringToCalendar = new StringToCalendar(); - public static final LocalizedConverter<String, java.util.Date> StringToDate = new StringToDate(); - public static final LocalizedConverter<String, Double> StringToDouble = new StringToDouble(); + public static final LocalizedConverter<java.sql.Time, String> SqlTimeToString = new SqlTimeToString(); + public static final LocalizedConverter<String, BigDecimal> StringToBigDecimal = new StringToBigDecimal(); + public static final Converter<String, Boolean> StringToBoolean = new StringToBoolean(); + public static final LocalizedConverter<String, Calendar> StringToCalendar = new StringToCalendar(); + public static final LocalizedConverter<String, java.util.Date> StringToDate = new StringToDate(); + public static final LocalizedConverter<String, Double> StringToDouble = new StringToDouble(); public static final Converter<String, TimeDuration> StringToDuration = new StringToDuration(); public static final LocalizedConverter<String, Float> StringToFloat = new StringToFloat(); public static final LocalizedConverter<String, Integer> StringToInteger = new StringToInteger(); + public static final Converter<String, List<?>> StringToList = new StringToList(); public static final Converter<String, Locale> StringToLocale = new StringToLocale(); public static final LocalizedConverter<String, Long> StringToLong = new StringToLong(); + public static final Converter<String, Map<?, ?>> StringToMap = new StringToMap(); + public static final Converter<String, Set<?>> StringToSet = new StringToSet(); public static final LocalizedConverter<String, java.sql.Date> StringToSqlDate = new StringToSqlDate(); public static final LocalizedConverter<String, java.sql.Time> StringToSqlTime = new StringToSqlTime(); public static final LocalizedConverter<String, java.sql.Timestamp> StringToTimestamp = new StringToTimestamp(); public static final Converter<String, TimeZone> StringToTimeZone = new StringToTimeZone(); public static final Converter<TimeZone, String> TimeZoneToString = new TimeZoneToString(); + private Converters() {} + /** Returns an appropriate <code>Converter</code> instance for * <code>sourceClass</code> and <code>targetClass</code>. If no matching * <code>Converter</code> is found, the method throws @@ -149,7 +161,7 @@ Debug.logWarning("*** No converter found, converting from " + sourceClass.getName() + " to " + targetClass.getName() + ". Please report this message to the developer community so " + - "a suitable converter can be developed. ***", module); + "a suitable converter can be created. ***", module); } } throw new ClassNotFoundException("No converter found for " + key); @@ -207,27 +219,28 @@ return "Map size = " + converterMap.size(); } + @SuppressWarnings("unchecked") public static String runPerformanceTest() { - @SuppressWarnings("unused") - Object obj = null; + Object[] intArray = {1,2,3,4}; + List obj = null; try { - Converter<BigDecimal, Integer> converter = Converters.getConverter(BigDecimal.class, Integer.class); - obj = converter.convert(BigDecimal.ONE); + Converter<Object[], List> converter = Converters.getConverter(Object[].class, List.class); + obj = converter.convert(intArray); } catch (Exception e) {} System.gc(); long newStart = System.currentTimeMillis(); try { for (int i = 0; i < 1000000; i++) { - Converter<BigDecimal, Integer> converter = Converters.getConverter(BigDecimal.class, Integer.class); - obj = converter.convert(BigDecimal.ONE); + Converter<Object[], List> converter = Converters.getConverter(Object[].class, List.class); + obj = converter.convert(intArray); } } catch (Exception e) { Debug.logError(e, module); } long newStop = System.currentTimeMillis(); - Debug.logInfo("Elasped time = " + (newStop - newStart), module); - return "Elasped time = " + (newStop - newStart); + Debug.logInfo("Elapsed time = " + (newStop - newStart), module); + return "Elapsed time = " + (newStop - newStart) + ", List size = " + obj.size(); } - */ + } Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java?rev=833827&r1=833826&r2=833827&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java Sun Nov 8 05:08:26 2009 @@ -455,7 +455,7 @@ * @return true if objectClass is a class or sub-class of, or implements typeClass */ public static boolean instanceOf(Class<?> objectClass, Class<?> typeClass) { - if (typeClass.isInterface()) { + if (typeClass.isInterface() && !objectClass.isInterface()) { return interfaceOf(objectClass, typeClass); } else { return isOrSubOf(objectClass, typeClass); |
Free forum by Nabble | Edit this page |