Compare commits
No commits in common. "f713e3941de3acdfa5ed8556ec7a3acf11cf5be8" and "bda04a188b72ea2b8515540770db9fdf79636943" have entirely different histories.
f713e3941d
...
bda04a188b
4 changed files with 1 additions and 61 deletions
|
@ -5,10 +5,6 @@ import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import dev.peerat.framework.Locker.Key;
|
|
||||||
|
|
||||||
public class Locker<V>{
|
public class Locker<V>{
|
||||||
|
|
||||||
|
@ -59,51 +55,5 @@ public class Locker<V>{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void listen(Consumer<V> action){
|
|
||||||
Key key = new Key();
|
|
||||||
init(key);
|
|
||||||
try {
|
|
||||||
while(true){
|
|
||||||
lock(key);
|
|
||||||
V value = getValue(key);
|
|
||||||
action.accept(value);
|
|
||||||
}
|
|
||||||
}catch(Exception e){}
|
|
||||||
remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void listen(Supplier<Boolean> condition,Consumer<V> action){
|
|
||||||
Key key = new Key();
|
|
||||||
init(key);
|
|
||||||
try {
|
|
||||||
while(condition.get()){
|
|
||||||
lock(key);
|
|
||||||
V value = getValue(key);
|
|
||||||
action.accept(value);
|
|
||||||
}
|
|
||||||
}catch(Exception e){}
|
|
||||||
remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Thread listenAsync(Consumer<V> action){
|
|
||||||
Thread thread = new Thread(new Runnable(){
|
|
||||||
public void run(){
|
|
||||||
listen(action);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
thread.start();
|
|
||||||
return thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Thread listenAsync(Supplier<Boolean> condition,Consumer<V> action){
|
|
||||||
Thread thread = new Thread(new Runnable(){
|
|
||||||
public void run(){
|
|
||||||
listen(condition, action);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
thread.start();
|
|
||||||
return thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Key{ public Key(){} }
|
public static class Key{ public Key(){} }
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package dev.peerat.framework.utils.json;
|
||||||
|
|
||||||
public class Json{
|
public class Json{
|
||||||
|
|
||||||
void buildValue(StringBuilder builder, Object value){
|
public void buildValue(StringBuilder builder, Object value){
|
||||||
if(value == null) builder.append("null");
|
if(value == null) builder.append("null");
|
||||||
else if(value instanceof String){
|
else if(value instanceof String){
|
||||||
builder.append('"');
|
builder.append('"');
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package dev.peerat.framework.utils.json;
|
package dev.peerat.framework.utils.json;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -13,10 +12,6 @@ public class JsonArray extends Json{
|
||||||
this.list = new ArrayList<>();
|
this.list = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Object> toList(){
|
|
||||||
return this.list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Object value){
|
public void add(Object value){
|
||||||
this.list.add(value);
|
this.list.add(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class JsonMap extends Json{
|
public class JsonMap extends Json{
|
||||||
|
|
||||||
|
@ -14,10 +13,6 @@ public class JsonMap extends Json{
|
||||||
this.map = new HashMap<>();
|
this.map = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Entry<String, Object>> entries(){
|
|
||||||
return this.map.entrySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(String key, Object value){
|
public void set(String key, Object value){
|
||||||
this.map.put(key, value);
|
this.map.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue