diff --git a/source/net/yacy/cora/sorting/AbstractScoreMap.java b/source/net/yacy/cora/sorting/AbstractScoreMap.java index 3d51d3402..829a03764 100644 --- a/source/net/yacy/cora/sorting/AbstractScoreMap.java +++ b/source/net/yacy/cora/sorting/AbstractScoreMap.java @@ -25,6 +25,8 @@ package net.yacy.cora.sorting; import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; import java.util.List; @@ -72,4 +74,25 @@ public abstract class AbstractScoreMap implements ScoreMap { return list; */ } + + public Collection keyList(final boolean up) { + List list = new ArrayList(this.size()); + Iterator i = this.keys(up); + while (i.hasNext()) list.add(i.next()); + return list; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append('['); + Iterator i = this.keys(false); + while (i.hasNext()) { + E e = i.next(); + String s = e.toString(); + sb.append(s.length() == 0 ? "\"\"" : s).append('/').append(Integer.toString(this.get(e))).append(','); + } + if (sb.length() == 1) sb.append(']'); else sb.replace(sb.length() - 1, sb.length(), "]"); + return sb.toString(); + } } diff --git a/source/net/yacy/cora/sorting/ClusteredScoreMap.java b/source/net/yacy/cora/sorting/ClusteredScoreMap.java index bba7f1f8e..aec5814ec 100644 --- a/source/net/yacy/cora/sorting/ClusteredScoreMap.java +++ b/source/net/yacy/cora/sorting/ClusteredScoreMap.java @@ -276,11 +276,6 @@ public final class ClusteredScoreMap extends AbstractScoreMap implements R return this.pam.get(this.pam.firstKey()); } - @Override - public String toString() { - return this.map + " / " + this.pam; - } - @Override public synchronized Iterator keys(final boolean up) { if (up) return new simpleScoreIterator(); diff --git a/source/net/yacy/cora/sorting/OrderedScoreMap.java b/source/net/yacy/cora/sorting/OrderedScoreMap.java index 292080b59..12472cfef 100644 --- a/source/net/yacy/cora/sorting/OrderedScoreMap.java +++ b/source/net/yacy/cora/sorting/OrderedScoreMap.java @@ -217,11 +217,6 @@ public class OrderedScoreMap extends AbstractScoreMap implements ScoreMap< return minScore; } - @Override - public String toString() { - return this.map.toString(); - } - public Iterator keys(final boolean up) { synchronized (this.map) { // re-organize entries @@ -251,7 +246,7 @@ public class OrderedScoreMap extends AbstractScoreMap implements ScoreMap< return r.iterator(); } } - + public static void main(String[] args) { OrderedScoreMap w = new OrderedScoreMap(StringBuilderComparator.CASE_INSENSITIVE_ORDER); Random r = new Random(); diff --git a/source/net/yacy/cora/sorting/ScoreMap.java b/source/net/yacy/cora/sorting/ScoreMap.java index 66e90bf3b..47a7e60ab 100644 --- a/source/net/yacy/cora/sorting/ScoreMap.java +++ b/source/net/yacy/cora/sorting/ScoreMap.java @@ -24,6 +24,7 @@ package net.yacy.cora.sorting; +import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -65,8 +66,10 @@ public interface ScoreMap extends Iterable { @Override public String toString(); - + public Iterator keys(final boolean up); + + public Collection keyList(final boolean up); public void inc(final E obj); public void inc(final E obj, final int incrementScore); diff --git a/source/net/yacy/server/serverObjects.java b/source/net/yacy/server/serverObjects.java index 4d4b3e3bd..81ec43501 100644 --- a/source/net/yacy/server/serverObjects.java +++ b/source/net/yacy/server/serverObjects.java @@ -445,6 +445,13 @@ public class serverObjects implements Serializable, Cloneable { return s.equals("true") || s.equals("on") || s.equals("1"); } + public boolean getBoolean(final String key, final boolean dflt) { + String s = removeByteOrderMark(get(key)); + if (s == null) return dflt; + s = s.toLowerCase(); + return s.equals("true") || s.equals("on") || s.equals("1"); + } + // returns a set of all values where their key mappes the keyMapper public String[] getAll(final String keyMapper) { // the keyMapper may contain regular expressions as defined in String.matches