jnr.ffi
Class Address

java.lang.Object
  extended by java.lang.Number
      extended by jnr.ffi.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:
Serialized Form

Constructor Summary
Address(Address address)
          Creates a new address representation.
 
Method Summary
 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(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.
 String toHexString()
          Returns a String object representing this Address as a hex value.
 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 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


Copyright © 2013. All Rights Reserved.