[New] Implemented AnySelection

This commit is contained in:
Robert von Burg 2014-08-07 01:00:25 +02:00
parent 41f0e72cc5
commit 5e062f0630
5 changed files with 87 additions and 13 deletions

View File

@ -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;
}
}

View File

@ -34,6 +34,24 @@ public class OrderQuery extends StrolchQuery<OrderQueryVisitor> {
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) {
return new OrderQuery(navigation);
}

View File

@ -20,6 +20,8 @@ package li.strolch.model.query;
*/
public interface QueryVisitor {
public void visitAny();
public void visitAnd(AndSelection andSelection);
public void visitOr(OrSelection orSelection);

View File

@ -38,6 +38,24 @@ public class ResourceQuery extends StrolchQuery<ResourceQueryVisitor> {
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) {
return new ResourceQuery(navigation);
}

View File

@ -41,37 +41,41 @@ public abstract class StrolchQuery<T extends QueryVisitor> {
return this.selection;
}
public void with(Selection selection) {
DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections", //$NON-NLS-1$
this.selection);
public StrolchQuery<T> with(Selection selection) {
assertNoSelectionYetSet();
this.selection = selection;
return this;
}
/**
* @deprecated use {@link #with(Selection)} instead
*/
@Deprecated
public void select(Selection selection) {
with(selection);
private void assertNoSelectionYetSet() {
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);
}
public StrolchQuery<T> withAny() {
assertNoSelectionYetSet();
this.selection = new AnySelection();
return this;
}
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();
this.selection = and;
return and;
}
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();
this.selection = or;
return or;
}
public void not(Selection selection) {
DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$
public StrolchQuery<T> not(Selection selection) {
assertNoSelectionYetSet();
this.selection = new NotSelection(selection);
return this;
}
public void accept(T visitor) {