Class SmiObjectJsonMatcher
java.lang.Object
com.snmp4j.smi.util.json.SmiObjectJsonMatcher
- All Implemented Interfaces:
SmiObjectFilter<SmiObject>
Matcher class for comparing JSON generated by SmiObjectJsonConverter against a pattern JSON
that contains regular expressions for field values.
- Since:
- 2.0
- Version:
- 2.0
- Author:
- Frank Fock
-
Constructor Summary
ConstructorsConstructorDescriptionSmiObjectJsonMatcher(String patternJsonString) Creates a new matcher with the given pattern JSON string.SmiObjectJsonMatcher(String patternJsonString, boolean strictMode) Creates a new matcher with the given pattern JSON string. -
Method Summary
Modifier and TypeMethodDescriptionGets the list of match errors from the last match operation.Gets a formatted string of all match errors.booleanMatches a SmiObject against the pattern by first converting it to JSON.booleanMatches a JSON string generated by SmiObjectJsonConverter against the pattern.booleanpassesFilter(SmiObject smiObject) Determines if the supplied smiObject passes the filter or not.booleanpassesFilter(SmiType smiType) Determines if the givenSmiTypegenerally passes this filter.static booleanquickMatch(String patternJson, SmiObject smiObject) Convenience method to create a matcher and match in one call.static booleanquickMatch(String patternJson, String actualJson) Convenience method to create a matcher and match JSON strings in one call.
-
Constructor Details
-
SmiObjectJsonMatcher
Creates a new matcher with the given pattern JSON string.- Parameters:
patternJsonString- JSON string containing regex patterns for matching- Throws:
IllegalArgumentException- if the pattern JSON is invalid
-
SmiObjectJsonMatcher
Creates a new matcher with the given pattern JSON string.- Parameters:
patternJsonString- JSON string containing regex patterns for matchingstrictMode- if true, all fields in actual JSON must be present in a pattern- Throws:
IllegalArgumentException- if the pattern JSON is invalid
-
-
Method Details
-
matches
Matches a SmiObject against the pattern by first converting it to JSON.- Parameters:
smiObject- the SmiObject to match- Returns:
- true if the object matches the pattern, false otherwise
-
matches
Matches a JSON string generated by SmiObjectJsonConverter against the pattern.- Parameters:
actualJsonString- the actual JSON string to match- Returns:
- true if the JSON matches the pattern, false otherwise
-
getMatchErrors
-
getMatchErrorsAsString
Gets a formatted string of all match errors.- Returns:
- formatted error string
-
quickMatch
-
quickMatch
-
passesFilter
Description copied from interface:SmiObjectFilterDetermines if the supplied smiObject passes the filter or not.- Specified by:
passesFilterin interfaceSmiObjectFilter<SmiObject>- Parameters:
smiObject- the smiObject to check.- Returns:
trueif smiObject passes the filter orfalseotherwise.
-
passesFilter
Description copied from interface:SmiObjectFilterDetermines if the givenSmiTypegenerally passes this filter. This method is called for performance optimization beforeSmiObjectFilter.passesFilter(SmiObject).- Specified by:
passesFilterin interfaceSmiObjectFilter<SmiObject>- Parameters:
smiType- the SMI object type.- Returns:
trueif smiObjects of smiType passes the filter orfalseotherwise.
-