package org.jenkinsci.plugins.lucene.search.databackend;

import org.apache.lucene.search.IndexSearcher;

/**
* Created by tobias on 3/24/15.
*/
class LengthLimitedDistinctCollector extends DistinctCollector {

    private final int maxLength;

    public LengthLimitedDistinctCollector(String fieldName, IndexSearcher searcher, int maxLength) {
        super(fieldName, searcher);
        if (maxLength < 4) {
            throw new IllegalArgumentException("Length must be at least 4");
        }
        this.maxLength = maxLength;
    }

    @Override
    protected void addData(String fieldValue) {
        if (fieldValue != null) {
            if (fieldValue.length() > maxLength) {
                // ellipsize
                super.addData(fieldValue.substring(0, maxLength - 3) + "...");
            } else {
                super.addData(fieldValue);
            }
        }
    }
}

@@ -103,47 +103,8 @@
 r;%0A%0A
-/**%0A* Created by tobias on 3/24/15.%0A*/%0A
 clas

remove useless header