- java.lang.Object
-
- java.lang.Number
-
- jnr.ffi.Address
-
- All Implemented Interfaces:
Serializable,Comparable<Address>
public final class Address extends Number implements 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(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.StringtoHexString()Returns aStringobject representing thisAddressas a hex value.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.-
Methods inherited from class java.lang.Number
byteValue, shortValue
-
-
-
-
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 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.
-
longValue
public final long longValue()
Returns the value of thisAddressas 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 classNumber- 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 classNumber- 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.
-
equals
public final boolean equals(Object obj)
Compares this address to another address.
-
toString
public final String toString()
Returns aStringobject representing thisAddressas a decimal value.
-
toHexString
public final 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 interfaceComparable<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
-
-