Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  
  package bpiwowar.argparser.handlers;
  
  
  
A generic value handler

Author(s):
B. Piwowarski
 

Author(s):
bpiwowar
 
 public abstract class Handler {
     final static private Logger LOGGER = Logger.getLogger(Handler.class);

    
Our checkers
 
     private ArrayList<ValueCheckercheckers = new ArrayList<ValueChecker>();

    
Check the value

Parameters:
value The object value
Throws:
bpiwowar.argparser.IllegalArgumentValue
 
     void check(Object valuethrows IllegalArgumentValue {
         .debug(String.format("We have %d check(s) to do".size()));
         for (ValueChecker checker : ) {
             .debug(String.format("Checking with %s"checker));
             boolean check = checker.check(value);
             if (!check) {
                 .debug("Error in argument " + value);
                 throw new IllegalArgumentValue("Checker error: <<" + value
                         + ">> " + checker.getDescription());
             }
         }
     }

    
Gets a new limit checker

Parameters:
scanner The string scanner
Returns:
a new limit checker
Throws:
bpiwowar.argparser.StringScanException If a scan error occurs
 
     public Limit getLimitChecker(StringScanner scanner)
             throws IllegalArgumentExceptionStringScanException {
         throw new IllegalArgumentException(
                 "Bound cannot be defined for holder " + this);
     }
 
     final public Limit getLimitChecker(Type typeStringScanner scanner)
             throws IllegalArgumentExceptionStringScanException {
         Limit limitChecker = getLimitChecker(scanner);
         limitChecker.setType(type);
         return limitChecker;
     }

    
Is this a help option?

Returns:
true if the option is help option
 
     public boolean isHelpOption() {
         return false;
     }

    
Add a value checker

Parameters:
newChecker the checker to add (or to replace)
 
 
     public void add(ValueChecker newChecker) {
         .debug("Adding a new value checker: " + newChecker + " for "
                 + this);
         .add(newChecker);
     }

    
Scan a range specification, and add the interval checks to the value handler

Parameters:
orChecker The condition
s The string to parse
Throws:
java.lang.IllegalArgumentException TODO
bpiwowar.argparser.StringScanException TODO
    public void updateRangeChecker(OrChecker orCheckerString s)
            throws IllegalArgumentExceptionStringScanException {
        StringScanner scanner = new StringScanner(s);
        char c;
        scanner.setStringDelimiters(")],}");
        c = scanner.getc(); // swallow the first '{'
        scanner.skipWhiteSpace();
        while ((c = scanner.peekc()) != '}') {
            if (c == '[' || c == '(') {
                AndCheckers rangeChecker = new AndCheckers();
                final char c0 = scanner.getc(); // record & swallow
                // character
                scanner.skipWhiteSpace();
                Limit limitChecker = getLimitChecker(scanner);
                limitChecker.setType(c0 == '(' ? ..
                        : ..);
                rangeChecker.add(limitChecker);
                scanner.skipWhiteSpace();
                if (scanner.getc() != ',')
                    throw new IllegalArgumentException(
                            "Missing ',' in subrange specification");
                limitChecker = getLimitChecker(scanner);
                rangeChecker.add(limitChecker);
                scanner.skipWhiteSpace();
                final char c1 = scanner.getc();
                if (c1 != ']' && c1 != ')')
                    throw new IllegalArgumentException("Unterminated subrange");
                limitChecker.setType(c1 == '(' ? ..
                        : ..);
                scanner.skipWhiteSpace();
                // Add the range checker
                orChecker.add(rangeChecker);
            } else {
                scanner.skipWhiteSpace();
                // Add the equality checker
                orChecker.add(getLimitChecker(.scanner));
            }
            scanner.skipWhiteSpace();
            if ((c = scanner.peekc()) == ',') {
                scanner.getc();
                scanner.skipWhiteSpace();
            } else if (c != '}') {
                throw new IllegalArgumentException(
                        "Range spec: ',' or '}' expected (got " + c + ")");
            }
        }
    }

    
Get a range checker

Parameters:
rangeDesc The range description
Returns:
The checker
Throws:
java.lang.IllegalArgumentException TODO
bpiwowar.argparser.StringScanException TODO
    public OrChecker getRangeChecker(String rangeDesc)
            throws IllegalArgumentExceptionStringScanException {
        OrChecker orChecker = new OrChecker();
        updateRangeChecker(orCheckerrangeDesc);
        return orChecker;
    }

    
Parse the arguments from the current index

Parameters:
argParser the argument parser
args The set of arguments
idx The index of the next argument at process
Returns:
The error code
Throws:
bpiwowar.argparser.ArgParseException If some argument related error occurs
bpiwowar.argparser.StringScanException If the string could not be parsed
bpiwowar.argparser.IllegalArgumentValue If the parameter is not OK
    abstract public int parse(ArgParser argParserString[] argsint idx)
            throws ArgParserException;


    
Called by bpiwowar.argparser.ArgParser when the argument had a prefix (to handle the case of prefix chains)

Parameters:
prefix The prefix
    public void setPrefix(String prefix) {
    }

    
Process the annotations
    public void processAnnotations() {
    }
New to GrepCode? Check out our FAQ X