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>
TheAddress
class wraps a native address in an object. Both 32 bit and 64 bit native address values are wrapped in a singularAddress
type.This class extends
Number
and implements allNumber
methods for converting to primitive integer types.An
Address
instance is lighter weight than mostPointer
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, aPointer
offers 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 long
address()
Gets the native memory address represented by thisAddress
as along
integer.int
compareTo(Address other)
Compares twoAddress
instances numerically.double
doubleValue()
Returns the value of thisAddress
as adouble
.boolean
equals(java.lang.Object obj)
Compares this address to another address.float
floatValue()
Returns the value of thisAddress
as afloat
.int
hashCode()
Returns a hash code for thisAddress
.int
intValue()
Returns the value of thisAddress
as anint
.boolean
isNull()
Tests if thisAddress
is equivalent to C NULLlong
longValue()
Returns the value of thisAddress
as along
.long
nativeAddress()
Returns the native value of this address.java.lang.String
toHexString()
Returns aString
object representing thisAddress
as a hex value.java.lang.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.
-
-
-
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 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.- Specified by:
intValue
in classjava.lang.Number
- Returns:
- the numeric value of this
Address
after conversion to anint
.
-
longValue
public final long longValue()
Returns the value of thisAddress
as along
.- Specified by:
longValue
in classjava.lang.Number
- Returns:
- the numeric value of this
Address
after conversion to 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 classjava.lang.Number
- 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 classjava.lang.Number
- 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
.- Overrides:
hashCode
in 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:
equals
in classjava.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 aString
object representing thisAddress
as a decimal value.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of this
Address
.
-
toHexString
public final java.lang.String toHexString()
Returns aString
object representing thisAddress
as a hex value.- Returns:
- a string representation of this
Address
.
-
compareTo
public final int compareTo(Address other)
Compares twoAddress
instances numerically.- Specified by:
compareTo
in interfacejava.lang.Comparable<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
public static Address valueOf(long address)
Returns a Address instance representing the specifiedlong
value.- Parameters:
address
- along
value- Returns:
- an
Address
instance representingaddress
-
valueOf
public static Address valueOf(int address)
Returns a Address instance representing the specifiedint
value.- Parameters:
address
- anint
value- Returns:
- an
Address
instance representingaddress
-
-