Package jnr.ffi

Class Address

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Address>

    public final class Address
    extends java.lang.Number
    implements java.lang.Comparable<Address>
    The Address class wraps a native address in an object. Both 32 bit and 64 bit native address values are wrapped in a singular Address type.

    This class extends Number and implements all Number methods for converting to primitive integer types.

    An Address instance is lighter weight than most Pointer instances, and may be used when a native address needs to be stored in java, but no other operations (such as reading/writing values) need be performed on the native memory. For most cases, a Pointer offers more flexibility and should be preferred instead.

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Address​(Address address)
      Creates a new address representation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long address()
      Gets the native memory address represented by this Address as a long integer.
      int compareTo​(Address other)
      Compares two Address instances numerically.
      double doubleValue()
      Returns the value of this Address as a double.
      boolean equals​(java.lang.Object obj)
      Compares this address to another address.
      float floatValue()
      Returns the value of this Address as a float.
      int hashCode()
      Returns a hash code for this Address.
      int intValue()
      Returns the value of this Address as an int.
      boolean isNull()
      Tests if this Address is equivalent to C NULL
      long longValue()
      Returns the value of this Address as a long.
      long nativeAddress()
      Returns the native value of this address.
      java.lang.String toHexString()
      Returns a String object representing this Address as a hex value.
      java.lang.String toString()
      Returns a String object representing this Address as a decimal value.
      static Address valueOf​(int address)
      Returns a Address instance representing the specified int value.
      static Address valueOf​(long address)
      Returns a Address instance representing the specified long value.
      • Methods inherited from class java.lang.Number

        byteValue, shortValue
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Address

        public Address​(Address address)
        Creates a new address representation.
        Parameters:
        address - the native address.
    • Method Detail

      • address

        public final long address()
        Gets the native memory address represented by this Address as a long integer.
        Returns:
        the native memory address
      • intValue

        public final int intValue()
        Returns the value of this Address as an int. On 64bit systems, this will result in the upper 32bits of the address being truncated.
        Specified by:
        intValue in class java.lang.Number
        Returns:
        the numeric value of this Address after conversion to an int.
      • longValue

        public final long longValue()
        Returns the value of this Address as a long.
        Specified by:
        longValue in class java.lang.Number
        Returns:
        the numeric value of this Address after conversion to a long.
      • floatValue

        public final float floatValue()
        Returns the value of this Address as a float. This method is not particularly useful, and is here to fulfill the Number interface contract.
        Specified by:
        floatValue in class java.lang.Number
        Returns:
        the numeric value of this Address after conversion to a float.
      • doubleValue

        public final double doubleValue()
        Returns the value of this Address as a double. This method is not particularly useful, and is here to fulfill the Number interface contract.
        Specified by:
        doubleValue in class java.lang.Number
        Returns:
        the numeric value of this Address after conversion to a double.
      • nativeAddress

        public final long nativeAddress()
        Returns the native value of this address.
        Returns:
        an long value representing the native value of this address.
      • hashCode

        public final int hashCode()
        Returns a hash code for this Address.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code for this Address.
      • equals

        public final boolean equals​(java.lang.Object obj)
        Compares this address to another address.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the other address to compare to.
        Returns:
        true if this Address is equal to the other address, else false.
      • toString

        public final java.lang.String toString()
        Returns a String object representing this Address as a decimal value.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this Address.
      • toHexString

        public final java.lang.String toHexString()
        Returns a String object representing this Address as a hex value.
        Returns:
        a string representation of this Address.
      • compareTo

        public final int compareTo​(Address other)
        Compares two Address instances numerically.
        Specified by:
        compareTo in interface java.lang.Comparable<Address>
        Parameters:
        other - the other Address to compare to.
        Returns:
        0 if other is equal to this instance, -1 if this instance is numerically less than other or 1 if this instance is numerically greater than other.
      • isNull

        public final boolean isNull()
        Tests if this Address is equivalent to C NULL
        Returns:
        true if the address is 0
      • valueOf

        public static Address valueOf​(long address)
        Returns a Address instance representing the specified long value.
        Parameters:
        address - a long value
        Returns:
        an Address instance representing address
      • valueOf

        public static Address valueOf​(int address)
        Returns a Address instance representing the specified int value.
        Parameters:
        address - an int value
        Returns:
        an Address instance representing address