Package uk.ipfreely

Class V6

All Implemented Interfaces:
Comparable<V6>

public final class V6 extends Address<V6>
Immutable IPv6 Address and 128-bit unsigned integer value. Use Family.v6() to create values.
  • Method Details

    • family

      public Family<V6> family()
      Description copied from class: Address
      Internet protocol family - V4 or V6.
      Specified by:
      family in class Address<V6>
      Returns:
      address family
    • equals

      public boolean equals(Object other)
      Description copied from class: Address
      Object equality.
      Specified by:
      equals in class Address<V6>
      Parameters:
      other - another object or null
      Returns:
      true if same family and value
    • hashCode

      public int hashCode()
      Description copied from class: Address
      Hash code.
      Specified by:
      hashCode in class Address<V6>
      Returns:
      object hash
    • toString

      public String toString()
      Specified by:
      toString in class Address<V6>
      Returns:
      the address in RFC5952 format
    • compareTo

      public int compareTo(V6 o)
      Useful for sorting.
      Parameters:
      o - another address
      Returns:
      negative, zero, or positive integer as this is less than, equal to, or greater than other address
    • toBigInteger

      public BigInteger toBigInteger()
      Description copied from class: Address
      The address as a BigInteger.
      Specified by:
      toBigInteger in class Address<V6>
      Returns:
      the address as a positive integer
    • toBytes

      public byte[] toBytes()
      Description copied from class: Address
      The address as bytes of length Family.width() / Byte.SIZE.
      Specified by:
      toBytes in class Address<V6>
      Returns:
      the address as a byte sequence, most significant bits first
      See Also:
    • highBits

      public long highBits()
      Description copied from class: Address
      Useful for efficient conversion.
      Specified by:
      highBits in class Address<V6>
      Returns:
      the high part of the value
    • lowBits

      public long lowBits()
      Description copied from class: Address
      Useful for efficient conversion.
      Specified by:
      lowBits in class Address<V6>
      Returns:
      the low part of the value
    • leadingZeros

      public int leadingZeros()
      Description copied from class: Address
      Specified by:
      leadingZeros in class Address<V6>
      Returns:
      number of zero bits preceding the highest-order ("leftmost") one-bit
    • trailingZeros

      public int trailingZeros()
      Description copied from class: Address
      Specified by:
      trailingZeros in class Address<V6>
      Returns:
      number of zero bits following the lowest-order ("rightmost") one-bit
    • doubleValue

      public double doubleValue()
      Description copied from class: Address
      Specified by:
      doubleValue in class Address<V6>
      Returns:
      approximate floating point value
    • add

      public V6 add(V6 addend)
      Description copied from class: Address
      Addition with overflow.
      Specified by:
      add in class Address<V6>
      Parameters:
      addend - the summand
      Returns:
      sum
    • subtract

      public V6 subtract(V6 subtrahend)
      Description copied from class: Address
      Subtraction with underflow.
      Specified by:
      subtract in class Address<V6>
      Parameters:
      subtrahend - number to subtract from this
      Returns:
      difference
    • multiply

      public V6 multiply(V6 multiplicand)
      Description copied from class: Address
      Multiplication with overflow.
      Specified by:
      multiply in class Address<V6>
      Parameters:
      multiplicand - the factor
      Returns:
      product
    • divide

      public V6 divide(V6 denominator)
      Description copied from class: Address
      Division.
      Specified by:
      divide in class Address<V6>
      Parameters:
      denominator - the divisor
      Returns:
      quotient
    • mod

      public V6 mod(V6 denominator)
      Description copied from class: Address
      Modulus.
      Specified by:
      mod in class Address<V6>
      Parameters:
      denominator - the divisor
      Returns:
      remainder
    • and

      public V6 and(V6 operand)
      Description copied from class: Address
      Bitwise AND.
      
           // EXAMPLE
           // LinkLocal is fe80::/10
           private static V6 LL = Family.v6().parse("fe80::");
           private static V6 MASK = Family.v6().subnets().masks().get(10);
      
           public static boolean isLinkLocal(V6 candidate) {
               return MASK.and(candidate).equals(LL);
           }
       
      Specified by:
      and in class Address<V6>
      Parameters:
      operand - the mask address
      Returns:
      the AND'd address
    • or

      public V6 or(V6 operand)
      Description copied from class: Address
      Bitwise OR.
      Specified by:
      or in class Address<V6>
      Parameters:
      operand - the mask address
      Returns:
      the OR'd address
    • xor

      public V6 xor(V6 operand)
      Description copied from class: Address
      Bitwise exclusive OR.
      Specified by:
      xor in class Address<V6>
      Parameters:
      operand - the mask address
      Returns:
      the XOR'd address
    • not

      public V6 not()
      Description copied from class: Address
      Bitwise NOT.
      
           // EXAMPLE
           // Define 192.168.0.0/24
           int maskBits = 24;
           V4 networkAddress = Family.v4().parse("192.168.0.0");
           // 255.255.255.0
           V4 mask = Family.v4().subnets().masks().get(maskBits);
           // 0.0.0.255
           V4 inverseMask = mask.not()
           // 192.168.0.255
           V4 lastAddress = inverseMask.or(networkAddress);
       
      Specified by:
      not in class Address<V6>
      Returns:
      the complement
    • shift

      public V6 shift(int bits)
      Description copied from class: Address
      Bitwise shift. Negative operands shift left. Positive operands shift right. Values exceeding Family.width() overflow as described in The Java Language Specification Java SE 21 Edition 15.19. Shift Operators.
      
           // EXAMPLE
           // 0.0.0.1
           V4 one = Family.v4().parse(1);
           // 0.0.0.2
           V4 two = one.shift(-1);
       
      Specified by:
      shift in class Address<V6>
      Parameters:
      bits - -127 to 127
      Returns:
      shifted value