org.hd.d.pg2k.svrCore
Class AddrTools.AddrPrefix

java.lang.Object
  extended by org.hd.d.pg2k.svrCore.AddrTools.AddrPrefix
All Implemented Interfaces:
java.lang.Comparable<AddrTools.AddrPrefix>, MemoryTools.Internable
Enclosing class:
AddrTools

public static final class AddrTools.AddrPrefix
extends java.lang.Object
implements java.lang.Comparable<AddrTools.AddrPrefix>, MemoryTools.Internable

Immutable store of a non-null, non-zero-length unsigned-byte IP(v4) address prefix.


Field Summary
private  byte[] prefix
          Address prefix, non-zero-length, non-null.
 
Constructor Summary
AddrTools.AddrPrefix(AddrTools.AddrPrefix ap, int len)
          Create a shorter (but non-zero-length) instance from an existing prefix.
AddrTools.AddrPrefix(byte[] addrPrefix)
          Create an instance from a non-null, non-zero-length byte array.
AddrTools.AddrPrefix(byte[] addrPrefix, int len)
          Create an instance from the prefix of a non-null, non-zero-length byte array.
AddrTools.AddrPrefix(java.lang.String s)
          Create an instance by parsing a padded dotted prefix format.
 
Method Summary
 int compareTo(AddrTools.AddrPrefix other)
          Sorted as if in a dictionary with the bytes treated as unsigned.
 boolean equals(java.lang.Object obj)
          Equal if the prefixes are the same length and have the same content.
 int hashCode()
          Compute hash based on the assumption that most prefixes are 1--3 bytes long.
 boolean isStrictPrefix(AddrTools.AddrPrefix other)
          Returns true if the argument is a strict prefix of this value.
 int length()
          Get the prefix length, in bytes; strictly positive.
 byte[] toByteArray()
          Get a copy of the byte[] prefix data; never null.
 java.lang.String toPaddedDottedPrefix()
          Print as padded dotted prefix; never null.
 java.lang.String toString()
          Human-readable representation; currently equivalent to toPaddedDottedPrefix(); never null.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

prefix

private final byte[] prefix
Address prefix, non-zero-length, non-null.

Constructor Detail

AddrTools.AddrPrefix

public AddrTools.AddrPrefix(byte[] addrPrefix)
Create an instance from a non-null, non-zero-length byte array. Takes a copy of the prefix data.

Parameters:
addrPrefix - prefix of address; non-null

AddrTools.AddrPrefix

public AddrTools.AddrPrefix(byte[] addrPrefix,
                            int len)
Create an instance from the prefix of a non-null, non-zero-length byte array.


AddrTools.AddrPrefix

public AddrTools.AddrPrefix(AddrTools.AddrPrefix ap,
                            int len)
Create a shorter (but non-zero-length) instance from an existing prefix.


AddrTools.AddrPrefix

public AddrTools.AddrPrefix(java.lang.String s)
                     throws java.lang.IllegalArgumentException
Create an instance by parsing a padded dotted prefix format. This is tolerant and does not insist that the octets are padded with zeros on the left.

Can be performance-critical, especially at start-up, so hand-crafted for speed and to avoid creating unnecessary objects.

Parameters:
s - dotted prefix of form n(.n)* eg 127.0.0 or 10.0 or 10.000; there must be at least one octet, and each octet must be between 1 and 3 digits long
Throws:
java.lang.IllegalArgumentException - if the value is unparsable or not at least one octet
Method Detail

length

public int length()
Get the prefix length, in bytes; strictly positive.


isStrictPrefix

public boolean isStrictPrefix(AddrTools.AddrPrefix other)
Returns true if the argument is a strict prefix of this value.


compareTo

public int compareTo(AddrTools.AddrPrefix other)
Sorted as if in a dictionary with the bytes treated as unsigned.

Specified by:
compareTo in interface java.lang.Comparable<AddrTools.AddrPrefix>

hashCode

public int hashCode()
Compute hash based on the assumption that most prefixes are 1--3 bytes long. All bytes should be involved in the hash for it to be effective since prefixes are likely to be dense in maps, etc.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Equal if the prefixes are the same length and have the same content.

Overrides:
equals in class java.lang.Object

toByteArray

public byte[] toByteArray()
Get a copy of the byte[] prefix data; never null.


toPaddedDottedPrefix

public java.lang.String toPaddedDottedPrefix()
Print as padded dotted prefix; never null.


toString

public java.lang.String toString()
Human-readable representation; currently equivalent to toPaddedDottedPrefix(); never null.

Overrides:
toString in class java.lang.Object

DHD Multimedia Gallery V1.60.69

Copyright (c) 1996-2012, Damon Hart-Davis. All rights reserved.