Class SearchCompiler
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.search.SearchCompiler
-
public class SearchCompiler extends java.lang.Object
Implements a google-like search.
Grammar:expression = fact | expression fact expression fact fact = ( expression ) -fact term? term=term term:term term
- Since:
- 12656 (moved from actions.search package)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SearchCompiler.AbstractBinaryMatch
A binary search operator which may take data parameters.static class
SearchCompiler.Always
Matches every OsmPrimitive.static class
SearchCompiler.And
Matches if both left and right expressions match.private static class
SearchCompiler.Any
Match a string in any tags (key or value), with optional regex and case insensitivity.private static class
SearchCompiler.AreaSize
Matches if the size of the area is within the given rangestatic interface
SearchCompiler.BinaryMatchFactory
A factor for gettingSearchCompiler.AbstractBinaryMatch
objectsstatic class
SearchCompiler.BooleanMatch
Matches if the value of the corresponding key is ''yes'', ''true'', ''1'' or ''on''.private static class
SearchCompiler.ChangesetId
Matches objects with a changeset ID in the given range.static class
SearchCompiler.Child
Matches objects if they are children of the expressionprivate static class
SearchCompiler.Closed
Matches ways which are closed (i.e.static class
SearchCompiler.CoreSimpleMatchFactory
The core factory for "simple"SearchCompiler.Match
objectsstatic class
SearchCompiler.CoreUnaryMatchFactory
The coreSearchCompiler.UnaryMatch
factoryprivate static class
SearchCompiler.Deleted
Matches all objects that have been deletedstatic class
SearchCompiler.ExactKeyValue
Matches objects with the exact given key-value pair.static class
SearchCompiler.ExactType
Filter OsmPrimitives based off of the base primitive typeprivate static class
SearchCompiler.HasRole
Matches relations with a member of the given roleprivate static class
SearchCompiler.Id
Matches objects with ID in the given range.static class
SearchCompiler.InArea
Matches objects within the given bounds.private static class
SearchCompiler.Incomplete
Match objects that are incomplete, where only id and type are known.static class
SearchCompiler.InDataSourceArea
Matches objects within source area ("downloaded area").static class
SearchCompiler.KeyValue
Matches objects with the given key-value pair.private static class
SearchCompiler.MapCSSMatch
static class
SearchCompiler.Match
Base class for all search criteria.private static interface
SearchCompiler.MatchFactory
Classes implementing this interface can provide Match operators.static interface
SearchCompiler.MatchSupplier
Classes implementing this interface can provide Match instances themselves and do not rely oncompile(String)
.private static class
SearchCompiler.MemberCountRange
private static class
SearchCompiler.Modified
Matches all objects that have been modified, created, or undeletedstatic class
SearchCompiler.Never
Never matches any OsmPrimitive.private static class
SearchCompiler.New
Matches objects that are new (i.e.private static class
SearchCompiler.NodeCountRange
Matches ways with a number of nodes in given rangestatic class
SearchCompiler.Not
Inverts the match.static class
SearchCompiler.NotOutsideDataSourceArea
Matches objects which are not outside the source area ("downloaded area").private static class
SearchCompiler.Nth
Matches the n-th object of a relation and/or the n-th node of a way.static class
SearchCompiler.Or
Matches if the left OR the right expression match.static class
SearchCompiler.Parent
Matches objects if they are parents of the expressionprivate static class
SearchCompiler.Preset
Matches presets.private static class
SearchCompiler.RangeMatch
Matches objects with properties in a certain range.private static class
SearchCompiler.RoleMatch
Matches objects with the given relation role (i.e.private static class
SearchCompiler.Selected
Matches all objects currently selectedstatic interface
SearchCompiler.SimpleMatchFactory
A factory for gettingSearchCompiler.Match
objectsprivate static class
SearchCompiler.TagCountRange
Matches objects with a number of tags in given rangestatic class
SearchCompiler.TaggedMatch
A common subclass ofSearchCompiler.Match
for matching against tagsprivate static class
SearchCompiler.TimestampRange
Matches objects with a timestamp in given rangestatic class
SearchCompiler.UnaryMatch
A unary search operator which may take data parameters.static interface
SearchCompiler.UnaryMatchFactory
A factory for gettingSearchCompiler.UnaryMatch
objectsprivate static class
SearchCompiler.Untagged
Matches objects that don't have any interesting tags (i.e.static class
SearchCompiler.UserMatch
Matches objects last changed by the given username.static class
SearchCompiler.ValueComparison
Match a primitive based off of a value comparison.private static class
SearchCompiler.Version
Matches objects with a version number in the given range.private static class
SearchCompiler.WayCountRange
Matches objects with the number of referring/contained ways in the given rangeprivate static class
SearchCompiler.WayLength
Matches if the length of a way is within the given rangestatic class
SearchCompiler.Xor
Matches if the left OR the right expression match, but not both.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
ALL_IN_DOWNLOADED_AREA
private static java.lang.String
AREA_SIZE
private static java.util.Map<java.lang.String,SearchCompiler.BinaryMatchFactory>
binaryMatchFactoryMap
private boolean
caseSensitive
private static java.lang.String
CHANGESET
private static java.lang.String
CLOSED
private static java.lang.String
DELETED
private static java.lang.String
IN_DOWNLOADED_AREA
private static java.lang.String
INCOMPLETE
private static java.lang.String
MEMBERS
private static java.lang.String
MODIFIED
private static java.lang.String
NODES
private static java.lang.String
RANGE_OF_NUMBERS_EXPECTED
private static java.lang.String
REGEX_ERROR_MESSAGE
private static java.lang.String
REGEX_ERROR_MESSAGE_NO_POSITION
private boolean
regexSearch
private static java.lang.String
SELECTED
private static java.util.Map<java.lang.String,SearchCompiler.SimpleMatchFactory>
simpleMatchFactoryMap
private static java.lang.String
TIMESTAMP
private PushbackTokenizer
tokenizer
private static java.util.Map<java.lang.String,SearchCompiler.UnaryMatchFactory>
unaryMatchFactoryMap
private static java.lang.String
UNTAGGED
private static java.lang.String
VERSION
private static java.lang.String
WAY_LENGTH
private static java.lang.String
WAYS
-
Constructor Summary
Constructors Constructor Description SearchCompiler(boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer)
Constructs a newSearchCompiler
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addMatchFactory(SearchCompiler.MatchFactory factory)
Add (register) MatchFactory with SearchCompilerstatic java.lang.String
buildSearchStringForTag(java.lang.String key, java.lang.String value)
Builds a search string for the given tag.static SearchCompiler.Match
compile(java.lang.String searchStr)
Compiles the search expression.static SearchCompiler.Match
compile(SearchSetting setting)
Compiles the search expression.(package private) static SearchCompiler.Match
compileMapCSS(java.lang.String mapCSS)
(package private) static java.lang.String
escapeStringForSearch(java.lang.String s)
private SearchCompiler.Match
getValidate(SearchCompiler.UnaryMatchFactory unaryFactory, java.lang.String key, PushbackTokenizer tokenizer)
SearchCompiler.Match
parse()
Parse search string.private SearchCompiler.Match
parseExpression()
Parse expression.private java.util.List<java.lang.Object>
parseExpressionStep1()
private static SearchCompiler.Match
parseExpressionStep2(java.util.List<java.lang.Object> list)
private SearchCompiler.Match
parseFactor()
Parse next factor (a search operator or search term).private SearchCompiler.Match
parseFactor(java.lang.String errorMessage)
private static int
regexFlags(boolean caseSensitive)
-
-
-
Field Detail
-
caseSensitive
private final boolean caseSensitive
-
regexSearch
private final boolean regexSearch
-
REGEX_ERROR_MESSAGE
private static final java.lang.String REGEX_ERROR_MESSAGE
-
REGEX_ERROR_MESSAGE_NO_POSITION
private static final java.lang.String REGEX_ERROR_MESSAGE_NO_POSITION
-
RANGE_OF_NUMBERS_EXPECTED
private static final java.lang.String RANGE_OF_NUMBERS_EXPECTED
-
tokenizer
private final PushbackTokenizer tokenizer
-
simpleMatchFactoryMap
private static final java.util.Map<java.lang.String,SearchCompiler.SimpleMatchFactory> simpleMatchFactoryMap
-
unaryMatchFactoryMap
private static final java.util.Map<java.lang.String,SearchCompiler.UnaryMatchFactory> unaryMatchFactoryMap
-
binaryMatchFactoryMap
private static final java.util.Map<java.lang.String,SearchCompiler.BinaryMatchFactory> binaryMatchFactoryMap
-
AREA_SIZE
private static final java.lang.String AREA_SIZE
- See Also:
- Constant Field Values
-
CHANGESET
private static final java.lang.String CHANGESET
- See Also:
- Constant Field Values
-
CLOSED
private static final java.lang.String CLOSED
- See Also:
- Constant Field Values
-
DELETED
private static final java.lang.String DELETED
- See Also:
- Constant Field Values
-
INCOMPLETE
private static final java.lang.String INCOMPLETE
- See Also:
- Constant Field Values
-
IN_DOWNLOADED_AREA
private static final java.lang.String IN_DOWNLOADED_AREA
- See Also:
- Constant Field Values
-
ALL_IN_DOWNLOADED_AREA
private static final java.lang.String ALL_IN_DOWNLOADED_AREA
- See Also:
- Constant Field Values
-
MEMBERS
private static final java.lang.String MEMBERS
- See Also:
- Constant Field Values
-
MODIFIED
private static final java.lang.String MODIFIED
- See Also:
- Constant Field Values
-
NODES
private static final java.lang.String NODES
- See Also:
- Constant Field Values
-
SELECTED
private static final java.lang.String SELECTED
- See Also:
- Constant Field Values
-
TIMESTAMP
private static final java.lang.String TIMESTAMP
- See Also:
- Constant Field Values
-
UNTAGGED
private static final java.lang.String UNTAGGED
- See Also:
- Constant Field Values
-
VERSION
private static final java.lang.String VERSION
- See Also:
- Constant Field Values
-
WAYS
private static final java.lang.String WAYS
- See Also:
- Constant Field Values
-
WAY_LENGTH
private static final java.lang.String WAY_LENGTH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SearchCompiler
public SearchCompiler(boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer)
Constructs a newSearchCompiler
.- Parameters:
caseSensitive
-true
to perform a case-sensitive searchregexSearch
-true
to perform a regex-based searchtokenizer
- to split the search string into tokens
-
-
Method Detail
-
addMatchFactory
public static void addMatchFactory(SearchCompiler.MatchFactory factory)
Add (register) MatchFactory with SearchCompiler- Parameters:
factory
- match factory
-
compile
public static SearchCompiler.Match compile(java.lang.String searchStr) throws SearchParseError
Compiles the search expression.- Parameters:
searchStr
- the search expression- Returns:
- a
SearchCompiler.Match
object for the expression - Throws:
SearchParseError
- if an error has been encountered while compiling- See Also:
compile(SearchSetting)
-
compile
public static SearchCompiler.Match compile(SearchSetting setting) throws SearchParseError
Compiles the search expression.- Parameters:
setting
- the settings to use- Returns:
- a
SearchCompiler.Match
object for the expression - Throws:
SearchParseError
- if an error has been encountered while compiling- See Also:
compile(String)
-
compileMapCSS
static SearchCompiler.Match compileMapCSS(java.lang.String mapCSS) throws SearchParseError
- Throws:
SearchParseError
-
parse
public SearchCompiler.Match parse() throws SearchParseError
Parse search string.- Returns:
- match determined by search string
- Throws:
SearchParseError
- if search expression cannot be parsed
-
parseExpression
private SearchCompiler.Match parseExpression() throws SearchParseError
Parse expression.- Returns:
- match determined by parsing expression
- Throws:
SearchParseError
- if search expression cannot be parsed
-
parseExpressionStep1
private java.util.List<java.lang.Object> parseExpressionStep1() throws SearchParseError
- Throws:
SearchParseError
-
parseExpressionStep2
private static SearchCompiler.Match parseExpressionStep2(java.util.List<java.lang.Object> list)
-
parseFactor
private SearchCompiler.Match parseFactor() throws SearchParseError
Parse next factor (a search operator or search term).- Returns:
- match determined by parsing factor string
- Throws:
SearchParseError
- if search expression cannot be parsed
-
parseFactor
private SearchCompiler.Match parseFactor(java.lang.String errorMessage) throws SearchParseError
- Throws:
SearchParseError
-
getValidate
private SearchCompiler.Match getValidate(SearchCompiler.UnaryMatchFactory unaryFactory, java.lang.String key, PushbackTokenizer tokenizer) throws SearchParseError
- Throws:
SearchParseError
-
regexFlags
private static int regexFlags(boolean caseSensitive)
-
escapeStringForSearch
static java.lang.String escapeStringForSearch(java.lang.String s)
-
buildSearchStringForTag
public static java.lang.String buildSearchStringForTag(java.lang.String key, java.lang.String value)
Builds a search string for the given tag. If value is empty, the existence of the key is checked.- Parameters:
key
- the tag keyvalue
- the tag value- Returns:
- a search string for the given tag
-
-