-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathNative.java
More file actions
52 lines (43 loc) · 1.3 KB
/
Native.java
File metadata and controls
52 lines (43 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package io.github.humbleui.jwm.impl;
import org.jetbrains.annotations.ApiStatus;
import java.lang.ref.Reference;
public abstract class Native {
public long _ptr;
public static long getPtr(Native n) { return n == null ? 0 : n._ptr; }
public Native(long ptr) {
if (ptr == 0)
throw new RuntimeException("Can't wrap nullptr");
this._ptr = ptr;
}
@Override
public String toString() {
return getClass().getSimpleName() + "(_ptr=0x" + Long.toString(_ptr, 16) + ")";
}
@Override
public boolean equals(Object other) {
try {
if (this == other)
return true;
if (null == other)
return false;
if (!getClass().isInstance(other))
return false;
Native nOther = (Native) other;
if (_ptr == nOther._ptr)
return true;
return _nativeEquals(nOther);
} finally {
Reference.reachabilityFence(this);
Reference.reachabilityFence(other);
}
}
@ApiStatus.Internal
public boolean _nativeEquals(Native other) {
return false;
}
// FIXME two different pointers might point to equal objects
@Override
public int hashCode() {
return Long.hashCode(_ptr);
}
}