namespace UglyToad.PdfPig.Tokens
{
using System;
using System.Globalization;
///
///
/// PDF supports integer and real numbers. Integer objects represent mathematical integers within a certain interval centered at 0.
/// Real objects approximate mathematical real numbers, but with limited range and precision.
/// This token represents both types and they are used interchangeably in the specification.
///
public class NumericToken : IDataToken
{
///
/// Single instance of numeric token for -1.
///
public static readonly NumericToken MinusOne = new NumericToken(-1);
///
/// Single instance of numeric token for 0.
///
public static readonly NumericToken Zero = new NumericToken(0);
///
/// Single instance of numeric token for 1.
///
public static readonly NumericToken One = new NumericToken(1);
///
/// Single instance of numeric token for 2.
///
public static readonly NumericToken Two = new NumericToken(2);
///
/// Single instance of numeric token for 3.
///
public static readonly NumericToken Three = new NumericToken(3);
///
/// Single instance of numeric token for 4.
///
public static readonly NumericToken Four = new NumericToken(4);
///
/// Single instance of numeric token for 5.
///
public static readonly NumericToken Five = new NumericToken(5);
///
/// Single instance of numeric token for 6.
///
public static readonly NumericToken Six = new NumericToken(6);
///
/// Single instance of numeric token for 7.
///
public static readonly NumericToken Seven = new NumericToken(7);
///
/// Single instance of numeric token for 8.
///
public static readonly NumericToken Eight = new NumericToken(8);
///
/// Single instance of numeric token for 9.
///
public static readonly NumericToken Nine = new NumericToken(9);
///
/// Single instance of numeric token for 10.
///
public static readonly NumericToken Ten = new NumericToken(10);
///
/// Single instance of numeric token for 11.
///
public static readonly NumericToken Eleven = new NumericToken(11);
///
/// Single instance of numeric token for 12.
///
public static readonly NumericToken Twelve = new NumericToken(12);
///
/// Single instance of numeric token for 13.
///
public static readonly NumericToken Thirteen = new NumericToken(13);
///
/// Single instance of numeric token for 14.
///
public static readonly NumericToken Fourteen = new NumericToken(14);
///
/// Single instance of numeric token for 15.
///
public static readonly NumericToken Fifteen = new NumericToken(15);
///
/// Single instance of numeric token for 16.
///
public static readonly NumericToken Sixteen = new NumericToken(16);
///
/// Single instance of numeric token for 17.
///
public static readonly NumericToken Seventeen = new NumericToken(17);
///
/// Single instance of numeric token for 18.
///
public static readonly NumericToken Eighteen = new NumericToken(18);
///
/// Single instance of numeric token for 19.
///
public static readonly NumericToken Nineteen = new NumericToken(19);
///
/// Single instance of numeric token for 20.
///
public static readonly NumericToken Twenty = new NumericToken(20);
///
/// Single instance of numeric token for 100.
///
public static readonly NumericToken OneHundred = new NumericToken(100);
///
/// Single instance of numeric token for 500.
///
public static readonly NumericToken FiveHundred = new NumericToken(500);
///
/// Single instance of numeric token for 1000.
///
public static readonly NumericToken OneThousand = new NumericToken(1000);
///
public double Data { get; }
///
/// Whether the number represented has a non-zero decimal part.
///
public bool HasDecimalPlaces => !Math.Floor(Data).Equals(Data);
///
/// The value of this number as an .
///
public int Int => (int)Data;
///
/// The value of this number as a .
///
public long Long => (long)Data;
///
/// The value of this number as a .
///
public double Double => Data;
///
/// Create a .
///
/// The number to represent.
public NumericToken(int value)
{
Data = value;
}
///
/// Create a .
///
/// The number to represent.
public NumericToken(double value)
{
Data = value;
}
///
public bool Equals(IToken obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}
if (!(obj is NumericToken other))
{
return false;
}
return Data.Equals(other.Data);
}
///
public override int GetHashCode()
{
return Data.GetHashCode();
}
///
public override string ToString()
{
return Data.ToString(NumberFormatInfo.InvariantInfo);
}
}
}