public class NumericCondition extends Object implements IImporterCondition, IXMLConfigurable
A condition based on the numeric value(s) of matching
metadata fields, supporting decimals. If multiple values are found for a
field, only one of them needs to match for this condition to be true.
If the value is not a valid number, it is considered not to be matching
(i.e., false
).
The decimal character is expected to be a dot (".").
The default operator is "eq" (equals).
This condition accepts zero, one, or two value matchers:
true
).
Operators can be parsed using symbols or text abbreviations. Text abbreviations are useful when you do now want to concern yourself when used in XML. Possible representations are:
Symbol | Abbreviation | Meaning |
---|---|---|
> | gt | greater than |
>=, => | ge | greater equal |
< | lt | lower than |
<=, =< | le | lowe equal |
=, == | eq,is | equals |
<condition
class="com.norconex.importer.handler.condition.impl.NumericCondition">
<fieldMatcher>(expression matching one or more numeric fields)</fieldMatcher>
<!-- Use two value matchers if you want to define a range. -->
<valueMatcher
operator="[gt|ge|lt|le|eq]"
number="(number)"/>
</condition>
<condition
class="NumericCondition">
<fieldMatcher>age</fieldMatcher>
<valueMatcher
operator="ge"
number="20"/>
<valueMatcher
operator="lt"
number="30"/>
</condition>
Let's say you are importing customer profile documents and you have a field called "age" and you need to only consider documents for customers in their twenties (greater or equal to 20, but lower than 30). The above example would achieve that.
Modifier and Type | Class and Description |
---|---|
static class |
NumericCondition.ValueMatcher |
Constructor and Description |
---|
NumericCondition() |
NumericCondition(TextMatcher fieldMatcher) |
NumericCondition(TextMatcher fieldMatcher,
NumericCondition.ValueMatcher valueMatcher) |
NumericCondition(TextMatcher fieldMatcher,
NumericCondition.ValueMatcher rangeStart,
NumericCondition.ValueMatcher rangeEnd) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
TextMatcher |
getFieldMatcher()
Gets the text matcher of field names.
|
NumericCondition.ValueMatcher |
getValueMatcher() |
NumericCondition.ValueMatcher |
getValueMatcherRangeEnd() |
int |
hashCode() |
void |
loadFromXML(XML xml) |
void |
saveToXML(XML xml) |
void |
setFieldMatcher(TextMatcher fieldMatcher)
Sets the text matcher of field names.
|
void |
setValueMatcher(NumericCondition.ValueMatcher firstValueMatcher) |
void |
setValueMatcherRangeEnd(NumericCondition.ValueMatcher secondValueMatcher) |
boolean |
testDocument(HandlerDoc doc,
InputStream input,
ParseState parseState)
Tests a given document.
|
String |
toString() |
public NumericCondition()
public NumericCondition(TextMatcher fieldMatcher)
public NumericCondition(TextMatcher fieldMatcher, NumericCondition.ValueMatcher valueMatcher)
public NumericCondition(TextMatcher fieldMatcher, NumericCondition.ValueMatcher rangeStart, NumericCondition.ValueMatcher rangeEnd)
public TextMatcher getFieldMatcher()
public void setFieldMatcher(TextMatcher fieldMatcher)
fieldMatcher
- text matcherpublic NumericCondition.ValueMatcher getValueMatcher()
public void setValueMatcher(NumericCondition.ValueMatcher firstValueMatcher)
public NumericCondition.ValueMatcher getValueMatcherRangeEnd()
public void setValueMatcherRangeEnd(NumericCondition.ValueMatcher secondValueMatcher)
public boolean testDocument(HandlerDoc doc, InputStream input, ParseState parseState) throws ImporterHandlerException
IImporterCondition
testDocument
in interface IImporterCondition
doc
- the document to testinput
- document contentparseState
- whether the document has been parsed already or not (a
parsed document should normally be text-based)true
if the condition evaluates as suchImporterHandlerException
- problem reading the documentpublic void loadFromXML(XML xml)
loadFromXML
in interface IXMLConfigurable
public void saveToXML(XML xml)
saveToXML
in interface IXMLConfigurable
Copyright © 2009–2023 Norconex Inc.. All rights reserved.