package org.geotools.filter.function;

import java.util.Set;

public final class ExplicitClassifier extends Classifier {

    Set[] values = null; //the contents of each bin (set of objects)
    
    public ExplicitClassifier(Set[] values) {
        this.values = values;
        //initialize titles
        this.titles = new String[values.length];
        for (int i = 0; i < titles.length; i++) {
            Object[] set = values[i].toArray();
            if (set.length > 0) {
                StringBuffer title = new StringBuffer(set[0] == null ? "null" : set[0].toString());
                for (int j = 1; j < set.length; j++) {
                    title.append(", ");
                    title.append(set[j] == null ? "null" : set[j].toString());
                }
                titles[i] = title.toString();
            } else {
                titles[i] = "";
            }
        }
    }
    
    public int getSize() {
        return values.length;
    }
    
    /**
     * Returns all the unique values for a particular slot.
     * 
     * @param index
     * @return all applicable values for a slot
     */
    public Set getValues(int index) {
        return values[index];
    }

    
    public int classify(Object value) {
        for (int i = 0; i < values.length; i++) {
            if (values[i].contains(value)) {
                return i;
            }
        }
        return -1;
    }
    
}
