001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.dialogs.properties;
003
004import javax.swing.RowFilter;
005import javax.swing.table.TableModel;
006
007import org.openstreetmap.josm.actions.search.SearchCompiler;
008import org.openstreetmap.josm.data.osm.Tag;
009
010/**
011 * A {@link RowFilter} implementation which matches tags w.r.t. the specified filter's
012 * {@link org.openstreetmap.josm.actions.search.SearchCompiler.Match#match(org.openstreetmap.josm.data.osm.Tagged)} method.
013 *
014 * <p>An {@link javax.swing.RowFilter.Entry}'s column 0 is considered as key, and column 1 is considered as value.</p>
015 */
016class SearchBasedRowFilter extends RowFilter<TableModel, Integer> {
017
018    final SearchCompiler.Match filter;
019
020    /**
021     * Constructs a new {@code SearchBasedRowFilter} with the given filter.
022     * @param filter the filter used to match tags
023     */
024    SearchBasedRowFilter(SearchCompiler.Match filter) {
025        this.filter = filter;
026    }
027
028    @Override
029    public boolean include(Entry entry) {
030        final String key = entry.getStringValue(0);
031        final String value = entry.getStringValue(1);
032        return filter.match(new Tag(key, value));
033    }
034
035}