Class SimpleReplaceHandler
- All Implemented Interfaces:
IReplaceHandler,ISearchHandler,Iterable<ADQLObject>
- Direct Known Subclasses:
RemoveHandler
Lets searching and replacing ADQL objects which match with the condition defined in the function SimpleSearchHandler.match(ADQLObject).
- By default, this replace handler does not search recursively (that's to say, it does not search in sub-queries).
- By default, this replace handler does not stop to the first matching object.
- The matching objects are simply collected in an ArrayList.
- Matching objects are collected before their replacement.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intCount matching objects which have been replaced successfully.Fields inherited from class adql.search.SimpleSearchHandler
results -
Constructor Summary
ConstructorsConstructorDescriptionBuilds a SimpleReplaceHandler:SimpleReplaceHandler(boolean recursive) Builds a SimpleReplaceHandler which does not stop at the first match.SimpleReplaceHandler(boolean recursive, boolean onlyFirstMatch) Builds a SimpleReplaceHandler. -
Method Summary
Modifier and TypeMethodDescriptionprotected ADQLObjectaddMatchAndReplace(ADQLObject matchObj, ADQLIterator it) Adds the given ADQL object as one result of the research, and then replace its reference inside its parent.intGets the number of matched objects which have been successfully replaced.protected abstract ADQLObjectgetReplacer(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 voidreset()Resets this handler before the beginning of the research: by default, the list of results is cleared.voidsearchAndReplace(ADQLObject startObj) Searches all matching ADQL objects from the given ADQL object (included) and replaces them by their corresponding ADQL object.Methods inherited from class adql.search.SimpleSearchHandler
addMatch, getNbMatch, goInto, isFinished, isRecursive, iterator, match, onlyFirstMatch, search, setOnlyFirstMatch, setRecursiveMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface adql.search.ISearchHandler
getNbMatch, iterator, searchMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
nbReplacement
protected int nbReplacementCount matching objects which have been replaced successfully.
-
-
Constructor Details
-
SimpleReplaceHandler
public SimpleReplaceHandler()Builds a SimpleReplaceHandler:
- not recursive,
- and which does not stop at the first match.
-
SimpleReplaceHandler
public SimpleReplaceHandler(boolean recursive) Builds a SimpleReplaceHandler which does not stop at the first match.- Parameters:
recursive- true to search also in sub-queries, false otherwise.
-
SimpleReplaceHandler
public SimpleReplaceHandler(boolean recursive, boolean onlyFirstMatch) Builds a SimpleReplaceHandler.- Parameters:
recursive- true to search also in sub-queries, false otherwise.onlyFirstMatch- true to stop at the first match, false otherwise.
-
-
Method Details
-
getNbReplacement
public int getNbReplacement()Description copied from interface:IReplaceHandlerGets the number of matched objects which have been successfully replaced.- Specified by:
getNbReplacementin interfaceIReplaceHandler- Returns:
- The number of replaced objects.
-
reset
protected void reset()Description copied from class:SimpleSearchHandlerResets this handler before the beginning of the research: by default, the list of results is cleared.- Overrides:
resetin classSimpleSearchHandler
-
addMatchAndReplace
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.
- Parameters:
matchObj- An ADQL object which has matched to the research criteria.it- The iterator from which the matched ADQL object has been extracted.- Returns:
- The match item after replacement if any replacement has occurred,
or
nullif the item has been removed, or the object given in parameter if there was no replacement.
-
searchAndReplace
Description copied from interface:IReplaceHandlerSearches all matching ADQL objects from the given ADQL object (included) and replaces them by their corresponding ADQL object.- Specified by:
searchAndReplacein interfaceIReplaceHandler- Parameters:
startObj- The ADQL object from which the search must start.
-
getReplacer
protected abstract ADQLObject getReplacer(ADQLObject objToReplace) throws 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 !
- Parameters:
objToReplace- The ADQL item to replace.- Returns:
- The replacement ADQL item.
- Throws:
UnsupportedOperationException- If the this method must not be used.
-