Пример #1
0
 /**
  * Returns a CosInt instance with the given value.
  *
  * @param val integer value
  * @return CosInt instance
  */
 public static CosInt Get(long val)
 {
     if (Low <= val && val <= High)
     {
         int index = (int)val - Low;
         // no synchronization needed
         if (Static[index] == null)
         {
             Static[index] = new CosInt(val);
         }
         return(Static[index]);
     }
     return(new CosInt(val));
 }
Пример #2
0
        /**
         * This factory method will get the appropriate number object.
         *
         * @param number The string representation of the number.
         *
         * @return A number object, either float or int.
         *
         * @throws IOException If the string is not a number.
         */
        public static ICosNumber get(string value)
        {
            if (value.Length == 1)
            {
                char digit = value[0];
                if ('0' <= digit && digit <= '9')
                {
                    return(CosInt.Get(digit - '0'));
                }
                else if (digit == '-' || digit == '.')
                {
                    // See https://issues.apache.org/jira/browse/PDFBOX-592
                    return(CosInt.Zero);
                }
                else
                {
                    throw new ArgumentException($"Not a number: {value}");
                }
            }
            else if (value.IndexOf('.') == -1 && (value.ToLower().IndexOf('e') == -1))
            {
                try
                {
                    if (value[0] == '+')
                    {
                        return(CosInt.Get(long.Parse(value.Substring(1))));
                    }
                    return(CosInt.Get(long.Parse(value)));
                }
                catch (FormatException e)
                {
// might be a huge number, see PDFBOX-3116
                    return(new CosFloat(value));
                }
            }
            else
            {
                return(new CosFloat(value));
            }
        }
Пример #3
0
 protected bool Equals(CosInt other)
 {
     return(value == other?.value);
 }
Пример #4
0
 /**
  * Set the value in the array as an integer.
  *
  * @param index The index into the array.
  * @param value The value to set.
  */
 public void setInt(int index, int value)
 {
     set(index, CosInt.Get(value));
 }
Пример #5
0
 /**
  * This will set an object at a specific index.
  *
  * @param index zero based index into array.
  * @param intVal The object to set.
  */
 public void set(int index, int intVal)
 {
     set(index, CosInt.Get(intVal));
 }