mirror of
https://github.com/corda/corda.git
synced 2025-01-14 16:59:52 +00:00
sketch of java/lang/ref/*
This commit is contained in:
parent
32dff71994
commit
b213ec0ef8
11
classpath/java/lang/ref/PhantomReference.java
Normal file
11
classpath/java/lang/ref/PhantomReference.java
Normal file
@ -0,0 +1,11 @@
|
||||
package java.lang.ref;
|
||||
|
||||
public class PhantomReference<T> extends Reference<T> {
|
||||
public PhantomReference(T target, ReferenceQueue<? super T> queue) {
|
||||
super(target, queue);
|
||||
}
|
||||
|
||||
public PhantomReference(T target) {
|
||||
this(target, null);
|
||||
}
|
||||
}
|
34
classpath/java/lang/ref/Reference.java
Normal file
34
classpath/java/lang/ref/Reference.java
Normal file
@ -0,0 +1,34 @@
|
||||
package java.lang.ref;
|
||||
|
||||
public abstract class Reference<T> {
|
||||
private T target;
|
||||
private ReferenceQueue<? super T> queue;
|
||||
Reference<? extends T> next;
|
||||
|
||||
protected Reference(T target, ReferenceQueue<? super T> queue) {
|
||||
this.target = target;
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
public T get() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
target = 0;
|
||||
}
|
||||
|
||||
public boolean isEnqueued() {
|
||||
return next != null;
|
||||
}
|
||||
|
||||
public boolean enqueue() {
|
||||
if (queue != null) {
|
||||
queue.add(this);
|
||||
queue = null;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
28
classpath/java/lang/ref/ReferenceQueue.java
Normal file
28
classpath/java/lang/ref/ReferenceQueue.java
Normal file
@ -0,0 +1,28 @@
|
||||
package java.lang.ref;
|
||||
|
||||
public abstract class ReferenceQueue<T> {
|
||||
private Reference<? extends T> front;
|
||||
private Reference<? extends T> rear;
|
||||
|
||||
public Reference<? extends T> poll() {
|
||||
Reference<? extends T> r = front;
|
||||
if (front != null) {
|
||||
if (front == front.next) {
|
||||
front = rear = null;
|
||||
} else {
|
||||
front = front.next;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void add(Reference<? extends T> r) {
|
||||
r.next = r;
|
||||
if (front == null) {
|
||||
front = rear = r;
|
||||
} else {
|
||||
rear.next = r;
|
||||
rear = r;
|
||||
}
|
||||
}
|
||||
}
|
11
classpath/java/lang/ref/WeakReference.java
Normal file
11
classpath/java/lang/ref/WeakReference.java
Normal file
@ -0,0 +1,11 @@
|
||||
package java.lang.ref;
|
||||
|
||||
public class WeakReference<T> extends Reference<T> {
|
||||
public WeakReference(T target, ReferenceQueue<? super T> queue) {
|
||||
super(target, queue);
|
||||
}
|
||||
|
||||
public WeakReference(T target) {
|
||||
this(target, null);
|
||||
}
|
||||
}
|
@ -216,14 +216,23 @@
|
||||
(extends jobject)
|
||||
(uint64_t value))
|
||||
|
||||
(type referenceQueue java/lang/ref/ReferenceQueue
|
||||
(extends jobject)
|
||||
(object front)
|
||||
(object rear))
|
||||
|
||||
(type jreference java/lang/ref/Reference
|
||||
(extends jobject)
|
||||
(void* target)
|
||||
(void* queue)
|
||||
(void* next))
|
||||
|
||||
(type weakReference java/lang/ref/WeakReference
|
||||
(extends jreference))
|
||||
|
||||
(type phantomReference java/lang/ref/PhantomReference
|
||||
(extends jreference))
|
||||
|
||||
(type byteArray [B
|
||||
(extends jobject)
|
||||
(array int8_t body))
|
||||
|
Loading…
Reference in New Issue
Block a user