@@ -0,0 +1,1694 @@
+// Copyright (c) 2003 Brian Wellington (bwelling@xbill.org)%0A%0Apackage org.xbill.DNS;%0A%0A/**%0A * Helper functions for doing serial arithmetic.  These should be used when%0A * setting/checking SOA serial numbers.%0A *%0A * @author Brian Wellington%0A */%0A%0Apublic final class Serial %7B%0A%0Aprivate static final long MAX32 = 0xFFFFFFFFL;%0A%0Aprivate%0ASerial() %7B%0A%7D%0A%0A/**%0A * Compares two numbers using serial arithmetic.  The numbers are assumed%0A * to be 32 bit unsigned integers stored in longs.%0A * @param serial1 The first integer%0A * @param serial2 The second integer%0A * @return 0 if the 2 numbers are equal, a positive number if serial1 is greater%0A * than serial2, and a negative number if serial2 is greater than serial1.%0A * @throws IllegalArgumentException serial1 or serial2 is out of range%0A */%0Apublic static int%0Acompare(long serial1, long serial2) %7B%0A%09if (serial1 %3C 0 %7C%7C serial1 %3E MAX32)%0A%09%09throw new IllegalArgumentException(serial1 + %22 out of range%22);%0A%09if (serial2 %3C 0 %7C%7C serial2 %3E MAX32)%0A%09%09throw new IllegalArgumentException(serial2 + %22 out of range%22);%0A%09long diff = serial1 - serial2;%0A%09if (diff %3E= MAX32)%0A%09%09diff -= (MAX32 + 1);%0A%09else if (diff %3C -MAX32)%0A%09%09diff += (MAX32 + 1);%0A%09return (int)diff;%0A%7D%0A%0A/**%0A * Increments a serial number.  The number is assumed to be a 32 bit unsigned%0A * integer stored in a long.  This basically adds 1 and resets the value to%0A * 0 if it is 2%5E32.%0A * @param val The serial number%0A * @return The incremented serial number%0A * @throws IllegalArgumentException serial is out of range%0A */%0Apublic static long%0Aincrement(long serial) %7B%0A%09if (serial %3C 0 %7C%7C serial %3E MAX32)%0A%09%09throw new IllegalArgumentException(serial + %22 out of range%22);%0A%09if (serial == MAX32)%0A%09%09return 0;%0A%09return serial + 1;%0A%7D%0A%0A%7D%0A

Add a class for doing serial arithmetic.