/** * Creates a {@link AbstractFilterList} that includes a subset of the specified * source {@link EventList}. * * <p>Extending classes must call handleFilterChanged(). */ protected AbstractFilterList(EventList source) { super(new FilterList(source)); // listen for changes to the source list this.source.addListEventListener(this); }
/** * A hidden constructor that allows us to store a reference to the * FilterList, which we created and must dispose later. * * @param filterList the FilterList that backs this TableCheckFilterList * @param table the checkable table * @param tableFormat the format of the checkable table */ private TableCheckFilterList(FilterList<S> filterList, Table table, TableFormat tableFormat) { super(filterList); this.filterList = filterList; this.table = table; this.checkableTableFormat = tableFormat instanceof CheckableTableFormat ? (CheckableTableFormat) tableFormat : null; // listen for changes in checkedness table.addSelectionListener(this); // prepare the filter filterList.setMatcherEditor(checkMatcherEditor); // handle changes filterList.addListEventListener(this); }
/** * This method acquires the write lock for the FilterList and then selects * an appropriate delegate method to perform the correct work for each of * the possible <code>changeType</code>s. */ private void changeMatcherWithLocks(MatcherEditor<? super E> matcherEditor, Matcher<? super E> matcher, int changeType) { getReadWriteLock().writeLock().lock(); try { changeMatcher(matcherEditor, matcher, changeType); } finally { getReadWriteLock().writeLock().unlock(); } }
/** * This method selects an appropriate delegate method to perform the * correct work for each of the possible <code>changeType</code>s. This * method does <strong>NOT</strong> acquire any locks and is thus used * during initialization of FilterList. */ private void changeMatcher(MatcherEditor<? super E> matcherEditor, Matcher<? super E> matcher, int changeType) { // first check if this list is already disposed if (!disposed) { // ensure the MatcherEvent is from OUR MatcherEditor if (currentEditor != matcherEditor) throw new IllegalStateException(); switch (changeType) { case MatcherEditor.Event.CONSTRAINED: currentMatcher = matcher; this.constrained(); break; case MatcherEditor.Event.RELAXED: currentMatcher = matcher; this.relaxed(); break; case MatcherEditor.Event.CHANGED: currentMatcher = matcher; this.changed(); break; case MatcherEditor.Event.MATCH_ALL: currentMatcher = Matchers.trueMatcher(); this.matchAll(); break; case MatcherEditor.Event.MATCH_NONE: currentMatcher = Matchers.falseMatcher(); this.matchNone(); break; } } }
/** * Creates a new filter list that uses a TextFilterator. A TextFilterator is something * that I made up. It is basically a class that knows how to take an arbitrary * object and get an array of strings for that object. * * @param filterEdit a text field for typing in the filter text. */ public TextFilterList(EventList source, Text filterEdit, TextFilterator filterator) { super(new FilterList(source)); this.filterEdit = filterEdit; matcherEditor = new TextWidgetMatcherEditor(filterEdit, filterator, false); ((FilterList)this.source).setMatcherEditor(matcherEditor); // handle changes this.source.addListEventListener(this); }
filterList = new FilterList<MyIndustryJob>(sortedList); eventList.getReadWriteLock().readLock().unlock(); filterList.addListEventListener(listener);
/** * @param source the raw elements that will be tested by the given * <code>matcher</code> * @param matcher the logic which determines whether an element is counted * in the value reported by this Calculation */ public ConditionalCount(EventList<E> source, Matcher<E> matcher) { super(new Integer(0)); // the user should ideally know nothing about this FilterList, so we // lock the pipeline during its construction so the calling code need // not consider concurrency, which is really an implementation detail source.getReadWriteLock().readLock().lock(); try { filtered = new FilterList<E>(source, matcher); filtered.addListEventListener(this); setValue(new Integer(filtered.size())); } finally { source.getReadWriteLock().readLock().unlock(); } }
try { eventList.getReadWriteLock().readLock().lock(); FilterList<E> filterList = new FilterList<E>(eventList, new FilterLogicalMatcher<E>(filterControl, filter)); if (!filterList.isEmpty() && filterList.get(0) instanceof TreeAsset) { FilterList<E> treeFilterList = new FilterList<E>(eventList, new TreeMatcher<E>(filterList)); items.addAll(treeFilterList); } else { try { eventList.getReadWriteLock().readLock().lock(); FilterList<E> filterList = new FilterList<E>(eventList, new FilterLogicalMatcher<E>(filterControl, filter)); if (!filterList.isEmpty() && filterList.get(0) instanceof TreeAsset) { FilterList<E> treeFilterList = new FilterList<E>(eventList, new TreeMatcher<E>(filterList)); items.addAll(treeFilterList); } else {
@Benchmark @Warmup(iterations = 5) @Measurement(iterations = 10) @Fork(1) public EventList<Element> testSeparatorListFilterNew() { EventList<Element> baseCopy = GlazedLists.eventList(base); FilterList<Element> filterList = new FilterList<>(baseCopy); EventList<Element> sepBase = new SeparatorList<>(filterList, elementComparator(), 0, Integer.MAX_VALUE); for (int i = 0; i < 10; i++) { filterList.setMatcher(Matchers.falseMatcher()); filterList.setMatcher(Matchers.trueMatcher()); } return sepBase; }
/** * Handles a constraining of the filter to a degree that guarantees no * values can be matched. That is, the filter list will act as a total * filter and not match any of the elements of the wrapped source list. */ private void matchNone() { // all of these changes to this list happen "atomically" updates.beginEvent(); // fire all the elements in the list as deleted for(int i = 0; i < size(); i++) { updates.elementDeleted(0, get(i)); } // reset the flaglist to all white (which matches nothing) flagList.clear(); flagList.addWhite(0, source.size()); // commit the changes and notify listeners updates.commitEvent(); }
final FilterList filteredList = new FilterList(sortedList, new ThreadedMatcherEditor(matcherEditor)); filteredList.addListEventListener(new ListEventListener() { countLabel.setText("" + filteredList.size());
/** * Convenience constructor for creating a {@link FilterList} and setting its * {@link Matcher}. */ public FilterList(EventList<E> source, Matcher<? super E> matcher) { this(source); // if no matcher was given, we have no further initialization work if (matcher == null) return; currentMatcher = matcher; changed(); }
/** * Set the {@link Matcher} which specifies which elements shall be filtered. * * <p>This will remove the current {@link Matcher} or {@link MatcherEditor} * and refilter the entire list. */ public void setMatcher(Matcher<? super E> matcher) { // cancel the previous editor if(currentEditor != null) { currentEditor.removeMatcherEditorListener(listener); currentEditor = null; } if (matcher != null) changeMatcherWithLocks(currentEditor, matcher, MatcherEditor.Event.CHANGED); else changeMatcherWithLocks(currentEditor, null, MatcherEditor.Event.MATCH_ALL); }
this.defaultFilters = defaultFilters; ListenerClass listener = new ListenerClass(); filterList.addListEventListener(listener); gui = new FilterGui<E>(jFrame, this); cache = new HashMap<E, String>();
filterList.getReadWriteLock().readLock().lock(); for (TreeAsset treeAsset : filterList) { treeAsset.updateParents(); filterList.getReadWriteLock().readLock().unlock(); filterList.getReadWriteLock().readLock().lock(); for (TreeAsset treeAsset : filterList) { if (treeAsset.isItem()) { filterList.getReadWriteLock().readLock().unlock();
filterList = new FilterList<MyMarketOrder>(sortedList); eventList.getReadWriteLock().readLock().unlock(); filterList.addListEventListener(listener);
/** * @param source the raw elements that will be tested by the given * <code>matcher</code> * @param matcher the logic which determines whether an element is counted * in the value reported by this Calculation */ public ConditionalCount(EventList<E> source, Matcher<E> matcher) { super(new Integer(0)); // the user should ideally know nothing about this FilterList, so we // lock the pipeline during its construction so the calling code need // not consider concurrency, which is really an implementation detail source.getReadWriteLock().readLock().lock(); try { filtered = new FilterList<E>(source, matcher); filtered.addListEventListener(this); setValue(new Integer(filtered.size())); } finally { source.getReadWriteLock().readLock().unlock(); } }
/** * Creates a new filter list that uses a TextFilterator. A TextFilterator is something * that I made up. It is basically a class that knows how to take an arbitrary * object and get an array of strings for that object. * * @param filterEdit a text field for typing in the filter text. */ public TextFilterList(EventList source, Text filterEdit, TextFilterator filterator) { super(new FilterList(source)); this.filterEdit = filterEdit; matcherEditor = new TextWidgetMatcherEditor(filterEdit, filterator, false); ((FilterList)this.source).setMatcherEditor(matcherEditor); // handle changes this.source.addListEventListener(this); }
/** * This method selects an appropriate delegate method to perform the * correct work for each of the possible <code>changeType</code>s. This * method does <strong>NOT</strong> acquire any locks and is thus used * during initialization of FilterList. */ private void changeMatcher(MatcherEditor<? super E> matcherEditor, Matcher<? super E> matcher, int changeType) { // first check if this list is already disposed if (!disposed) { // ensure the MatcherEvent is from OUR MatcherEditor if (currentEditor != matcherEditor) throw new IllegalStateException(); switch (changeType) { case MatcherEditor.Event.CONSTRAINED: currentMatcher = matcher; this.constrained(); break; case MatcherEditor.Event.RELAXED: currentMatcher = matcher; this.relaxed(); break; case MatcherEditor.Event.CHANGED: currentMatcher = matcher; this.changed(); break; case MatcherEditor.Event.MATCH_ALL: currentMatcher = Matchers.trueMatcher(); this.matchAll(); break; case MatcherEditor.Event.MATCH_NONE: currentMatcher = Matchers.falseMatcher(); this.matchNone(); break; } } }
@Benchmark @Warmup(iterations = 5) @Measurement(iterations = 10) @Fork(1) public EventList<Element> testSeparatorListFilterOld() { EventList<Element> baseCopy = GlazedLists.eventList(base); FilterList<Element> filterList = new FilterList<>(baseCopy); EventList<Element> sepBase = new SeparatorListOld<>(filterList, elementComparator(), 0, Integer.MAX_VALUE); for (int i = 0; i < 10; i++) { filterList.setMatcher(Matchers.falseMatcher()); filterList.setMatcher(Matchers.trueMatcher()); } return sepBase; }