
org.whispersystems.libsignal.SignalProtocolAddress Maven / Gradle / Ivy
/**
* Copyright (C) 2014-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
*/
package org.whispersystems.libsignal;
import org.signal.client.internal.Native;
import org.signal.client.internal.NativeHandleGuard;
public class SignalProtocolAddress implements NativeHandleGuard.Owner {
private final long unsafeHandle;
public SignalProtocolAddress(String name, int deviceId) {
this.unsafeHandle = Native.ProtocolAddress_New(name, deviceId);
}
public SignalProtocolAddress(long unsafeHandle) {
this.unsafeHandle = unsafeHandle;
}
@Override
protected void finalize() {
Native.ProtocolAddress_Destroy(this.unsafeHandle);
}
public String getName() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ProtocolAddress_Name(guard.nativeHandle());
}
}
public int getDeviceId() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.ProtocolAddress_DeviceId(guard.nativeHandle());
}
}
@Override
public String toString() {
return getName() + "." + getDeviceId();
}
@Override
public boolean equals(Object other) {
if (other == null) return false;
if (!(other instanceof SignalProtocolAddress)) return false;
SignalProtocolAddress that = (SignalProtocolAddress)other;
return this.getName().equals(that.getName()) && this.getDeviceId() == that.getDeviceId();
}
@Override
public int hashCode() {
return this.getName().hashCode() ^ this.getDeviceId();
}
public long unsafeNativeHandleWithoutGuard() {
return this.unsafeHandle;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy