Package jnr.ffi
Class Address
java.lang.Object
java.lang.Number
jnr.ffi.Address
- All Implemented Interfaces:
Serializable
,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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal long
address()
Gets the native memory address represented by thisAddress
as along
integer.final int
Compares twoAddress
instances numerically.final double
Returns the value of thisAddress
as adouble
.final boolean
Compares this address to another address.final float
Returns the value of thisAddress
as afloat
.final int
hashCode()
Returns a hash code for thisAddress
.final int
intValue()
Returns the value of thisAddress
as anint
.final boolean
isNull()
Tests if thisAddress
is equivalent to C NULLfinal long
Returns the value of thisAddress
as along
.final long
Returns the native value of this address.final String
Returns aString
object representing thisAddress
as a hex value.final String
toString()
Returns aString
object representing thisAddress
as a decimal value.static Address
valueOf
(int address) Returns a Address instance representing the specifiedint
value.static Address
valueOf
(long address) Returns a Address instance representing the specifiedlong
value.Methods inherited from class java.lang.Number
byteValue, shortValue
-
Constructor Details
-
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 thisAddress
as along
integer.- Returns:
- the native memory address
-
intValue
public final int intValue()Returns the value of thisAddress
as anint
. On 64bit systems, this will result in the upper 32bits of the address being truncated. -
longValue
public final long longValue()Returns the value of thisAddress
as along
. -
floatValue
public final float floatValue()Returns the value of thisAddress
as afloat
. This method is not particularly useful, and is here to fulfill theNumber
interface contract.- Specified by:
floatValue
in classNumber
- Returns:
- the numeric value of this
Address
after conversion to afloat
.
-
doubleValue
public final double doubleValue()Returns the value of thisAddress
as adouble
. This method is not particularly useful, and is here to fulfill theNumber
interface contract.- Specified by:
doubleValue
in classNumber
- Returns:
- the numeric value of this
Address
after conversion to adouble
.
-
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 thisAddress
. -
equals
Compares this address to another address. -
toString
Returns aString
object representing thisAddress
as a decimal value. -
toHexString
Returns aString
object representing thisAddress
as a hex value.- Returns:
- a string representation of this
Address
.
-
compareTo
Compares twoAddress
instances numerically.- Specified by:
compareTo
in interfaceComparable<Address>
- Parameters:
other
- the other Address to compare to.- Returns:
0
ifother
is equal to this instance, -1 if this instance is numerically less thanother
or 1 if this instance is numerically greater thanother
.
-
isNull
public final boolean isNull()Tests if thisAddress
is equivalent to C NULL- Returns:
- true if the address is 0
-
valueOf
Returns a Address instance representing the specifiedlong
value.- Parameters:
address
- along
value- Returns:
- an
Address
instance representingaddress
-
valueOf
Returns a Address instance representing the specifiedint
value.- Parameters:
address
- anint
value- Returns:
- an
Address
instance representingaddress
-