All Downloads are FREE. Search and download functionalities are using the official Maven repository.

test.ca.odell.glazedlists.CollectionMatcherEditor Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
/* Glazed Lists                                                 (c) 2003-2006 */
/* http://publicobject.com/glazedlists/                      publicobject.com,*/
/*                                                     O'Dell Engineering Ltd.*/
package ca.odell.glazedlists;

import ca.odell.glazedlists.matchers.Matcher;
import ca.odell.glazedlists.matchers.AbstractMatcherEditor;

import java.util.Collection;
import java.util.Collections;

/**
 * A simple matcher editor that uses set collection for matching.
 *
 * @author Jesse Wilson
 */
public class CollectionMatcherEditor extends AbstractMatcherEditor {

    private Collection current = null;

    public void matchAll() {
        current = null;
        fireMatchAll();
    }

    public void matchNone() {
        current = Collections.EMPTY_LIST;
        fireMatchNone();
    }

    public void setCollection(Collection values) {
        boolean relaxed = current != null && values.containsAll(current);
        boolean constrained = current == null || current.containsAll(values);
        this.current = values;
        CollectionMatcher matcherEditor = new CollectionMatcher(values);

        if(relaxed) {
            fireRelaxed(matcherEditor);

        } else if(constrained) {
            fireConstrained(matcherEditor);

        } else {
            fireChanged(matcherEditor);

        }
    }

    private static class CollectionMatcher implements Matcher {
        private final Collection values;
        public CollectionMatcher(Collection values) {
            this.values = values;
        }
        public boolean matches(E item) {
            return values.contains(item);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy