[New] Added NotSelection and further builder methods to StrolchQuery
This commit is contained in:
parent
5915fe086d
commit
e023733cf0
|
@ -44,6 +44,7 @@ public class AndSelection extends BooleanSelection {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void accept(QueryVisitor visitor) {
|
public void accept(QueryVisitor visitor) {
|
||||||
visitor.visitAnd(this);
|
visitor.visitAnd(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ package li.strolch.model.query;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,19 +28,25 @@ public abstract class BooleanSelection implements Selection {
|
||||||
protected List<Selection> selections;
|
protected List<Selection> selections;
|
||||||
|
|
||||||
public BooleanSelection() {
|
public BooleanSelection() {
|
||||||
this.selections = new ArrayList<>();
|
this.selections = new ArrayList<>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BooleanSelection(List<Selection> selections) {
|
public BooleanSelection(List<Selection> selections) {
|
||||||
this.selections = selections;
|
this.selections = selections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BooleanSelection(Selection leftHandSide, Selection rightHandSide) {
|
||||||
|
this.selections = new ArrayList<>(2);
|
||||||
|
this.selections.add(leftHandSide);
|
||||||
|
this.selections.add(rightHandSide);
|
||||||
|
}
|
||||||
|
|
||||||
public BooleanSelection(Selection... selections) {
|
public BooleanSelection(Selection... selections) {
|
||||||
this.selections = Arrays.asList(selections);
|
this.selections = Arrays.asList(selections);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Selection> getSelections() {
|
public List<Selection> getSelections() {
|
||||||
return this.selections;
|
return Collections.unmodifiableList(this.selections);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BooleanSelection with(Selection selection) {
|
public BooleanSelection with(Selection selection) {
|
||||||
|
@ -47,5 +54,6 @@ public abstract class BooleanSelection implements Selection {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public abstract void accept(QueryVisitor visitor);
|
public abstract void accept(QueryVisitor visitor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,25 +15,57 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.query;
|
package li.strolch.model.query;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class IdSelection extends StrolchElementSelection {
|
public class IdSelection extends StrolchElementSelection {
|
||||||
|
|
||||||
private String id;
|
private List<String> ids;
|
||||||
|
|
||||||
|
public IdSelection() {
|
||||||
|
this.ids = new ArrayList<>(1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
public IdSelection(String id) {
|
public IdSelection(String id) {
|
||||||
this.id = id;
|
this.ids = new ArrayList<>(1);
|
||||||
|
this.ids.add(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the id
|
* @param ids
|
||||||
*/
|
*/
|
||||||
public String getId() {
|
public IdSelection(String... ids) {
|
||||||
return this.id;
|
this.ids = Arrays.asList(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
public IdSelection(List<String> ids) {
|
||||||
|
this.ids = ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the ids
|
||||||
|
*/
|
||||||
|
public List<String> getIds() {
|
||||||
|
return this.ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public IdSelection with(String id) {
|
||||||
|
this.ids.add(id);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* 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 NotSelection extends BooleanSelection {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param selection
|
||||||
|
*/
|
||||||
|
public NotSelection(Selection selection) {
|
||||||
|
super(selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws UnsupportedOperationException
|
||||||
|
* because a {@link NotSelection} can only work on a single {@link Selection}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public NotSelection with(Selection selection) {
|
||||||
|
throw new UnsupportedOperationException("NotSelection can only have a single selection"); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
public Selection getSelection() {
|
||||||
|
return this.selections.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(QueryVisitor visitor) {
|
||||||
|
visitor.visitNot(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,4 +23,6 @@ public interface QueryVisitor {
|
||||||
public void visitAnd(AndSelection andSelection);
|
public void visitAnd(AndSelection andSelection);
|
||||||
|
|
||||||
public void visitOr(OrSelection orSelection);
|
public void visitOr(OrSelection orSelection);
|
||||||
|
|
||||||
|
public void visitNot(NotSelection notSelection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,29 @@ public abstract class StrolchQuery<T extends QueryVisitor> {
|
||||||
this.selections.add(selection);
|
this.selections.add(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StrolchQuery<T> select(Selection selection) {
|
||||||
|
this.selections.add(selection);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrolchQuery<T> and(Selection... selections) {
|
||||||
|
AndSelection and = new AndSelection(selections);
|
||||||
|
this.selections.add(and);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrolchQuery<T> or(Selection... selections) {
|
||||||
|
OrSelection or = new OrSelection(selections);
|
||||||
|
this.selections.add(or);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrolchQuery<T> not(Selection selection) {
|
||||||
|
NotSelection not = new NotSelection(selection);
|
||||||
|
this.selections.add(not);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void accept(T visitor) {
|
public void accept(T visitor) {
|
||||||
this.navigation.accept(visitor);
|
this.navigation.accept(visitor);
|
||||||
for (Selection selection : this.selections) {
|
for (Selection selection : this.selections) {
|
||||||
|
|
Loading…
Reference in New Issue