@ SuppressWarnings ( "unchecked" ) private < T > ParameterConverter < T > getConverter ( Class < T > type ) { // check for String first if ( type == String . class ) { return ( ParameterConverter < T > ) StringConverter . INSTANCE ; } // Search for exposed converters. for ( ParameterConverter pc : converters ) { //noinspection EqualsBetweenInconvertibleTypes if ( pc . getType ( ) . equals ( type ) ) { //NOSONAR return pc ; } } // Boolean has a special case as they support other form of "truth" such as "yes", "on", "1"... if ( type == Boolean . class ) { return ( ParameterConverter < T > ) BooleanConverter . INSTANCE ; } // None of them are there, try default converters in the following order: // 1. constructor // 2. valueOf // 3. from // 4. fromString ParameterConverter < T > converter = ConstructorBasedConverter . getIfEligible ( type ) ; if ( converter != null ) { return converter ; } converter = ValueOfBasedConverter . getIfEligible ( type ) ; if ( converter != null ) { return converter ; } converter = FromBasedConverter . getIfEligible ( type ) ; if ( converter != null ) { return converter ; } converter = FromStringBasedConverter . getIfEligible ( type ) ; if ( converter != null ) { return converter ; } // Unlike other primitive type, characters cannot be created using the 'valueOf' method, // so we need a specific converter. As creating characters is quite rare, this must be the last check. if ( type == Character . class ) { return ( ParameterConverter < T > ) CharacterConverter . INSTANCE ; } // running out of converters... throw new NoSuchElementException ( "Cannot find a converter able to create instance of " + type . getName ( ) ) ; }
Searches a suitable converter to convert String to the given type .