com.optimaize.langdetect.text.MultiTextFilter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of language-detector Show documentation
Show all versions of language-detector Show documentation
Language Detection Library for Java.
The newest version!
package com.optimaize.langdetect.text;
import com.google.common.collect.ImmutableList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* Groups multiple {@link com.optimaize.langdetect.text.TextFilter}s as one and runs them in the given order.
*
* @author Fabian Kessler
*/
public class MultiTextFilter implements TextFilter {
@Nullable
private final List filters;
/**
* @param filters may be empty by definition
*/
public MultiTextFilter(@NotNull List filters) {
if (filters.isEmpty()) {
this.filters = null;
} else {
this.filters = ImmutableList.copyOf(filters);
}
}
@Override
public String filter(CharSequence text) {
if (filters==null) {
return text.toString();
} else {
String modified = text.toString();
for (TextFilter filter : filters) {
modified = filter.filter(modified);
}
return modified;
}
}
}