-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1368 Restructures Message and Event filter framework.
- Loading branch information
Dennis Sheirer
committed
Jul 14, 2023
1 parent
d246fff
commit b0a524c
Showing
121 changed files
with
4,841 additions
and
4,922 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 49 additions & 23 deletions
72
src/main/java/io/github/dsheirer/filter/AllPassFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,61 @@ | ||
/* | ||
* ***************************************************************************** | ||
* Copyright (C) 2014-2023 Dennis Sheirer | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* **************************************************************************** | ||
*/ | ||
|
||
package io.github.dsheirer.filter; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Implements a message filter that passes (true) all messages | ||
* Implements an all-pass filter that automatically passes/allows any presented object. | ||
* | ||
* A key type of String is used, but that makes no difference in how this filter functions. | ||
*/ | ||
@SuppressWarnings( "rawtypes" ) | ||
public class AllPassFilter<T> extends Filter<T> | ||
public class AllPassFilter<T> extends Filter<T, String> | ||
{ | ||
public AllPassFilter() | ||
{ | ||
super( "Allow All Messages" ); | ||
} | ||
|
||
@Override | ||
public boolean passes( T t ) | ||
private static final String KEY = "Other/Unlisted"; | ||
private final AllPassKeyExtractor mKeyExtractor = new AllPassKeyExtractor(); | ||
|
||
/** | ||
* Constructor | ||
* @param name to display for this filter | ||
*/ | ||
public AllPassFilter(String name) | ||
{ | ||
return true; | ||
super(name); | ||
add(new FilterElement<>(KEY)); | ||
} | ||
|
||
@Override | ||
public boolean canProcess( T t ) | ||
{ | ||
return true; | ||
} | ||
public Function getKeyExtractor() | ||
{ | ||
return mKeyExtractor; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings( "unchecked" ) | ||
public List getFilterElements() | ||
{ | ||
return Collections.EMPTY_LIST; | ||
} | ||
/** | ||
* Key extractor that always returns the same (String)key. | ||
*/ | ||
public class AllPassKeyExtractor implements Function<T,String> | ||
{ | ||
@Override | ||
public String apply(T t) | ||
{ | ||
return KEY; | ||
} | ||
} | ||
} |
Oops, something went wrong.