Rev 221 | Rev 224 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
public class IPAddr{private int[] fields = new int[4];public IPAddr (String ip){int i;String[] sp = ip.split("\\.");for (i=0; i<sp.length; i++)fields[i] = Integer.parseInt(sp[i]);}public int getField (int fieldNum){return fields[fieldNum];}public int compareTo (IPAddr ip){int i;for (i=0; i<4; i++)if (fields[i] < ip.getField(i))return -1;else if (fields[i] > ip.getField(i))return 1;return 0; // Equal}public int compareTo (String ip){IPAddr that = new IPAddr (ip);return this.compareTo(that);}public String toString (){String s = new String("" + fields[0] + '.' + fields[1] + '.'+ fields[2] + '.' + fields[3]);return s;}}