|
|
|
@ -66,9 +66,10 @@ public final class ScoreCluster<E> {
|
|
|
|
|
* shrink the cluster to a demanded size
|
|
|
|
|
* @param maxsize
|
|
|
|
|
*/
|
|
|
|
|
public synchronized void shrinkToMaxSize(int maxsize) {
|
|
|
|
|
public void shrinkToMaxSize(int maxsize) {
|
|
|
|
|
if (maxsize < 0) return;
|
|
|
|
|
Long key;
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
while (refkeyDB.size() > maxsize) {
|
|
|
|
|
// find and remove smallest objects until cluster has demanded size
|
|
|
|
|
key = keyrefDB.firstKey();
|
|
|
|
@ -76,14 +77,16 @@ public final class ScoreCluster<E> {
|
|
|
|
|
refkeyDB.remove(keyrefDB.remove(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* shrink the cluster in such a way that the smallest score is equal or greater than a given minScore
|
|
|
|
|
* @param minScore
|
|
|
|
|
*/
|
|
|
|
|
public synchronized void shrinkToMinScore(int minScore) {
|
|
|
|
|
public void shrinkToMinScore(int minScore) {
|
|
|
|
|
int score;
|
|
|
|
|
Long key;
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
while (keyrefDB.size() > 0) {
|
|
|
|
|
// find and remove objects where their score is smaller than the demanded minimum score
|
|
|
|
|
key = keyrefDB.firstKey();
|
|
|
|
@ -93,6 +96,7 @@ public final class ScoreCluster<E> {
|
|
|
|
|
refkeyDB.remove(keyrefDB.remove(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static final String shortDateFormatString = "yyyyMMddHHmmss";
|
|
|
|
|
public static final SimpleDateFormat shortFormatter = new SimpleDateFormat(shortDateFormatString, Locale.US);
|
|
|
|
@ -197,9 +201,9 @@ public final class ScoreCluster<E> {
|
|
|
|
|
addScore(obj, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public synchronized void setScore(final E obj, final int newScore) {
|
|
|
|
|
public void setScore(final E obj, final int newScore) {
|
|
|
|
|
if (obj == null) return;
|
|
|
|
|
//System.out.println("setScore " + obj.getClass().getName());
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
Long usk = refkeyDB.remove(obj); // get unique score key, old entry is not needed any more
|
|
|
|
|
if (newScore < 0) throw new kelondroOutOfLimitsException(newScore);
|
|
|
|
|
|
|
|
|
@ -226,7 +230,7 @@ public final class ScoreCluster<E> {
|
|
|
|
|
refkeyDB.put(obj, usk);
|
|
|
|
|
keyrefDB.put(usk, obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// increase overall counter
|
|
|
|
|
gcount += newScore;
|
|
|
|
|
}
|
|
|
|
@ -266,15 +270,17 @@ public final class ScoreCluster<E> {
|
|
|
|
|
gcount += incrementScore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public synchronized int deleteScore(final E obj) {
|
|
|
|
|
public int deleteScore(final E obj) {
|
|
|
|
|
// deletes entry and returns previous score
|
|
|
|
|
if (obj == null) return 0;
|
|
|
|
|
//System.out.println("setScore " + obj.getClass().getName());
|
|
|
|
|
final Long usk = refkeyDB.remove(obj); // get unique score key, old entry is not needed any more
|
|
|
|
|
final Long usk;
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
usk = refkeyDB.remove(obj); // get unique score key, old entry is not needed any more
|
|
|
|
|
if (usk == null) return 0;
|
|
|
|
|
|
|
|
|
|
// delete old entry
|
|
|
|
|
keyrefDB.remove(usk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get previous handle and score
|
|
|
|
|
final int oldScore = (int) ((usk.longValue() & 0xFFFFFFFF00000000L) >> 32);
|
|
|
|
@ -289,9 +295,12 @@ public final class ScoreCluster<E> {
|
|
|
|
|
return (refkeyDB.get(obj) != null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public synchronized int getScore(final E obj) {
|
|
|
|
|
public int getScore(final E obj) {
|
|
|
|
|
if (obj == null) return 0;
|
|
|
|
|
final Long cs = refkeyDB.get(obj);
|
|
|
|
|
final Long cs;
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
cs = refkeyDB.get(obj);
|
|
|
|
|
}
|
|
|
|
|
if (cs == null) return 0;
|
|
|
|
|
return (int) ((cs.longValue() & 0xFFFFFFFF00000000L) >> 32);
|
|
|
|
|
}
|
|
|
|
|