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.data.type.Integer; 18 import org.as2lib.data.type.NumberFormatException; 19 20 /** 21 * {@code NaturalNumber} represents a natural number. 22 * 23 * <p>Natural numbers are positive integers excluding 0 in this case. If you want 24 * to allow 0 use {@code NaturalNumberIncludingZero} instead. 25 * 26 * @author Martin Heidegger 27 * @see org.as2lib.data.type.NaturalNumberIncludingZero 28 */ 29 class org.as2lib.data.type.NaturalNumber extends Integer { 30 31 /** 32 * Constructs a new {@code NaturalNumber} instance. 33 * 34 * <p>Decimal places are cropped from the passed-in {@code number} if it has at least 35 * one. The passed-in {@code number} must also not be negative. 36 * 37 * @param number the natural number 38 * @throws NumberFormatException if the passed-in {@code number} is negative number, 39 * zero or (-)infinity 40 */ 41 public function NaturalNumber(number:Number) { 42 super (number); 43 if (int <= 0) { 44 throw new NumberFormatException("Natural numbers don't inlude negative numbers or numbers that get zero if they were round down, like: "+number+".", this, arguments); 45 } 46 } 47 48 }