Package com.martiansoftware.jsap

Examples of com.martiansoftware.jsap.ParseException


   * the resulting size is larger than {@link Long#MAX_VALUE}.
   */
   
  public static long parseSize( final CharSequence s ) throws ParseException {
    final Matcher m = PARSE_SIZE_REGEX.matcher( s );
    if ( ! m.matches() ) throw new ParseException( "Invalid size specification '" + s + "'." );
   
    final String unit = m.group( 3 );

    BigInteger unitSize = BigInteger.ONE;

    if ( unit != null ) {
      Long unitSizeObj = (Long)UNIT2SIZE.get( unit );
      if ( unitSizeObj == null ) throw new ParseException( "Invalid unit specification '" + unit + "'." );
      unitSize = new BigInteger( unitSizeObj.toString() );
    }

    final String number = m.group( 1 );
    final Long size;

    try {
      size = Long.decode( number );
      if ( size.longValue() < 0 ) throw new ParseException( "Sizes cannot be negative." );
    }
    catch( NumberFormatException e ) {
      throw new ParseException( "Invalid number '" + number + "'." );
    }
   
    BigInteger result = new BigInteger( size.toString() ).multiply( unitSize );
   
    if ( result.compareTo( LONG_MAX_VALUE ) > 0 ) throw new ParseException( "Size '" + s + "' is too big." );
   
    return Long.parseLong( result.toString() );
  }
View Full Code Here


        Float result = null;
        try {
            result = new Float(arg);
        } catch (NumberFormatException e) {
            throw (
                new ParseException(
                    "Unable to convert '" + arg + "' to a Float.",
                    e));
        }
        return (result);
    }
View Full Code Here

    {
      result = Integer.decode(arg);
    }
    catch (NumberFormatException nfe)
    {
      throw new ParseException("Unable to convert '" + arg + "' to an Integer.", nfe);
    }

    if (result <= 0)
      throw new ParseException("Value has to be greater than 0.");

    return result;
  }
View Full Code Here

      return keyvalue;
    }
    catch (NumberFormatException nfe)
    {
      throw new ParseException("Unable to parse value in \"" + arg + "\".", nfe);
    }
    catch (Exception e)
    {
      throw new ParseException("Unable to parse key-value pair in \"" + arg + "\".", e);
    }
  }
View Full Code Here

    {
      result = new Double(arg);
    }
    catch (NumberFormatException nfe)
    {
      throw new ParseException("Unable to convert '" + arg + "' to a Double.", nfe);
    }

    if (result <= 0)
      throw new ParseException("Value has to be greater than 0.0.");

    return result;
  }
View Full Code Here

     * @param s the ParseException's message.
     * @return a new ParseException with the specified message.
     */
    private ParseException colorException(String s) {
        return (
            new ParseException("Unable to convert '" + s + "' to a Color."));
    }
View Full Code Here

        URL result = null;
        try {
            result = new URL(arg);
        } catch (MalformedURLException e) {
            throw (
                new ParseException(
                    "Unable to convert '" + arg + "' to a URL.",
                    e));
        }
        return (result);
    }
View Full Code Here

        Long result = null;
        try {
            result = Long.decode(arg);
        } catch (NumberFormatException e) {
            throw (
                new ParseException(
                    "Unable to convert '" + arg + "' to a Long.",
                    e));
        }
        return (result);
    }
View Full Code Here

        Integer result = null;
        try {
            result = Integer.decode(arg);
        } catch (NumberFormatException nfe) {
            throw (
                new ParseException(
                    "Unable to convert '" + arg + "' to an Integer.",
                    nfe));
        }
        return (result);
    }
View Full Code Here

        Class result = null;
        try {
            result = Class.forName(arg);
        } catch (Exception e) {
            throw (
                new ParseException("Unable to locate class '" + arg + "'.", e));
        }
        return (result);
    }
View Full Code Here

TOP

Related Classes of com.martiansoftware.jsap.ParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.