-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from thevpc/refactor_simplify_api
Refactor simplify api
- Loading branch information
Showing
704 changed files
with
11,702 additions
and
11,428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,3 +89,4 @@ | |
/core/nuts/.jpeek/ | ||
/core/nuts-runtime/.jpeek/ | ||
/core/.jpeek/ | ||
/.gradle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...s-runtime/src/main/java/net/thevpc/nuts/runtime/bundles/collections/EvictingIntQueue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
61 changes: 49 additions & 12 deletions
61
...nuts-runtime/src/main/java/net/thevpc/nuts/runtime/bundles/collections/EvictingQueue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.