I started introducing TypeName (starting from ValueType) and by now it has
cleaned up already quite a lot of code and
duplication. What do you think about encapsulating the ugly "String" type name
(inferred from classes, strings etc) to a
concrete type?
By now it looks like that:
package org.qi4j.spi.entity;
import java.lang.reflect.Type;
import org.qi4j.api.util.Classes;
public class TypeName
{
private final String typeName;
public static TypeName nameOf( Class type )
{
if (type==null) throw new IllegalArgumentException( "type must not be
null ");
return new TypeName( type.getName() );
}
public static TypeName nameOf( Type type )
{
return nameOf( Classes.getRawClass( type ) );
}
public static TypeName nameOf( String typeName ) {
return new TypeName(typeName);
}
private TypeName( String typeName )
{
if( typeName == null || typeName.trim().length() == 0 )
{
throw new IllegalArgumentException( "typeName must not be null or
empty" );
}
this.typeName = typeName;
}
public String normalizeToURI()
{
return Classes.normalizeClassToURI( typeName );
}
public String toURI()
{
return Classes.toURI( typeName );
}
public String typeName()
{
return typeName;
}
@Override public String toString()
{
return typeName;
}
public boolean isClass(final Class<?> type) {
return type.getName().equals(typeName);
}
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final TypeName other = (TypeName) o;
return typeName.equals(other.typeName);
}
public int hashCode() {
return typeName.hashCode();
}
}
Am 28.02.2009 2:46 Uhr, schrieb Rickard Öberg:
> Michael Hunger wrote:
>> Ok, then at least stick with Niclas suggestion of having a class
>> encapsulating this and not having the MD5 and
>> UnsupportedEncodingExceptiosn leak into all kinds of types of qi4j ...
>
> Right.
>
> But the code refers to "SHA" as the algorithm... my crypto is not up to
> date, so maybe that is the same as MD5...?
>
> /Rickard
>
> _______________________________________________
> qi4j-dev mailing list
> [email protected]
> http://lists.ops4j.org/mailman/listinfo/qi4j-dev
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev