1  /*
     2   * Copyright the original author or authors.
     3   * 
     4   * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   * 
     8   *      http://www.mozilla.org/MPL/MPL-1.1.html
     9   * 
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  import org.as2lib.core.BasicInterface;
    18  import org.as2lib.data.type.NumberFormatException;
    19  
    20  /**
    21   * {@code Integer} represents an integer value.
    22   *
    23   * <p>A integer is a positive or negative natural number including 0.
    24   * 
    25   * @author Martin Heidegger.
    26   */
    27  class org.as2lib.data.type.Integer extends Number implements BasicInterface {
    28  	
    29  	/** The actual integer. */
    30  	private var int:Number;
    31  	
    32  	/**
    33  	 * Constructs a new {@code Integer} instance.
    34  	 *
    35  	 * <p>The passed-in {@code number} is transformed into an integer. The {@code number}
    36  	 * will be floored so that only the base will be used as integer, if it has decimal
    37  	 * places.
    38  	 * 
    39  	 * @param number the number to convert to an integer
    40  	 * @throws NumberFormatException if the passed-in {@code number} is infinity or
    41  	 * -infinity.
    42  	 */
    43  	public function Integer(number:Number) {
    44  		if (number == Infinity || number == -Infinity) {
    45  			throw new NumberFormatException("Infinity is not evaluateable as integer", this, arguments);
    46  		} else {
    47  			int = number - number%1;
    48  		}
    49  	}
    50  	
    51  	/**
    52  	 * Returns this integer as number.
    53  	 * 
    54  	 * @return this integer as number
    55  	 */
    56  	public function valueOf(Void):Number {
    57  		return int;
    58  	}
    59  	
    60  	/**
    61  	 * Returns the string representation of this integer.
    62  	 * 
    63  	 * @return the string representation of this integer
    64  	 */
    65  	public function toString():String {
    66  		return int.toString();
    67  	}
    68  
    69  }