incubator-clerezza-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reto Bachmann-Gmür (JIRA) <j...@apache.org>
Subject [jira] [Closed] (CLEREZZA-511) allow access to individual SimpleLiteralFactory converters
Date Tue, 17 May 2011 23:05:48 GMT

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

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


should have closed them earlier.

> 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

Mime
View raw message