You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@clerezza.apache.org by "Reto Bachmann-Gmür (JIRA)" <ji...@apache.org> on 2011/05/08 22:08:03 UTC

[jira] [Resolved] (CLEREZZA-511) allow access to individual SimpleLiteralFactory converters

     [ https://issues.apache.org/jira/browse/CLEREZZA-511?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Reto Bachmann-Gmür resolved CLEREZZA-511.
-----------------------------------------

    Resolution: Won't Fix

I did a commit under this issue that prevents the iteration over the map entries when this is not needed. Where an exact type is in the map this is now accessed directly thus having only a minimally performance overhead over the proposed solution.

I'm against the proposed solution as:
- This would make CLEREZZA-423 harder to implement (and less efficient as this fields would have to be proxies forwarding to one of the provided optimized converters).
- For making a public interface more complicated (okay its not very complicated but still a huge bunch of new public members) we should have good reasons, the performance problems mentioned seem to be theoretical and not actually seen while profiling a real application, the iteration causing a complexity linear to the number of converters is now avoided.


> allow access to individual SimpleLiteralFactory converters 
> -----------------------------------------------------------
>
>                 Key: CLEREZZA-511
>                 URL: https://issues.apache.org/jira/browse/CLEREZZA-511
>             Project: Clerezza
>          Issue Type: Improvement
>            Reporter: Henry Story
>            Assignee: Reto Bachmann-Gmür
>
> code in Scala could do with using the converters from the SimpleLiteralFactory, but when it does it is absolutely clear
> which converter is needed. Instead of just adding the converters to a hashmap I suggest adding giving each one of them names.
> This is already implemented at it works
> 	final static public TypeConverter<byte[]> BYTE_ARRAY_CONVERTER = new ByteArrayConverter();
> 	final static public TypeConverter<Boolean> BOOLEAN_CONVERTER = new BooleanConverter();
> 	final static public TypeConverter<Date> DATE_CONVERTER = new DateConverter();
> 	final static public TypeConverter<String> STRING_CONVERTER = new StringConverter();
> 	final static public TypeConverter<Integer> INTEGER_CONVERTER = new IntegerConverter();
> 	final static public TypeConverter<BigInteger> BIG_INTEGER_CONVERTER = new BigIntegerConverter();
> 	final static public TypeConverter<Long> LONG_CONVERTER = new LongConverter();
> 	final static public TypeConverter<Double> DOUBLE_CONVERTER = new DoubleConverter();
> 	final static public TypeConverter<UriRef> URIREF_CONVERTER = new UriRefConverter();
> 	final private static Map<Class<?>, TypeConverter<?>> typeConverterMap = new HashMap<Class<?>, TypeConverter<?>>();
> 	final static Class<? extends byte[]> byteArrayType;
> 	static {
> 		//what's this for?
> 		Collections.addAll(decimalTypes, xsdInteger, xsdInt, xsdByte, xsdShort);
> 		byte[] byteArray = new byte[0];
> 		byteArrayType = byteArray.getClass();
> 		typeConverterMap.put(byteArrayType, BYTE_ARRAY_CONVERTER);
> 		typeConverterMap.put(Date.class, DATE_CONVERTER);
> 		typeConverterMap.put(Boolean.class, BOOLEAN_CONVERTER);
> 		typeConverterMap.put(String.class, STRING_CONVERTER);
> 		typeConverterMap.put(Integer.class, INTEGER_CONVERTER);
> 		typeConverterMap.put(BigInteger.class, BIG_INTEGER_CONVERTER);
> 		typeConverterMap.put(Long.class, LONG_CONVERTER);
> 		typeConverterMap.put(Double.class, DOUBLE_CONVERTER);
> 		typeConverterMap.put(UriRef.class, URIREF_CONVERTER);
> 	}
> This then allows one to write code such as
> 	implicit def string2lit(str: String) = new PlainLiteralScala(str)
> 	implicit def date2lit(date: Date) = DATE_CONVERTER.createTypedLiteral(date)
> 	implicit def int2lit(int: Int) = INTEGER_CONVERTER.createTypedLiteral(int)
> 	implicit def bigint2lit(bint: BigInt) = BIG_INTEGER_CONVERTER.createTypedLiteral(bint.underlying())
> 	implicit def bigint2lit(bigInt: BigInteger) = BIG_INTEGER_CONVERTER.createTypedLiteral(bigInt)
> 	implicit def bool2lit(boolean: Boolean) = BOOLEAN_CONVERTER.createTypedLiteral(boolean)
> 	implicit def scalaBool2lit(boolean: scala.Boolean) = BOOLEAN_CONVERTER.createTypedLiteral(boolean)
> 	implicit def long2lit(long: Long) = LONG_CONVERTER.createTypedLiteral(long)
> 	implicit def double2lit(double: Double) = DOUBLE_CONVERTER.createTypedLiteral(double)
> Saving on the hash lookup and iterations in these cases where it really is not necessary

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira