[New] Added a StrolchQuery.hasSelection() and Selection.hasSelection()
This allows for checking if a query really has a selection.
This commit is contained in:
parent
c8cedae647
commit
c246c76236
|
@ -45,6 +45,20 @@ public abstract class BooleanSelection implements Selection {
|
|||
this.selections = Arrays.asList(selections);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSelection() {
|
||||
if (this.selections == null || this.selections.isEmpty())
|
||||
return false;
|
||||
|
||||
for (Selection selection : this.selections) {
|
||||
if (selection.hasSelection()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Selection> getSelections() {
|
||||
return Collections.unmodifiableList(this.selections);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ package li.strolch.model.query;
|
|||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class OrderSelection implements Selection {
|
||||
|
||||
|
@ -26,5 +26,10 @@ public abstract class OrderSelection implements Selection {
|
|||
accept((OrderSelectionVisitor) visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSelection() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void accept(OrderSelectionVisitor visitor);
|
||||
}
|
||||
|
|
|
@ -45,11 +45,27 @@ public abstract class ParameterSelection implements Selection {
|
|||
return this.paramKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSelection() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(QueryVisitor visitor) {
|
||||
accept((ParameterSelectionVisitor) visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(getClass().getSimpleName() + " [bagKey=");
|
||||
builder.append(this.bagKey);
|
||||
builder.append(", paramKey=");
|
||||
builder.append(this.paramKey);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public abstract void accept(ParameterSelectionVisitor visitor);
|
||||
|
||||
public static StringParameterSelection stringSelection(String bagKey, String paramKey, String value) {
|
||||
|
|
|
@ -20,6 +20,7 @@ package li.strolch.model.query;
|
|||
*/
|
||||
public interface Selection {
|
||||
|
||||
// marker interface
|
||||
public void accept(QueryVisitor visitor);
|
||||
|
||||
public boolean hasSelection();
|
||||
}
|
||||
|
|
|
@ -25,5 +25,10 @@ public abstract class StrolchElementSelection implements Selection {
|
|||
accept((StrolchElementSelectionVisitor) visitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSelection() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void accept(StrolchElementSelectionVisitor visitor);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,14 @@ public abstract class StrolchQuery<T extends QueryVisitor> {
|
|||
public StrolchQuery(Navigation navigation) {
|
||||
this.navigation = navigation;
|
||||
}
|
||||
|
||||
public boolean hasNavigation() {
|
||||
return navigation != null;
|
||||
}
|
||||
|
||||
public boolean hasSelection() {
|
||||
return selection != null && selection.hasSelection();
|
||||
}
|
||||
|
||||
public void select(Selection selection) {
|
||||
DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections",
|
||||
|
|
Loading…
Reference in New Issue