[New] Implemented AnySelection
This commit is contained in:
parent
41f0e72cc5
commit
5e062f0630
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package li.strolch.model.query;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class AnySelection implements Selection {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(QueryVisitor visitor) {
|
||||||
|
visitor.visitAny();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasSelection() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,6 +34,24 @@ public class OrderQuery extends StrolchQuery<OrderQueryVisitor> {
|
||||||
super(navigation);
|
super(navigation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderQuery with(Selection selection) {
|
||||||
|
super.with(selection);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderQuery not(Selection selection) {
|
||||||
|
super.not(selection);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OrderQuery withAny() {
|
||||||
|
super.withAny();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public static OrderQuery query(Navigation navigation) {
|
public static OrderQuery query(Navigation navigation) {
|
||||||
return new OrderQuery(navigation);
|
return new OrderQuery(navigation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ package li.strolch.model.query;
|
||||||
*/
|
*/
|
||||||
public interface QueryVisitor {
|
public interface QueryVisitor {
|
||||||
|
|
||||||
|
public void visitAny();
|
||||||
|
|
||||||
public void visitAnd(AndSelection andSelection);
|
public void visitAnd(AndSelection andSelection);
|
||||||
|
|
||||||
public void visitOr(OrSelection orSelection);
|
public void visitOr(OrSelection orSelection);
|
||||||
|
|
|
@ -38,6 +38,24 @@ public class ResourceQuery extends StrolchQuery<ResourceQueryVisitor> {
|
||||||
super(navigation);
|
super(navigation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceQuery with(Selection selection) {
|
||||||
|
super.with(selection);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceQuery not(Selection selection) {
|
||||||
|
super.not(selection);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceQuery withAny() {
|
||||||
|
super.withAny();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public static ResourceQuery query(Navigation navigation) {
|
public static ResourceQuery query(Navigation navigation) {
|
||||||
return new ResourceQuery(navigation);
|
return new ResourceQuery(navigation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,37 +41,41 @@ public abstract class StrolchQuery<T extends QueryVisitor> {
|
||||||
return this.selection;
|
return this.selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void with(Selection selection) {
|
public StrolchQuery<T> with(Selection selection) {
|
||||||
DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections", //$NON-NLS-1$
|
assertNoSelectionYetSet();
|
||||||
this.selection);
|
|
||||||
this.selection = selection;
|
this.selection = selection;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void assertNoSelectionYetSet() {
|
||||||
* @deprecated use {@link #with(Selection)} instead
|
String msg = "A selection is already set! Use a cascaded boolean operators to perform multiple selections"; //$NON-NLS-1$
|
||||||
*/
|
DBC.PRE.assertNull(msg, this.selection);
|
||||||
@Deprecated
|
}
|
||||||
public void select(Selection selection) {
|
|
||||||
with(selection);
|
public StrolchQuery<T> withAny() {
|
||||||
|
assertNoSelectionYetSet();
|
||||||
|
this.selection = new AnySelection();
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AndSelection and() {
|
public AndSelection and() {
|
||||||
DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$
|
assertNoSelectionYetSet();
|
||||||
AndSelection and = new AndSelection();
|
AndSelection and = new AndSelection();
|
||||||
this.selection = and;
|
this.selection = and;
|
||||||
return and;
|
return and;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrSelection or() {
|
public OrSelection or() {
|
||||||
DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$
|
assertNoSelectionYetSet();
|
||||||
OrSelection or = new OrSelection();
|
OrSelection or = new OrSelection();
|
||||||
this.selection = or;
|
this.selection = or;
|
||||||
return or;
|
return or;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void not(Selection selection) {
|
public StrolchQuery<T> not(Selection selection) {
|
||||||
DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$
|
assertNoSelectionYetSet();
|
||||||
this.selection = new NotSelection(selection);
|
this.selection = new NotSelection(selection);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void accept(T visitor) {
|
public void accept(T visitor) {
|
||||||
|
|
Loading…
Reference in New Issue