Package jnr.ffi

Class Address

All Implemented Interfaces:
Serializable, Comparable<Address>

public final class Address extends Number implements 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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final long
    The native numeric value of this Address
    private static final Address
    A global instance of this class representing the C NULL value
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Address(long address)
    Creates a new address representation.
     
    Address(Address address)
    Creates a new address representation.
  • Method Summary

    Modifier and Type
    Method
    Description
    final long
    Gets the native memory address represented by this Address as a long integer.
    final int
    Compares two Address instances numerically.
    final double
    Returns the value of this Address as a double.
    final boolean
    Compares this address to another address.
    final float
    Returns the value of this Address as a float.
    final int
    Returns a hash code for this Address.
    final int
    Returns the value of this Address as an int.
    final boolean
    Tests if this Address is equivalent to C NULL
    final long
    Returns the value of this Address as a long.
    final long
    Returns the native value of this address.
    final String
    Returns a String object representing this Address as a hex value.
    final String
    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
  • Field Details

    • NULL

      private static final Address NULL
      A global instance of this class representing the C NULL value
    • address

      private final long address
      The native numeric value of this Address
  • Constructor Details

    • Address

      private Address(long address)
      Creates a new address representation.
      Parameters:
      address - the native address.
    • Address

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

    • 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 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 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 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 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 Object
      Returns:
      a hash code for this Address.
    • equals

      public final boolean equals(Object obj)
      Compares this address to another address.
      Overrides:
      equals in class 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 String toString()
      Returns a String object representing this Address as a decimal value.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this Address.
    • toHexString

      public final 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 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