source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/properties/SearchBasedRowFilter.java@ 8985

Last change on this file since 8985 was 8985, checked in by Don-vip, 8 years ago

checkstyle

File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.properties;
3
4import java.util.Collection;
5import java.util.Collections;
6import java.util.Map;
7
8import javax.swing.RowFilter;
9import javax.swing.table.TableModel;
10
11import org.openstreetmap.josm.actions.search.SearchCompiler;
12import org.openstreetmap.josm.data.osm.Tagged;
13
14/**
15 * A {@link RowFilter} implementation which matches tags w.r.t. the specified filter's
16 * {@link SearchCompiler.Match#match(org.openstreetmap.josm.data.osm.Tagged)} method.
17 *
18 * <p>An {@link javax.swing.RowFilter.Entry}'s column 0 is considered as key, and column 1 is considered as value.</p>
19 */
20class SearchBasedRowFilter extends RowFilter<TableModel, Integer> {
21
22 final SearchCompiler.Match filter;
23
24 /**
25 * Constructs a new {@code SearchBasedRowFilter} with the given filter.
26 * @param filter the filter used to match tags
27 */
28 SearchBasedRowFilter(SearchCompiler.Match filter) {
29 this.filter = filter;
30 }
31
32 @Override
33 public boolean include(Entry entry) {
34 final String key = entry.getStringValue(0);
35 final String value = entry.getStringValue(1);
36 return filter.match(new OneKeyValue(key, value));
37 }
38
39 static class OneKeyValue implements Tagged {
40 private final String key;
41 private final String value;
42
43 OneKeyValue(String key, String value) {
44 this.key = key;
45 this.value = value;
46 }
47
48 @Override
49 public void setKeys(Map<String, String> keys) {
50 throw new UnsupportedOperationException();
51 }
52
53 @Override
54 public Map<String, String> getKeys() {
55 return Collections.singletonMap(key, value);
56 }
57
58 @Override
59 public void put(String key, String value) {
60 throw new UnsupportedOperationException();
61 }
62
63 @Override
64 public String get(String k) {
65 return key.equals(k) ? value : null;
66 }
67
68 @Override
69 public void remove(String key) {
70 throw new UnsupportedOperationException();
71 }
72
73 @Override
74 public boolean hasKeys() {
75 return true;
76 }
77
78 @Override
79 public Collection<String> keySet() {
80 return Collections.singleton(key);
81 }
82
83 @Override
84 public void removeAll() {
85 throw new UnsupportedOperationException();
86 }
87 }
88}
Note: See TracBrowser for help on using the repository browser.