@Override @SuppressWarnings("unchecked") public Class<? extends IExternalConverter> convert(String value) { try { return (Class<? extends IExternalConverter>) Class.forName(value); } catch (ClassNotFoundException e) { throw new ValueConversionException("Not a class name or not on class path: " + value, e); } }
@Override public T convert(String input) { try { return Enum.valueOf(enumClass, input.toUpperCase()); } catch (IllegalArgumentException e) { throw new ValueConversionException("Unrecognized value for enum " + enumClass.getSimpleName() + ": '" + input + "'."); } }
/** {@inheritDoc} */ public String convert( String value ) { if ( !pattern.matcher( value ).matches() ) { throw new ValueConversionException( "Value [" + value + "] did not match regex [" + pattern.pattern() + ']' ); } return value; }
/** {@inheritDoc} */ public String convert( String value ) { if ( !pattern.matcher( value ).matches() ) { throw new ValueConversionException( "Value [" + value + "] did not match regex [" + pattern.pattern() + ']' ); } return value; }
@Override public T convert(String input) { try { return Enum.valueOf(enumClass, input.toUpperCase()); } catch (IllegalArgumentException e) { throw new ValueConversionException("Unrecognized value for enum " + enumClass.getSimpleName() + ": '" + input + "'."); } }
/** {@inheritDoc} */ public String convert( String value ) { if ( !pattern.matcher( value ).matches() ) { throw new ValueConversionException( "Value [" + value + "] did not match regex [" + pattern.pattern() + ']' ); } return value; }
public String convert( String value ) { if ( value.equalsIgnoreCase("true") || value.equalsIgnoreCase("t")) { return "true"; } else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("f")) { return "false"; } else { throw new ValueConversionException(value + " does not match one of T|True|F|False"); } } public final Class<? extends String> valueType() {
public InetAddress convert( String value ) { try { return InetAddress.getByName( value ); } catch ( UnknownHostException e ) { throw new ValueConversionException( message( value ) ); } }
public Date convert( String value ) { ParsePosition position = new ParsePosition( 0 ); Date date = formatter.parse( value, position ); if ( position.getIndex() != value.length() ) throw new ValueConversionException( message( value ) ); return date; }
private void raiseValueConversionFailure( String value ) { String message = message( Locale.getDefault(), "joptsimple.ExceptionMessages", RegexMatcher.class, "message", value, pattern.pattern() ); throw new ValueConversionException( message ); } }
@Override public Date convert( String value ) { ParsePosition position = new ParsePosition( 0 ); Date date = formatter.parse( value, position ); if ( position.getIndex() != value.length() ) throw new ValueConversionException( message( value ) ); return date; }
@Override public Pair<String, String> convert(String input) { int eqPos = input.indexOf('='); if (eqPos == -1) { throw new ValueConversionException("Parameter should be in the form key=value, which the " + "following is not: '" + input + "'."); } String key = input.substring(0, eqPos).trim(); String value = input.substring(eqPos + 1).trim(); return Pair.newPair(key, value); }
@Override public InetAddress convert( String value ) { try { return InetAddress.getByName( value ); } catch ( UnknownHostException e ) { throw new ValueConversionException( message( value ) ); } }
/** {@inheritDoc} */ public Date convert( String value ) { ParsePosition position = new ParsePosition( 0 ); Date date = formatter.parse( value, position ); if ( position.getIndex() != value.length() ) throw new ValueConversionException( message( value ) ); return date; }
/** {@inheritDoc} */ public Date convert( String value ) { ParsePosition position = new ParsePosition( 0 ); Date date = formatter.parse( value, position ); if ( position.getIndex() != value.length() ) throw new ValueConversionException( message( value ) ); return date; }
private void raiseValueConversionFailure( String value ) { String message = message( Locale.getDefault(), "joptsimple.ExceptionMessages", RegexMatcher.class, "message", value, pattern.pattern() ); throw new ValueConversionException( message ); } }
@Override public Pair<String, String> convert(String input) { int eqPos = input.indexOf('='); if (eqPos == -1) { throw new ValueConversionException("Parameter should be in the form key=value, which the " + "following is not: '" + input + "'."); } String key = input.substring(0, eqPos).trim(); String value = input.substring(eqPos + 1).trim(); return Pair.newPair(key, value); }
/** {@inheritDoc} */ public Date convert( String value ) { ParsePosition position = new ParsePosition( 0 ); Date date = formatter.parse( value, position ); if ( position.getIndex() != value.length() ) throw new ValueConversionException( message( value ) ); return date; }
@Override public Level convert(String value) { value = value.toLowerCase(); if (value.equals(LEVEL_OFF)) { return Level.OFF; } else if (value.equals(LEVEL_ERROR)) { return Level.ERROR; } else if (value.equals(LEVEL_WARN)) { return Level.WARN; } else if (value.equals(LEVEL_INFO)) { return Level.INFO; } else if (value.equals(LEVEL_DEBUG)) { return Level.DEBUG; } else if (value.equals(LEVEL_TRACE)) { return Level.TRACE; } else if (value.equals(LEVEL_ALL)) { return Level.ALL; } else { throw new ValueConversionException("No valid log level: " + value); } }
@Override public E convert( String value ) { for ( E each : valueType().getEnumConstants() ) { if ( each.name().equalsIgnoreCase( value ) ) { return each; } } throw new ValueConversionException( message( value ) ); }