public abstract class SimpleReplaceHandler extends SimpleSearchHandler implements IReplaceHandler
Lets searching and replacing ADQL objects which match with the condition defined in the function SimpleSearchHandler.match(ADQLObject)
.
RemoveHandler
Modifier and Type | Field and Description |
---|---|
protected int |
nbReplacement
Count matching objects which have been replaced successfully.
|
results
Constructor and Description |
---|
SimpleReplaceHandler()
Builds a SimpleReplaceHandler:
|
SimpleReplaceHandler(boolean recursive)
Builds a SimpleReplaceHandler which does not stop at the first match.
|
SimpleReplaceHandler(boolean recursive,
boolean onlyFirstMatch)
Builds a SimpleReplaceHandler.
|
Modifier and Type | Method and Description |
---|---|
protected ADQLObject |
addMatchAndReplace(ADQLObject matchObj,
ADQLIterator it)
Adds the given ADQL object as one result of the research, and then replace its reference
inside its parent.
|
int |
getNbReplacement()
Gets the number of matched objects which have been successfully replaced.
|
protected abstract ADQLObject |
getReplacer(ADQLObject objToReplace)
Gets (generate on the fly or not) an ADQLObject which must replace the given one (expected to be an ADQLObject that has matched).
|
protected void |
reset()
Resets this handler before the beginning of the research:
by default, the list of results is cleared.
|
void |
searchAndReplace(ADQLObject startObj)
Searches all matching ADQL objects from the given ADQL object (included)
and replaces them by their corresponding ADQL object.
|
addMatch, getNbMatch, goInto, isFinished, isRecursive, iterator, match, onlyFirstMatch, search, setOnlyFirstMatch, setRecursive
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getNbMatch, iterator, search
protected int nbReplacement
public SimpleReplaceHandler()
Builds a SimpleReplaceHandler:
public SimpleReplaceHandler(boolean recursive)
recursive
- true to search also in sub-queries, false otherwise.public SimpleReplaceHandler(boolean recursive, boolean onlyFirstMatch)
recursive
- true to search also in sub-queries, false otherwise.onlyFirstMatch
- true to stop at the first match, false otherwise.public int getNbReplacement()
IReplaceHandler
getNbReplacement
in interface IReplaceHandler
protected void reset()
SimpleSearchHandler
reset
in class SimpleSearchHandler
protected ADQLObject addMatchAndReplace(ADQLObject matchObj, ADQLIterator it)
Adds the given ADQL object as one result of the research, and then replace its reference inside its parent.
Thus, the matched item added in the list is no longer available in its former parent.
Warning: the second parameter (it) may be null if the given match is the root search object itself.
matchObj
- An ADQL object which has matched to the research criteria.it
- The iterator from which the matched ADQL object has been extracted.null
if the item has been removed,
or the object given in parameter if there was no replacement.public void searchAndReplace(ADQLObject startObj)
IReplaceHandler
searchAndReplace
in interface IReplaceHandler
startObj
- The ADQL object from which the search must start.protected abstract ADQLObject getReplacer(ADQLObject objToReplace) throws java.lang.UnsupportedOperationException
Gets (generate on the fly or not) an ADQLObject which must replace the given one (expected to be an ADQLObject that has matched).
IMPORTANT: It is the responsibility of the object which calls this method to apply the replacement !
Note: If the returned value is null it may be interpreted as a removal of the matched ADQL object. Note also that it is still the responsibility of the object which calls this method to apply the removal !
objToReplace
- The ADQL item to replace.java.lang.UnsupportedOperationException
- If the this method must not be used.