Skip to content

Commit

Permalink
Merge pull request #106 from thevpc/refactor_simplify_api
Browse files Browse the repository at this point in the history
Refactor simplify api
  • Loading branch information
thevpc authored Nov 2, 2021
2 parents e155fbc + 4b11bbb commit 5893284
Show file tree
Hide file tree
Showing 704 changed files with 11,702 additions and 11,428 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@
/core/nuts/.jpeek/
/core/nuts-runtime/.jpeek/
/core/.jpeek/
/.gradle/
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public static Class[] findClassHierarchy(Class clazz, Class baseType) {
return result.toArray(new Class[result.size()]);
}

public Set<V> keySet() {
return new HashSet(values.keySet());
}

public Collection<V> values() {
return values.values();
}

public V put(Class classKey, V value) {
cachedValues.clear();
return values.put(classKey, value);
Expand Down Expand Up @@ -208,4 +216,7 @@ public void clear() {
cachedHierarchy.clear();
}

public int size() {
return values.size();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package net.thevpc.nuts.runtime.bundles.collections;

import java.util.Arrays;

public class EvictingIntQueue {
private int from=0;
private int len;
private int[] values;

public EvictingIntQueue(int max) {
this.values=new int[max];
}

public void clear() {
from=0;
len=0;
}

public int size() {
return len;
}

public int get(int pos) {
if(pos>=0 && pos<len) {
int i=(from+pos)%values.length;
return values[i];
}
throw new IllegalArgumentException("invalid index "+pos);
}

public void add(int t) {
int pos=(from+len)%values.length;
values[pos]=t;
if(len<values.length){
len++;
}else{
from=(from+1)%values.length;
}
}

public String dump() {
StringBuilder sb=new StringBuilder();
for (int i = 0; i < size(); i++) {
sb.append(get(i));
}
return "EvictingIntQueue{" +
"from=" + from +
", len=" + len +
", raw=" + Arrays.toString(values) +
", values='" + sb +"'"+
'}';
}

@Override
public String toString() {
StringBuilder sb=new StringBuilder("{");
for (int i = 0; i < size(); i++) {
if(i>0){
sb.append(",");
}
sb.append(get(i));
}
sb.append("}");
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,69 @@
package net.thevpc.nuts.runtime.bundles.collections;

import java.util.LinkedList;
import java.util.AbstractList;
import java.util.Arrays;

public class EvictingQueue<T> {
int max;
LinkedList<T> values = new LinkedList<>();
public class EvictingQueue<T> extends AbstractList<T>{
private int from=0;
private int len;
private Object[] values;

public EvictingQueue(int max) {
this.max = max;
this.values=new Object[max];
}

public void clear() {
values.clear();
from=0;
len=0;
}

public int size() {
return values.size();
return len;
}

public T get(int pos) {
return values.get(pos);
if(pos>=0 && pos<len) {
int i=(from+pos)%values.length;
return (T)values[i];
}
throw new IllegalArgumentException("invalid index "+pos);
}

public void add(T t) {
if (values.size() >= max) {
values.removeFirst();

public boolean add(T t) {
int pos=(from+len)%values.length;
values[pos]=t;
if(len<values.length){
len++;
}else{
from=(from+1)%values.length;
}
values.add(t);
return true;
}

public String dump() {
StringBuilder sb=new StringBuilder();
for (int i = 0; i < size(); i++) {
sb.append(get(i));
}
return "EvictingQueue{" +
"from=" + from +
", len=" + len +
", raw=" + Arrays.toString(values) +
", values='" + sb +"'"+
'}';
}

@Override
public String toString() {
StringBuilder sb=new StringBuilder("{");
for (int i = 0; i < size(); i++) {
if(i>0){
sb.append(",");
}
sb.append(get(i));
}
sb.append("}");
return sb.toString();
}
}
Loading

0 comments on commit 5893284

Please sign in to comment.