Class ClauseConstraints
- All Implemented Interfaces:
ADQLObject
,Iterable<ADQLConstraint>
- Direct Known Subclasses:
ConstraintsGroup
Represents a clause which deals with ADQLConstraint
s (i.e. WHERE, HAVING).
The logical operators AND (see AND
) and OR (see OR
) are managed
in a separated list by this class. To add a constraint you can use the default add functions or use the one defined by this class:
-
add(String, ADQLConstraint
: which lets you specify the logical operator between the added constraint (index=size()) and the previous one (index=size()-1) in the list. -
add(int, String, ADQLConstraint
: which lets you specify the logical operator between the added constraint (index) and the previous one (index-1) in the list.
If no logical separator is specified the default one is used (see getDefaultSeparator()
).
The only way to set this default separator is during the ClauseConstraints
creation
(see ClauseConstraints(String, String)
).
- Version:
- 01/2012
- Author:
- Grégory Mantelet (CDS)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class adql.query.ADQLList
ADQLList.ADQLListIterator
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The logical separator AND.protected final String
The logical separator used when none is specified during a constraint insertion (by default =OR
).static final String
The logical separator OR (By default, the default separator (seegetDefaultSeparator()
) is equals to OR). -
Constructor Summary
ConstructorsConstructorDescriptionClauseConstraints
(ClauseConstraints toCopy) Builds a ClauseConstraints by copying the given one.ClauseConstraints
(String name) Builds a constraints list with only its name (which will prefix the whole list).ClauseConstraints
(String name, String logicalSep) Builds a constraints list with its name and its default separator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int index, ADQLConstraint constraint) Adds the given item (if not null) at the given position into this clause.void
add
(int index, String logicalSep, ADQLConstraint constraint) Adds the given constraint with the given separator at the given position in the constraints list.boolean
add
(ADQLConstraint constraint) Adds the given item (if not null) at the end of this clause.boolean
add
(String logicalSep, ADQLConstraint constraint) Adds the given constraint with the given separator.static final String
checkSeparator
(String sepToCheck) Checks/Converts the given separator in one of the two logical separators.void
clear()
Clears this clause.getCopy()
Gets a (deep) copy of this ADQL object.final String
String[]
getSeparator
(int index) Returns always ",", except if the index is incorrect (index <= 0 or index >= size()).remove
(int index) Removes the specified ADQL item.set
(int index, ADQLConstraint constraint) Replaces the specified ADQL item by the given one.set
(int index, String logicalSep, ADQLConstraint constraint) Replaces the specified constraint by the given one with the given constraint separator.Methods inherited from class adql.query.ADQLList
adqlIterator, get, getName, getPosition, isEmpty, iterator, setPosition, size, toADQL
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
OR
The logical separator OR (By default, the default separator (seegetDefaultSeparator()
) is equals to OR).- See Also:
-
AND
The logical separator AND.- See Also:
-
defaultSeparator
The logical separator used when none is specified during a constraint insertion (by default =OR
).
-
-
Constructor Details
-
ClauseConstraints
Builds a constraints list with only its name (which will prefix the whole list).
Note: The default separator is automatically set to OR.
- Parameters:
name
- The name/prefix of the list.
-
ClauseConstraints
Builds a constraints list with its name and its default separator.
Note: if the given separator is no
AND
orOR
, the default separator is automatically set toOR
. -
ClauseConstraints
Builds a ClauseConstraints by copying the given one.
- Parameters:
toCopy
- The ClauseConstraints to copy.- Throws:
Exception
- If there is an error during the copy.- See Also:
-
-
Method Details
-
getDefaultSeparator
- Returns:
- The default separator.
-
checkSeparator
Checks/Converts the given separator in one of the two logical separators. If the given separator is neither AND nor OR, then the returned separator isOR
.- Parameters:
sepToCheck
- The separator to check/convert.- Returns:
- The understood separator (OR if neither AND nor OR).
-
add
Description copied from class:ADQLList
Adds the given item (if not null) at the end of this clause.- Overrides:
add
in classADQLList<ADQLConstraint>
- Parameters:
constraint
- The ADQL item to add to this clause.- Returns:
- true if the given item has been successfully added, false otherwise.
- Throws:
NullPointerException
- If the given item is null.- See Also:
-
add
public void add(int index, ADQLConstraint constraint) throws NullPointerException, ArrayIndexOutOfBoundsException Description copied from class:ADQLList
Adds the given item (if not null) at the given position into this clause.- Overrides:
add
in classADQLList<ADQLConstraint>
- Parameters:
index
- Position at which the given item must be added.constraint
- ADQL item to add to this clause.- Throws:
NullPointerException
- If the given item is null.ArrayIndexOutOfBoundsException
- If the index is out of range (index < 0 || index > size()).- See Also:
-
add
Adds the given constraint with the given separator. The separator is added just before the added constraint, that is to say between the last constraint of the list and the added one.- Parameters:
logicalSep
- The separator to add just before the given constraint.constraint
- The constraint to add.- Returns:
- true if the constraint has been successfully added, false otherwise.
- Throws:
NullPointerException
- If the given constraint is null.- See Also:
-
add
public void add(int index, String logicalSep, ADQLConstraint constraint) throws NullPointerException, ArrayIndexOutOfBoundsException Adds the given constraint with the given separator at the given position in the constraints list. The separator is added just before the added constraint, that is to say between the (index-1)-th constraint of the list and the added one (at the index position).- Parameters:
index
- Position at which the given constraint must be added.logicalSep
- The constraints separator to add just before the given constraint.constraint
- The constraint to add.- Throws:
NullPointerException
- If the given constraint is null.ArrayIndexOutOfBoundsException
- If the given index is incorrect (index < 0 || index >= size()).- See Also:
-
set
public ADQLConstraint set(int index, ADQLConstraint constraint) throws NullPointerException, ArrayIndexOutOfBoundsException Description copied from class:ADQLList
Replaces the specified ADQL item by the given one.- Overrides:
set
in classADQLList<ADQLConstraint>
- Parameters:
index
- Position of the item to replace.constraint
- Replacer of the specified ADQL item.- Returns:
- The replaced ADQL item.
- Throws:
NullPointerException
- If the given item is null.ArrayIndexOutOfBoundsException
- If the index is out of range (index < 0 || index > size()).- See Also:
-
set
public ADQLConstraint set(int index, String logicalSep, ADQLConstraint constraint) throws NullPointerException, ArrayIndexOutOfBoundsException Replaces the specified constraint by the given one with the given constraint separator. The separator is added just before the added constraint, that is to say between the (index-1)-th constraint of the list and the added one (at the index position).- Parameters:
index
- Position of the constraint to replace.logicalSep
- The separator to insert just before the given constraint (if null, the previous separator is kept).constraint
- The replacer.- Returns:
- The replaced constraint.
- Throws:
NullPointerException
- If the given constraint is null.ArrayIndexOutOfBoundsException
- If the given index is incorrect (index < 0 || index >= size()).- See Also:
-
clear
public void clear()Description copied from class:ADQLList
Clears this clause.- Overrides:
clear
in classADQLList<ADQLConstraint>
-
remove
Description copied from class:ADQLList
Removes the specified ADQL item.- Overrides:
remove
in classADQLList<ADQLConstraint>
- Parameters:
index
- Index of the ADQL item to remove.- Returns:
- The removed ADQL item.
- Throws:
ArrayIndexOutOfBoundsException
- If the index is out of range (index < 0 || index > size()).
-
getCopy
Description copied from interface:ADQLObject
Gets a (deep) copy of this ADQL object.- Specified by:
getCopy
in interfaceADQLObject
- Overrides:
getCopy
in classClauseADQL<ADQLConstraint>
- Returns:
- The copy of this ADQL object.
- Throws:
Exception
- If there is any error during the copy.
-
getPossibleSeparators
- Overrides:
getPossibleSeparators
in classClauseADQL<ADQLConstraint>
- Returns:
- Possible separators.
- See Also:
-
getSeparator
Description copied from class:ClauseADQL
Returns always ",", except if the index is incorrect (index <= 0 or index >= size()).- Overrides:
getSeparator
in classClauseADQL<ADQLConstraint>
- Parameters:
index
- Index of the right list item.- Returns:
- The corresponding separator.
- Throws:
ArrayIndexOutOfBoundsException
- If the index is less or equal than 0, or is greater or equal thansize()
.- See Also:
-