commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jke...@apache.org
Subject cvs commit: jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation UrlValidator.java FileValidator.java NumberValidator.java InvalidArgumentException.java
Date Mon, 20 Oct 2003 21:46:13 GMT
jkeyes      2003/10/20 14:46:13

  Modified:    cli/src/java/org/apache/commons/cli2/validation
                        UrlValidator.java FileValidator.java
                        NumberValidator.java InvalidArgumentException.java
  Log:
  
- removed TABs
  
  Revision  Changes    Path
  1.3       +38 -37    jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/UrlValidator.java
  
  Index: UrlValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/UrlValidator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UrlValidator.java	20 Oct 2003 21:40:44 -0000	1.2
  +++ UrlValidator.java	20 Oct 2003 21:46:13 -0000	1.3
  @@ -70,40 +70,41 @@
    */
   public class UrlValidator implements Validator {
   
  -	private String protocol = null;
  +    private String protocol = null;
   
  -	/* (non-Javadoc)
  -	 * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
  -	 */
  -	public void validate(final List values) throws InvalidArgumentException {
  -		for (final ListIterator i = values.listIterator(); i.hasNext();) {
  -			final String name = (String) i.next();
  -			try {
  -				final URL url = new URL(name);
  +    /* (non-Javadoc)
  +     * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
  +     */
  +    public void validate(final List values) throws InvalidArgumentException {
  +        for (final ListIterator i = values.listIterator(); i.hasNext();) {
  +            final String name = (String) i.next();
  +            try {
  +                final URL url = new URL(name);
   
  -				if (protocol != null && !protocol.equals(url.getProtocol())) {
  -					throw new InvalidArgumentException(name);
  -				}
  +                if (protocol != null && !protocol.equals(url.getProtocol())) {
  +                    throw new InvalidArgumentException(name);
  +                }
   
  -				i.set(url);
  -			} catch (final MalformedURLException mue) {
  -				throw new InvalidArgumentException(
  -					"Cannot understand url: " + name);
  -			}
  -		}
  -	}
  +                i.set(url);
  +            }
  +            catch (final MalformedURLException mue) {
  +                throw new InvalidArgumentException(
  +                    "Cannot understand url: " + name);
  +            }
  +        }
  +    }
   
  -	/**
  -	 * @return
  -	 */
  -	public String getProtocol() {
  -		return protocol;
  -	}
  +    /**
  +     * @return
  +     */
  +    public String getProtocol() {
  +        return protocol;
  +    }
   
  -	/**
  -	 * @param protocol
  -	 */
  -	public void setProtocol(String protocol) {
  -		this.protocol = protocol;
  -	}
  +    /**
  +     * @param protocol
  +     */
  +    public void setProtocol(String protocol) {
  +        this.protocol = protocol;
  +    }
   }
  
  
  
  1.3       +135 -134  jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/FileValidator.java
  
  Index: FileValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/FileValidator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileValidator.java	20 Oct 2003 21:40:44 -0000	1.2
  +++ FileValidator.java	20 Oct 2003 21:46:13 -0000	1.3
  @@ -69,136 +69,137 @@
    */
   public class FileValidator implements Validator {
   
  -	public static FileValidator getExistingInstance() {
  -		final FileValidator validator = new FileValidator();
  -		validator.setExisting(true);
  -		return validator;
  -	}
  -
  -	public static FileValidator getExistingFileInstance() {
  -		final FileValidator validator = new FileValidator();
  -		validator.setExisting(true);
  -		validator.setFile(true);
  -		return validator;
  -	}
  -
  -	public static FileValidator getExistingDirectoryInstance() {
  -		final FileValidator validator = new FileValidator();
  -		validator.setExisting(true);
  -		validator.setDirectory(true);
  -		return validator;
  -	}
  -
  -	private boolean readable = false;
  -	private boolean writable = false;
  -	private boolean existing = false;
  -	private boolean directory = false;
  -	private boolean file = false;
  -	private boolean hidden = false;
  -
  -	/* (non-Javadoc)
  -	 * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
  -	 */
  -	public void validate(final List values) throws InvalidArgumentException {
  -		for (final ListIterator i = values.listIterator(); i.hasNext();) {
  -			final String name = (String) i.next();
  -			final File f = new File(name);
  -
  -			if ((existing && !f.exists())
  -				|| (file && !f.isFile())
  -				|| (directory && !f.isDirectory())
  -				|| (hidden && !f.isHidden())
  -				|| (readable && !f.canRead())
  -				|| (writable && !f.canWrite())) {
  -
  -				throw new InvalidArgumentException(name);
  -			} else {
  -				i.set(f);
  -			}
  -		}
  -	}
  -
  -	/**
  -	 * @return
  -	 */
  -	public boolean isDirectory() {
  -		return directory;
  -	}
  -
  -	/**
  -	 * @param directory
  -	 */
  -	public void setDirectory(boolean directory) {
  -		this.directory = directory;
  -	}
  -
  -	/**
  -	 * @return
  -	 */
  -	public boolean isExisting() {
  -		return existing;
  -	}
  -
  -	/**
  -	 * @param existing
  -	 */
  -	public void setExisting(boolean existing) {
  -		this.existing = existing;
  -	}
  -
  -	/**
  -	 * @return
  -	 */
  -	public boolean isFile() {
  -		return file;
  -	}
  -
  -	/**
  -	 * @param file
  -	 */
  -	public void setFile(boolean file) {
  -		this.file = file;
  -	}
  -
  -	/**
  -	 * @return
  -	 */
  -	public boolean isHidden() {
  -		return hidden;
  -	}
  -
  -	/**
  -	 * @param hidden
  -	 */
  -	public void setHidden(boolean hidden) {
  -		this.hidden = hidden;
  -	}
  -
  -	/**
  -	 * @return
  -	 */
  -	public boolean isReadable() {
  -		return readable;
  -	}
  -
  -	/**
  -	 * @param readable
  -	 */
  -	public void setReadable(boolean readable) {
  -		this.readable = readable;
  -	}
  -
  -	/**
  -	 * @return
  -	 */
  -	public boolean isWritable() {
  -		return writable;
  -	}
  -
  -	/**
  -	 * @param writable
  -	 */
  -	public void setWritable(boolean writable) {
  -		this.writable = writable;
  -	}
  +    public static FileValidator getExistingInstance() {
  +        final FileValidator validator = new FileValidator();
  +        validator.setExisting(true);
  +        return validator;
  +    }
  +
  +    public static FileValidator getExistingFileInstance() {
  +        final FileValidator validator = new FileValidator();
  +        validator.setExisting(true);
  +        validator.setFile(true);
  +        return validator;
  +    }
  +
  +    public static FileValidator getExistingDirectoryInstance() {
  +        final FileValidator validator = new FileValidator();
  +        validator.setExisting(true);
  +        validator.setDirectory(true);
  +        return validator;
  +    }
  +
  +    private boolean readable = false;
  +    private boolean writable = false;
  +    private boolean existing = false;
  +    private boolean directory = false;
  +    private boolean file = false;
  +    private boolean hidden = false;
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
  +     */
  +    public void validate(final List values) throws InvalidArgumentException {
  +        for (final ListIterator i = values.listIterator(); i.hasNext();) {
  +            final String name = (String) i.next();
  +            final File f = new File(name);
  +
  +            if ((existing && !f.exists())
  +                || (file && !f.isFile())
  +                || (directory && !f.isDirectory())
  +                || (hidden && !f.isHidden())
  +                || (readable && !f.canRead())
  +                || (writable && !f.canWrite())) {
  +
  +                throw new InvalidArgumentException(name);
  +            }
  +            else {
  +                i.set(f);
  +            }
  +        }
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public boolean isDirectory() {
  +        return directory;
  +    }
  +
  +    /**
  +     * @param directory
  +     */
  +    public void setDirectory(boolean directory) {
  +        this.directory = directory;
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public boolean isExisting() {
  +        return existing;
  +    }
  +
  +    /**
  +     * @param existing
  +     */
  +    public void setExisting(boolean existing) {
  +        this.existing = existing;
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public boolean isFile() {
  +        return file;
  +    }
  +
  +    /**
  +     * @param file
  +     */
  +    public void setFile(boolean file) {
  +        this.file = file;
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public boolean isHidden() {
  +        return hidden;
  +    }
  +
  +    /**
  +     * @param hidden
  +     */
  +    public void setHidden(boolean hidden) {
  +        this.hidden = hidden;
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public boolean isReadable() {
  +        return readable;
  +    }
  +
  +    /**
  +     * @param readable
  +     */
  +    public void setReadable(boolean readable) {
  +        this.readable = readable;
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public boolean isWritable() {
  +        return writable;
  +    }
  +
  +    /**
  +     * @param writable
  +     */
  +    public void setWritable(boolean writable) {
  +        this.writable = writable;
  +    }
   }
  
  
  
  1.3       +88 -88    jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/NumberValidator.java
  
  Index: NumberValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/NumberValidator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- NumberValidator.java	20 Oct 2003 21:40:44 -0000	1.2
  +++ NumberValidator.java	20 Oct 2003 21:46:13 -0000	1.3
  @@ -70,91 +70,91 @@
    */
   public class NumberValidator implements Validator {
   
  -	public static NumberValidator getCurrencyInstance() {
  -		return new NumberValidator(NumberFormat.getCurrencyInstance());
  -	}
  -
  -	public static NumberValidator getIntegerInstance() {
  -		return new NumberValidator(NumberFormat.getIntegerInstance());
  -	}
  -
  -	public static NumberValidator getPercentInstance() {
  -		return new NumberValidator(NumberFormat.getPercentInstance());
  -	}
  -
  -	public static NumberValidator getNumberInstance() {
  -		return new NumberValidator(NumberFormat.getNumberInstance());
  -	}
  -
  -	private final NumberFormat format;
  -	private Number minimum = null;
  -	private Number maximum = null;
  -
  -	public NumberValidator() {
  -		this(NumberFormat.getInstance());
  -	}
  -
  -	public NumberValidator(final NumberFormat format) {
  -		this.format = format;
  -	}
  -
  -	/* (non-Javadoc)
  -	 * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
  -	 */
  -	public void validate(final List values) throws InvalidArgumentException {
  -		for (final ListIterator i = values.listIterator(); i.hasNext();) {
  -			final String value = (String) i.next();
  -
  -			final ParsePosition pp = new ParsePosition(0);
  -			final Number number = format.parse(value, pp);
  -			if (pp.getIndex() < value.length()) {
  -				throw new InvalidArgumentException(value);
  -			}
  -
  -			if ((minimum != null
  -				&& number.doubleValue() < minimum.doubleValue())
  -				|| (maximum != null
  -					&& number.doubleValue() > maximum.doubleValue())) {
  -				throw new InvalidArgumentException("Out of range: " + value);
  -			}
  -
  -			i.set(number);
  -		}
  -	}
  -
  -	/**
  -	 * @return
  -	 */
  -	public NumberFormat getFormat() {
  -		return format;
  -	}
  -
  -	/**
  -	 * @return
  -	 */
  -	public Number getMaximum() {
  -		return maximum;
  -	}
  -
  -	/**
  -	 * @param maximum
  -	 */
  -	public void setMaximum(Number maximum) {
  -		this.maximum = maximum;
  -	}
  -
  -	/**
  -	 * @return
  -	 */
  -	public Number getMinimum() {
  -		return minimum;
  -	}
  -
  -	/**
  -	 * @param minimum
  -	 */
  -	public void setMinimum(Number minimum) {
  -		this.minimum = minimum;
  -	}
  +    public static NumberValidator getCurrencyInstance() {
  +        return new NumberValidator(NumberFormat.getCurrencyInstance());
  +    }
  +
  +    public static NumberValidator getIntegerInstance() {
  +        return new NumberValidator(NumberFormat.getIntegerInstance());
  +    }
  +
  +    public static NumberValidator getPercentInstance() {
  +        return new NumberValidator(NumberFormat.getPercentInstance());
  +    }
  +
  +    public static NumberValidator getNumberInstance() {
  +        return new NumberValidator(NumberFormat.getNumberInstance());
  +    }
  +
  +    private final NumberFormat format;
  +    private Number minimum = null;
  +    private Number maximum = null;
  +
  +    public NumberValidator() {
  +        this(NumberFormat.getInstance());
  +    }
  +
  +    public NumberValidator(final NumberFormat format) {
  +        this.format = format;
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.commons.cli2.validation.Validator#validate(java.util.List)
  +     */
  +    public void validate(final List values) throws InvalidArgumentException {
  +        for (final ListIterator i = values.listIterator(); i.hasNext();) {
  +            final String value = (String) i.next();
  +
  +            final ParsePosition pp = new ParsePosition(0);
  +            final Number number = format.parse(value, pp);
  +            if (pp.getIndex() < value.length()) {
  +                throw new InvalidArgumentException(value);
  +            }
  +
  +            if ((minimum != null
  +                && number.doubleValue() < minimum.doubleValue())
  +                || (maximum != null
  +                    && number.doubleValue() > maximum.doubleValue())) {
  +                throw new InvalidArgumentException("Out of range: " + value);
  +            }
  +
  +            i.set(number);
  +        }
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public NumberFormat getFormat() {
  +        return format;
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public Number getMaximum() {
  +        return maximum;
  +    }
  +
  +    /**
  +     * @param maximum
  +     */
  +    public void setMaximum(Number maximum) {
  +        this.maximum = maximum;
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public Number getMinimum() {
  +        return minimum;
  +    }
  +
  +    /**
  +     * @param minimum
  +     */
  +    public void setMinimum(Number minimum) {
  +        this.minimum = minimum;
  +    }
   
   }
  
  
  
  1.3       +5 -5      jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/InvalidArgumentException.java
  
  Index: InvalidArgumentException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/validation/InvalidArgumentException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InvalidArgumentException.java	20 Oct 2003 21:40:44 -0000	1.2
  +++ InvalidArgumentException.java	20 Oct 2003 21:46:13 -0000	1.3
  @@ -65,7 +65,7 @@
    */
   public class InvalidArgumentException extends Exception {
   
  -	public InvalidArgumentException(final String message) {
  -		super(message);
  -	}
  +    public InvalidArgumentException(final String message) {
  +        super(message);
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message