Inheritance: global::java.lang.IllegalArgumentException
Example #1
0
        /// <summary>
        /// Compare this package's specification version with a
        /// desired version. It returns true if
        /// this packages specification version number is greater than or equal
        /// to the desired version number. <para>
        ///
        /// Version numbers are compared by sequentially comparing corresponding
        /// components of the desired and specification strings.
        /// Each component is converted as a decimal integer and the values
        /// compared.
        /// If the specification value is greater than the desired
        /// value true is returned. If the value is less false is returned.
        /// If the values are equal the period is skipped and the next pair of
        /// components is compared.
        ///
        /// </para>
        /// </summary>
        /// <param name="desired"> the version string of the desired version. </param>
        /// <returns> true if this package's version number is greater
        ///          than or equal to the desired version number
        /// </returns>
        /// <exception cref="NumberFormatException"> if the desired or current version
        ///          is not of the correct dotted form. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean isCompatibleWith(String desired) throws NumberFormatException
        public virtual bool IsCompatibleWith(String desired)
        {
            if (SpecVersion == reflect.AnnotatedElement_Fields.Null || SpecVersion.Length() < 1)
            {
                throw new NumberFormatException("Empty version string");
            }

            String[] sa = SpecVersion.Split("\\.", -1);
            int[]    si = new int[sa.Length];
            for (int i = 0; i < sa.Length; i++)
            {
                si[i] = Convert.ToInt32(sa[i]);
                if (si[i] < 0)
                {
                    throw NumberFormatException.ForInputString("" + si[i]);
                }
            }

            String[] da = desired.Split("\\.", -1);
            int[]    di = new int[da.Length];
            for (int i = 0; i < da.Length; i++)
            {
                di[i] = Convert.ToInt32(da[i]);
                if (di[i] < 0)
                {
                    throw NumberFormatException.ForInputString("" + di[i]);
                }
            }

            int len = System.Math.Max(di.Length, si.Length);

            for (int i = 0; i < len; i++)
            {
                int d = (i < di.Length ? di[i] : 0);
                int s = (i < si.Length ? si[i] : 0);
                if (s < d)
                {
                    return(false);
                }
                if (s > d)
                {
                    return(true);
                }
            }
            return(true);
        }
Example #2
0
        public static long parseLong(String s, int radix)
        {
            if (s == null)
            {
                throw new NumberFormatException("null");
            }
            if (radix < Character.MIN_RADIX)
            {
                throw new NumberFormatException("radix " + radix +
                                                " less than Character.MIN_RADIX");
            }
            if (radix > Character.MAX_RADIX)
            {
                throw new NumberFormatException("radix " + radix +
                                                " greater than Character.MAX_RADIX");
            }
            long    result = 0;
            boolean negative = false;
            int     i = 0, len = s.length();
            long    limit = -Long.MAX_VALUE;
            long    multmin;
            int     digit;

            if (len > 0)
            {
                char firstChar = s.charAt(0);
                if (firstChar < '0') // Possible leading "+" or "-"
                {
                    if (firstChar == '-')
                    {
                        negative = true;
                        limit    = Long.MIN_VALUE;
                    }
                    else if (firstChar != '+')
                    {
                        throw NumberFormatException.forInputString(s);
                    }
                    if (len == 1) // Cannot have lone "+" or "-"
                    {
                        throw NumberFormatException.forInputString(s);
                    }
                    i++;
                }
                multmin = limit / radix;
                while (i < len)
                {
                    // Accumulating negatively avoids surprises near MAX_VALUE
                    digit = Character.digit(s.charAt(i++), radix);
                    if (digit < 0)
                    {
                        throw NumberFormatException.forInputString(s);
                    }
                    if (result < multmin)
                    {
                        throw NumberFormatException.forInputString(s);
                    }
                    result *= radix;
                    if (result < limit + digit)
                    {
                        throw NumberFormatException.forInputString(s);
                    }
                    result -= digit;
                }
            }
            else
            {
                throw NumberFormatException.forInputString(s);
            }
            return(negative ? result : -result);
        }
Example #3
0
        public static int parseInt(String s, int radix)
        {
            /*
             * WARNING: This method may be invoked early during VM initialization
             * before IntegerCache is initialized. Care must be taken to not use
             * the valueOf method.
             */
            if (s == null)
            {
                throw new NumberFormatException("null");
            }
            if (radix < Character.MIN_RADIX)
            {
                throw new NumberFormatException("radix " + radix +
                                                " less than Character.MIN_RADIX");
            }
            if (radix > Character.MAX_RADIX)
            {
                throw new NumberFormatException("radix " + radix +
                                                " greater than Character.MAX_RADIX");
            }
            int     result = 0;
            boolean negative = false;
            int     i = 0, len = s.length();
            int     limit = -Integer.MAX_VALUE;
            int     multmin;
            int     digit;

            if (len > 0)
            {
                char firstChar = s.charAt(0);
                if (firstChar < '0') // Possible leading "+" or "-"
                {
                    if (firstChar == '-')
                    {
                        negative = true;
                        limit    = Integer.MIN_VALUE;
                    }
                    else if (firstChar != '+')
                    {
                        throw NumberFormatException.forInputString(s);
                    }
                    if (len == 1) // Cannot have lone "+" or "-"
                    {
                        throw NumberFormatException.forInputString(s);
                    }
                    i++;
                }
                multmin = limit / radix;
                while (i < len)
                {
                    // Accumulating negatively avoids surprises near MAX_VALUE
                    digit = Character.digit(s.charAt(i++), radix);
                    if (digit < 0)
                    {
                        throw NumberFormatException.forInputString(s);
                    }
                    if (result < multmin)
                    {
                        throw NumberFormatException.forInputString(s);
                    }
                    result *= radix;
                    if (result < limit + digit)
                    {
                        throw NumberFormatException.forInputString(s);
                    }
                    result -= digit;
                }
            }
            else
            {
                throw NumberFormatException.forInputString(s);
            }
            return(negative ? result : -result);
        }