File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
custom/src/main/java/com/isolpro/custom Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .isolpro .custom ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .List ;
5+
6+ public abstract class ListFilter <T > {
7+
8+ private final Callback <List <T >> onFilterChanged ;
9+ private List <T > items , filteredItems ;
10+
11+ public ListFilter (Callback <List <T >> onFilterChanged ) {
12+ this .onFilterChanged = onFilterChanged ;
13+ }
14+
15+ public void setItems (List <T > items ) {
16+ this .items = items ;
17+
18+ notifyFilterChanged ();
19+ }
20+
21+ protected abstract boolean compare (T item );
22+
23+ public void clearFilters () {
24+ notifyFilterChanged ();
25+ }
26+
27+ private void filter () {
28+ filteredItems = new ArrayList <>();
29+
30+ if (items == null ) return ;
31+
32+ for (T item : items ) {
33+ if (compare (item ))
34+ filteredItems .add (item );
35+ }
36+ }
37+
38+ protected void notifyFilterChanged () {
39+ filter ();
40+
41+ if (onFilterChanged != null )
42+ onFilterChanged .exec (filteredItems );
43+ }
44+
45+ public List <T > getFilteredItems () {
46+ return filteredItems ;
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments