public static TypeName nameOf( String typeName ) { return new TypeName( typeName ); }
@Override public int compareTo( QualifiedName other ) { final int result = typeName.compareTo( other.typeName ); if( result != 0 ) { return result; } return name.compareTo( other.name ); } }
@Override public int hashCode() { return 31 * typeName.hashCode() + name.hashCode(); }
public static TypeName nameOf( Type type ) { return nameOf( Classes.RAW_CLASS.map( type ) ); }
/** * Returns the normalized string of the type part of the QualifiedName. * * <p> * The normalized type name means that all dollar ($) characters have been replaced by dashes (-). * </p> * * @return the normalized string of the type part of the QualifiedName. */ public String type() { return typeName.normalized(); }
/** * Return the URI of the {@link TypeName} component of the QualifiedName. * <p> * The URI of the {@link TypeName} component is in the form of; * </p> * <pre> * "urn:qi4j:type:" normalizedClassName * </pre> * <p> * where {@code normalizedClassName} is the fully-qualified class name having had any dollar ($) characters replaced * by URI friendly dashes (-), with a trailing hash (#). Examples; * </p> * <pre> * urn:qi4j:type:org.qi4j.api.common.QualifiedName# * urn:qi4j:type:org.qi4j.samples.MyClass-MyInnerClass# * </pre> * * @return the URI of the {@link TypeName} component of the QualifiedName. */ public String toNamespace() { return typeName.toURI() + "#"; }
@Override public boolean equals( Object o ) { if( this == o ) { return true; } if( o == null || getClass() != o.getClass() ) { return false; } QualifiedName that = (QualifiedName) o; return name.equals( that.name ) && typeName.equals( that.typeName ); }
/** * Creates a Qualified name from a type as string and a name qualifier. * * @param type The type name as a a string, which must be properly formatted. No checks for correctly formatted * type name is performed. * @param name The qualifier name which will be appended to the base name derived from the {@code type} argument. * * @return A QualifiedName instance representing the {@code type} and {@code name} arguments. * * @throws NullArgumentException if any of the two arguments are {@code null} or either string is empty. */ public static QualifiedName fromName( String type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); }
/** * Creates a QualifiedName instance from the Class and a given name. * <p> * This factory method converts the {@code type} to a {@link TypeName} and appends the given {@code name}. * * @param type The Class that is the base of the QualifiedName. * @param name The qualifier name which will be appended to the base name derived from the {@code type} argument. * * @return A QualifiedName instance representing the {@code type} and {@code name} arguments. * * @throws NullArgumentException if any of the two arguments are {@code null}, or if the name string is empty. */ public static QualifiedName fromClass( Class type, String name ) { return new QualifiedName( TypeName.nameOf( type ), name ); }
public static TypeName nameOf( Class type ) { NullArgumentException.validateNotNull( "type", type ); return new TypeName( type.getName() ); }
/** * Creates a QualifiedName from the external string format of QualifiedName. * <p> * This factory method is the reverse of {@link QualifiedName#toString() } method, and creates a new QualifiedName * instance from the string representation of the QualifiedName. * </p> * * @param fullQualifiedName The QualifiedName external string representation to be converted back into a QualifiedName * instance. * * @return The QualifiedName instance represented by the {@code qualifiedName} argument. * * @throws IllegalArgumentException If the {@code qualifiedName} argument has wrong format. */ public static QualifiedName fromFQN( String fullQualifiedName ) { NullArgumentException.validateNotEmpty( "qualifiedName", fullQualifiedName ); int idx = fullQualifiedName.lastIndexOf( ":" ); if( idx == -1 ) { throw new IllegalArgumentException( "Name '" + fullQualifiedName + "' is not a qualified name" ); } final String type = fullQualifiedName.substring( 0, idx ); final String name = fullQualifiedName.substring( idx + 1 ); return new QualifiedName( TypeName.nameOf( type ), name ); }