/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ /** * * @author Uwe Schmidt * * eine Klasse fuer natuerliche Zahlen ab 1 * mit den Ordnungsoperationen ==, !=, >=, >, <=, < * * die Ordnungs Klasse wird hier beerbt, * dadurch muessen nur == und >= * in dieser Klasse implementiert werden, * im Gegensatz zur Nat0 Klasse * * Unterschied: interface <--> abstract class * */ //-------------------- public class Nat1 extends AbstractOrdering { //-------------------- // die Variable fuer die Zahl protected long n; //-------------------- // die Konstruktoren public Nat1() { n = 1; } public Nat1(long n) { assert n >= 1 : "argument <= 0"; this.n = n; } public Nat1(int n) { this((long)n); } //-------------------- // die Zugriffs-Funktionen public int intValue() { return (int)n; } public long longValue() { return n; } //-------------------- // eine Hilfsfunktion // zur Typueberpruefung protected void assertNat1(Object o2) { assert (o2 instanceof Nat1) : "not a Nat1 object"; } //-------------------- // die Vergleichsfunktionen // nur == und >= // muessen implementiert werden public boolean eq(Object o2) { assertNat1(o2); return n == ((Nat1)o2).n; } public boolean ge(Object o2) { assertNat1(o2); return n >= ((Nat1)o2).n; } } //--------------------