Package jnr.ffi
Class Address
- java.lang.Object
-
- java.lang.Number
-
- jnr.ffi.Address
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<Address>
public final class Address extends java.lang.Number implements java.lang.Comparable<Address>
TheAddressclass wraps a native address in an object. Both 32 bit and 64 bit native address values are wrapped in a singularAddresstype.This class extends
Numberand implements allNumbermethods for converting to primitive integer types.An
Addressinstance is lighter weight than mostPointerinstances, 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, aPointeroffers more flexibility and should be preferred instead.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddress()Gets the native memory address represented by thisAddressas alonginteger.intcompareTo(Address other)Compares twoAddressinstances numerically.doubledoubleValue()Returns the value of thisAddressas adouble.booleanequals(java.lang.Object obj)Compares this address to another address.floatfloatValue()Returns the value of thisAddressas afloat.inthashCode()Returns a hash code for thisAddress.intintValue()Returns the value of thisAddressas anint.booleanisNull()Tests if thisAddressis equivalent to C NULLlonglongValue()Returns the value of thisAddressas along.longnativeAddress()Returns the native value of this address.java.lang.StringtoHexString()Returns aStringobject representing thisAddressas a hex value.java.lang.StringtoString()Returns aStringobject representing thisAddressas a decimal value.static AddressvalueOf(int address)Returns a Address instance representing the specifiedintvalue.static AddressvalueOf(long address)Returns a Address instance representing the specifiedlongvalue.
-
-
-
Field Detail
-
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 thisAddress
-
-
Constructor Detail
-
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 Detail
-
address
public final long address()
Gets the native memory address represented by thisAddressas alonginteger.- Returns:
- the native memory address
-
intValue
public final int intValue()
Returns the value of thisAddressas anint. On 64bit systems, this will result in the upper 32bits of the address being truncated.- Specified by:
intValuein classjava.lang.Number- Returns:
- the numeric value of this
Addressafter conversion to anint.
-
longValue
public final long longValue()
Returns the value of thisAddressas along.- Specified by:
longValuein classjava.lang.Number- Returns:
- the numeric value of this
Addressafter conversion to along.
-
floatValue
public final float floatValue()
Returns the value of thisAddressas afloat. This method is not particularly useful, and is here to fulfill theNumberinterface contract.- Specified by:
floatValuein classjava.lang.Number- Returns:
- the numeric value of this
Addressafter conversion to afloat.
-
doubleValue
public final double doubleValue()
Returns the value of thisAddressas adouble. This method is not particularly useful, and is here to fulfill theNumberinterface contract.- Specified by:
doubleValuein classjava.lang.Number- Returns:
- the numeric value of this
Addressafter conversion to adouble.
-
nativeAddress
public final long nativeAddress()
Returns the native value of this address.- Returns:
- an
longvalue representing the native value of this address.
-
hashCode
public final int hashCode()
Returns a hash code for thisAddress.- Overrides:
hashCodein classjava.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:
equalsin classjava.lang.Object- Parameters:
obj- the other address to compare to.- Returns:
trueif this Address is equal to the other address, else false.
-
toString
public final java.lang.String toString()
Returns aStringobject representing thisAddressas a decimal value.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of this
Address.
-
toHexString
public final java.lang.String toHexString()
Returns aStringobject representing thisAddressas a hex value.- Returns:
- a string representation of this
Address.
-
compareTo
public final int compareTo(Address other)
Compares twoAddressinstances numerically.- Specified by:
compareToin interfacejava.lang.Comparable<Address>- Parameters:
other- the other Address to compare to.- Returns:
0ifotheris equal to this instance, -1 if this instance is numerically less thanotheror 1 if this instance is numerically greater thanother.
-
isNull
public final boolean isNull()
Tests if thisAddressis equivalent to C NULL- Returns:
- true if the address is 0
-
valueOf
public static Address valueOf(long address)
Returns a Address instance representing the specifiedlongvalue.- Parameters:
address- alongvalue- Returns:
- an
Addressinstance representingaddress
-
valueOf
public static Address valueOf(int address)
Returns a Address instance representing the specifiedintvalue.- Parameters:
address- anintvalue- Returns:
- an
Addressinstance representingaddress
-
-