Package net.sf.okapi.common
Class LocaleFilter
- java.lang.Object
-
- net.sf.okapi.common.LocaleFilter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classLocaleFilter.FilterTypeType of locale filter.
-
Constructor Summary
Constructors Constructor Description LocaleFilter()Public constructor.LocaleFilter(String string)Public constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LocaleFilterany()Creates a filter of the Any type.static LocaleFilteranyExcept(LocaleId... localeIds)Creates a filter filtering out the given locales.static LocaleFilteranyOf(LocaleId... localeIds)Creates a filter allowing only the given locales.static LocaleFilterbuild(String string)Builds a filter from a configuration string.LocaleFilterexclude(List<LocaleId> localeIds)Disallows the locales from a given list of locales.LocaleFilterexclude(Set<LocaleId> localeIds)Disallows the locales from a given set of locales.LocaleFilterexclude(LocaleFilter filter)Disallows all locales allowed in a given locale filter.LocaleFilterexclude(LocaleId localeId)Disallows a given locale.LocaleFilterexclude(LocaleId... localeIds)Disallows the locales from a given array of locales.LocaleFilterexcludeLanguage(String language)Disallows the locales which language matches a given language.LocaleFilterexcludeLanguage(String... languages)Disallows the locales which language matches any of the languages from a given array.LocaleFilterexcludePattern(String regex)Disallows all locales matching a given regular expression.LocaleFilterexcludePattern(String regex, int flags)Disallows all locales matching a given regular expression with a given set of regex flags.LocaleFilterexcludeRegion(String region)Disallows the locales which region matches a given region.LocaleFilterexcludeRegion(String... regions)Disallows the locales which region matches any of the regions from a given array.LocaleFilterexcludeUserPart(String userPart)Disallows the locales which user part matches a given user part.LocaleFilterexcludeUserPart(String... userParts)Disallows the locales which user part matches any of the user parts from a given array.Set<LocaleId>filter(LocaleId... localeIds)Creates a subset of the locales from a given array, which are allowed by this locale filter.LocaleFilterfromString(String string)Configures this locale filter from a given configuration string.List<LocaleId>getExcludes()Gets a list of disallowed locales.List<String>getExplicitLocaleIds()If the filter contains only explicitly listed locales (no regex patterns or masks), then returns the list of locale tags of those locales.static StringgetExplicitLocaleIds(String string)Determines if a given string contains only explicitly listed locales.List<LocaleId>getIncludes()Gets a list of allowed locales.List<String>getLanguageExcludes()Gets a list of disallowed languages.List<String>getLanguageIncludes()Gets a list of allowed languages.List<Pattern>getPatternExcludes()Gets a list of compiled regular expressions for disallowed locales.List<Pattern>getPatternIncludes()Gets a list of compiled regular expressions for allowed locales.List<String>getRegionExcludes()Gets a list of disallowed regions.List<String>getRegionIncludes()Gets a list of allowed regions.protected LocaleFilter.FilterTypegetType()Helper method.List<String>getUserPartExcludes()Gets a list of disallowed user parts.List<String>getUserPartIncludes()Gets a list of allowed user parts.LocaleFilterinclude(List<LocaleId> localeIds)Allows the locales from a given list of locales.LocaleFilterinclude(Set<LocaleId> localeIds)Allows the locales from a given set of locales.LocaleFilterinclude(LocaleFilter filter)Allows all locales allowed in a given locale filter.LocaleFilterinclude(LocaleId localeId)Allows a given locale.LocaleFilterinclude(LocaleId... localeIds)Allows the locales from a given array of locales.LocaleFilterincludeLanguage(String language)Allows the locales which language matches a given language.LocaleFilterincludeLanguage(String... languages)Allows the locales which language matches any of the languages from a given array.LocaleFilterincludePattern(String regex)Allows all locales matching a given regular expression.LocaleFilterincludePattern(String regex, int flags)Allows all locales matching a given regular expression with a given set of regex flags.LocaleFilterincludeRegion(String region)Allows the locales which region matches a given region.LocaleFilterincludeRegion(String... regions)Allows the locales which region matches any of the regions from a given array.LocaleFilterincludeUserPart(String userPart)Allows the locales which user part matches a given user part.LocaleFilterincludeUserPart(String... userParts)Allows the locales which user part matches any of the user parts from a given array.booleanisEmpty()Detects if after construction this locale filter was configured with includeXX(), excludeXX().booleanmatches(LocaleId localeId)Returns true if a given locale is allowed by this locale filter.static LocaleFilternone()Creates a filter of the None type.LocaleFilterreset()Resets this locale filter to its original right-after-construction state (all settings made with includeXX(), excludeXX() are neglected).protected voidsetType(LocaleFilter.FilterType type)Helper method.StringtoString()Constructs a configuration string for this locale filter.
-
-
-
Constructor Detail
-
LocaleFilter
public LocaleFilter()
Public constructor. Sets filter type to Any.
-
LocaleFilter
public LocaleFilter(String string)
Public constructor. Constructs filter from a string.- Parameters:
string- the configuration string of locale filter. SeefromString(java.lang.String)for details.
-
-
Method Detail
-
any
public static LocaleFilter any()
Creates a filter of the Any type.- Returns:
- a newly created locale filter.
-
none
public static LocaleFilter none()
Creates a filter of the None type.- Returns:
- a newly created locale filter.
-
anyOf
public static LocaleFilter anyOf(LocaleId... localeIds)
Creates a filter allowing only the given locales.- Parameters:
localeIds- an array of allowed LocaleId objects.- Returns:
- a newly created locale filter.
-
anyExcept
public static LocaleFilter anyExcept(LocaleId... localeIds)
Creates a filter filtering out the given locales.- Parameters:
localeIds- an array of the LocaleId objects to disallow.- Returns:
- a newly created locale filter.
-
build
public static LocaleFilter build(String string)
Builds a filter from a configuration string. SeefromString(java.lang.String)for details on the string format.- Parameters:
string- the parameters string.- Returns:
- a newly created locale filter object.
-
include
public LocaleFilter include(LocaleId localeId)
Allows a given locale.- Parameters:
localeId- the given locale.- Returns:
- this locale filter.
-
include
public LocaleFilter include(LocaleId... localeIds)
Allows the locales from a given array of locales.- Parameters:
localeIds- the given array of locales.- Returns:
- this locale filter.
-
include
public LocaleFilter include(Set<LocaleId> localeIds)
Allows the locales from a given set of locales.- Parameters:
localeIds- the given set of locales.- Returns:
- this locale filter.
-
include
public LocaleFilter include(List<LocaleId> localeIds)
Allows the locales from a given list of locales.- Parameters:
localeIds- the given list of locales.- Returns:
- this locale filter.
-
include
public LocaleFilter include(LocaleFilter filter)
Allows all locales allowed in a given locale filter.- Parameters:
filter- the given locale filter.- Returns:
- this locale filter.
-
includePattern
public LocaleFilter includePattern(String regex, int flags)
Allows all locales matching a given regular expression with a given set of regex flags.- Parameters:
regex- the given regular expression.flags- the given set of regex flags.- Returns:
- this locale filter.
-
includePattern
public LocaleFilter includePattern(String regex)
Allows all locales matching a given regular expression.- Parameters:
regex- the given regular expression.- Returns:
- this locale filter.
-
includeLanguage
public LocaleFilter includeLanguage(String... languages)
Allows the locales which language matches any of the languages from a given array.- Parameters:
languages- the given array of languages.- Returns:
- this locale filter.
-
includeLanguage
public LocaleFilter includeLanguage(String language)
Allows the locales which language matches a given language.- Parameters:
language- the given language.- Returns:
- this locale filter.
-
includeRegion
public LocaleFilter includeRegion(String... regions)
Allows the locales which region matches any of the regions from a given array.- Parameters:
regions- the given array of regions.- Returns:
- this locale filter.
-
includeRegion
public LocaleFilter includeRegion(String region)
Allows the locales which region matches a given region.- Parameters:
region- the given region.- Returns:
- this locale filter.
-
includeUserPart
public LocaleFilter includeUserPart(String... userParts)
Allows the locales which user part matches any of the user parts from a given array.- Parameters:
userParts- the given array of user parts.- Returns:
- this locale filter.
-
includeUserPart
public LocaleFilter includeUserPart(String userPart)
Allows the locales which user part matches a given user part.- Parameters:
userPart- the given user part.- Returns:
- this locale filter.
-
exclude
public LocaleFilter exclude(LocaleId localeId)
Disallows a given locale.- Parameters:
localeId- the given locale.- Returns:
- this locale filter.
-
exclude
public LocaleFilter exclude(LocaleId... localeIds)
Disallows the locales from a given array of locales.- Parameters:
localeIds- the given array of locales.- Returns:
- this locale filter.
-
exclude
public LocaleFilter exclude(Set<LocaleId> localeIds)
Disallows the locales from a given set of locales.- Parameters:
localeIds- the given set of locales.- Returns:
- this locale filter.
-
exclude
public LocaleFilter exclude(List<LocaleId> localeIds)
Disallows the locales from a given list of locales.- Parameters:
localeIds- the given list of locales.- Returns:
- this locale filter.
-
exclude
public LocaleFilter exclude(LocaleFilter filter)
Disallows all locales allowed in a given locale filter.- Parameters:
filter- the given locale filter.- Returns:
- this locale filter.
-
excludePattern
public LocaleFilter excludePattern(String regex, int flags)
Disallows all locales matching a given regular expression with a given set of regex flags.- Parameters:
regex- the given regular expression.flags- the given set of regex flags.- Returns:
- this locale filter.
-
excludePattern
public LocaleFilter excludePattern(String regex)
Disallows all locales matching a given regular expression.- Parameters:
regex- the given regular expression.- Returns:
- this locale filter.
-
excludeLanguage
public LocaleFilter excludeLanguage(String... languages)
Disallows the locales which language matches any of the languages from a given array.- Parameters:
languages- the given array of languages.- Returns:
- this locale filter.
-
excludeLanguage
public LocaleFilter excludeLanguage(String language)
Disallows the locales which language matches a given language.- Parameters:
language- the given language.- Returns:
- this locale filter.
-
excludeRegion
public LocaleFilter excludeRegion(String... regions)
Disallows the locales which region matches any of the regions from a given array.- Parameters:
regions- the given array of regions.- Returns:
- this locale filter.
-
excludeRegion
public LocaleFilter excludeRegion(String region)
Disallows the locales which region matches a given region.- Parameters:
region- the given region.- Returns:
- this locale filter.
-
excludeUserPart
public LocaleFilter excludeUserPart(String... userParts)
Disallows the locales which user part matches any of the user parts from a given array.- Parameters:
userParts- the given array of user parts.- Returns:
- this locale filter.
-
excludeUserPart
public LocaleFilter excludeUserPart(String userPart)
Disallows the locales which user part matches a given user part.- Parameters:
userPart- the given user part.- Returns:
- this locale filter.
-
reset
public LocaleFilter reset()
Resets this locale filter to its original right-after-construction state (all settings made with includeXX(), excludeXX() are neglected).- Returns:
- this locale filter.
-
matches
public boolean matches(LocaleId localeId)
Returns true if a given locale is allowed by this locale filter.- Parameters:
localeId- the given locale.- Returns:
- true if the given locale is allowed, false otherwise.
-
filter
public Set<LocaleId> filter(LocaleId... localeIds)
Creates a subset of the locales from a given array, which are allowed by this locale filter.- Parameters:
localeIds- the given array.- Returns:
- a set of allowed locales.
-
getIncludes
public List<LocaleId> getIncludes()
Gets a list of allowed locales.- Returns:
- the list of allowed locales.
-
getExcludes
public List<LocaleId> getExcludes()
Gets a list of disallowed locales.- Returns:
- the list of disallowed locales.
-
getLanguageIncludes
public List<String> getLanguageIncludes()
Gets a list of allowed languages.- Returns:
- the list of allowed languages.
-
getRegionIncludes
public List<String> getRegionIncludes()
Gets a list of allowed regions.- Returns:
- the list of allowed regions.
-
getUserPartIncludes
public List<String> getUserPartIncludes()
Gets a list of allowed user parts.- Returns:
- the list of allowed user parts.
-
getLanguageExcludes
public List<String> getLanguageExcludes()
Gets a list of disallowed languages.- Returns:
- the list of disallowed languages.
-
getRegionExcludes
public List<String> getRegionExcludes()
Gets a list of disallowed regions.- Returns:
- the list of disallowed regions.
-
getUserPartExcludes
public List<String> getUserPartExcludes()
Gets a list of disallowed user parts.- Returns:
- the list of disallowed user parts.
-
getPatternIncludes
public List<Pattern> getPatternIncludes()
Gets a list of compiled regular expressions for allowed locales.- Returns:
- the list of compiled regular expressions.
-
getPatternExcludes
public List<Pattern> getPatternExcludes()
Gets a list of compiled regular expressions for disallowed locales.- Returns:
- the list of compiled regular expressions.
-
getType
protected LocaleFilter.FilterType getType()
Helper method. Gets the locale filter type (either None or Any).- Returns:
- None or Any locale filter type.
-
setType
protected void setType(LocaleFilter.FilterType type)
Helper method. Sets the locale filter type (either None or Any).- Parameters:
type- None or Any locale filter type.
-
isEmpty
public boolean isEmpty()
Detects if after construction this locale filter was configured with includeXX(), excludeXX().- Returns:
- true if the locale filter was not configured after construction.
-
fromString
public LocaleFilter fromString(String string)
Configures this locale filter from a given configuration string.- Parameters:
string- the given configuration string. The string consists of locale descriptors. The locale descriptors are delimited with a comma or space.* -- field mask, can be used in either language, region, or user part fields of a locale descriptor.
! -- exclude prefix.
@ -- regex prefix.
^ -- regex flags prefix.Examples:
- all locales except English: !en
- only English locales except en-nz: en !en-nz
- all locales except US region: !*-us
- only locales with "win" as user part: *-*-win
- regular expression with flags: @e.?-us ^8
- all locales except English: !en
- Returns:
- this locale filter.
-
toString
public String toString()
Constructs a configuration string for this locale filter.
-
getExplicitLocaleIds
public List<String> getExplicitLocaleIds()
If the filter contains only explicitly listed locales (no regex patterns or masks), then returns the list of locale tags of those locales. If there's at least one mask or pattern, an empty list is returned.- Returns:
- the list of locale tags.
-
getExplicitLocaleIds
public static String getExplicitLocaleIds(String string)
Determines if a given string contains only explicitly listed locales. If the given strin contains only explicitly listed locales (no regex patterns or masks), then returns a string with a space-delimited list of locale tags of those locales. If there's at least one mask or pattern, an empty string is returned.- Parameters:
string- the given locale filter configuration string. SeefromString(java.lang.String)for details.- Returns:
- a string with a space-delimited list of locale tags allowed by this locale filter.
-
-