diff --git a/src/main/java/li/strolch/model/query/AndSelection.java b/src/main/java/li/strolch/model/query/AndSelection.java index b0f643169..8f0c70bb6 100644 --- a/src/main/java/li/strolch/model/query/AndSelection.java +++ b/src/main/java/li/strolch/model/query/AndSelection.java @@ -20,15 +20,30 @@ import java.util.List; /** * @author Robert von Burg */ -public class AndSelection extends BooleanSelection { +public class AndSelection extends BooleanSelection { + + public AndSelection() { + super(); + } + + @SafeVarargs + public AndSelection(Selection... selections) { + super(selections); + } /** * @param selections */ - public AndSelection(List selections) { + public AndSelection(List selections) { super(selections); } + @Override + public AndSelection with(Selection selection) { + super.with(selection); + return this; + } + public void accept(QueryVisitor visitor) { visitor.visitAnd(this); } diff --git a/src/main/java/li/strolch/model/query/BooleanSelection.java b/src/main/java/li/strolch/model/query/BooleanSelection.java index 54881e8f9..bfd9318bc 100644 --- a/src/main/java/li/strolch/model/query/BooleanSelection.java +++ b/src/main/java/li/strolch/model/query/BooleanSelection.java @@ -15,23 +15,37 @@ */ package li.strolch.model.query; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** * @author Robert von Burg - * */ -public abstract class BooleanSelection implements Selection { +public abstract class BooleanSelection implements Selection { - protected List selections; + protected List selections; - public BooleanSelection(List selections) { + public BooleanSelection() { + this.selections = new ArrayList<>(); + } + + public BooleanSelection(List selections) { this.selections = selections; } - public List getSelections() { + public BooleanSelection(Selection... selections) { + this.selections = Arrays.asList(selections); + } + + public List getSelections() { return this.selections; } + public BooleanSelection with(Selection selection) { + this.selections.add(selection); + return this; + } + public abstract void accept(QueryVisitor visitor); } diff --git a/src/main/java/li/strolch/model/query/OrSelection.java b/src/main/java/li/strolch/model/query/OrSelection.java index 7a01dd725..697a25182 100644 --- a/src/main/java/li/strolch/model/query/OrSelection.java +++ b/src/main/java/li/strolch/model/query/OrSelection.java @@ -19,14 +19,28 @@ import java.util.List; /** * @author Robert von Burg - * */ -public class OrSelection extends BooleanSelection { +public class OrSelection extends BooleanSelection { - public OrSelection(List selections) { + public OrSelection() { + super(); + } + + public OrSelection(List selections) { super(selections); } + @SafeVarargs + public OrSelection(Selection... selections) { + super(selections); + } + + @Override + public OrSelection with(Selection selection) { + super.with(selection); + return this; + } + @Override public void accept(QueryVisitor visitor) { visitor.visitOr(this); diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java index 5f1b53321..b57df7137 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -52,37 +52,39 @@ public abstract class ParameterSelection implements Selection { public abstract void accept(ParameterSelectionVisitor visitor); - public static ParameterSelection stringSelection(String bagKey, String paramKey, String value) { + public static StringParameterSelection stringSelection(String bagKey, String paramKey, String value) { return new StringParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection integerSelection(String bagKey, String paramKey, int value) { + public static IntegerParameterSelection integerSelection(String bagKey, String paramKey, int value) { return new IntegerParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection booleanSelection(String bagKey, String paramKey, boolean value) { + public static BooleanParameterSelection booleanSelection(String bagKey, String paramKey, boolean value) { return new BooleanParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection floatSelection(String bagKey, String paramKey, double value) { + public static FloatParameterSelection floatSelection(String bagKey, String paramKey, double value) { return new FloatParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection longSelection(String bagKey, String paramKey, long value) { + public static LongParameterSelection longSelection(String bagKey, String paramKey, long value) { return new LongParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection dateSelection(String bagKey, String paramKey, Date value) { + public static DateParameterSelection dateSelection(String bagKey, String paramKey, Date value) { return new DateParameterSelection(bagKey, paramKey, value); } - public static ParameterSelection stringListSelection(String bagKey, String paramKey, List value) { + public static StringListParameterSelection stringListSelection(String bagKey, String paramKey, List value) { return new StringListParameterSelection(bagKey, paramKey, value); } public static class StringParameterSelection extends ParameterSelection { private String value; + private boolean contains; + private boolean caseInsensitive; public StringParameterSelection(String bagKey, String paramKey, String value) { super(bagKey, paramKey); @@ -93,6 +95,24 @@ public abstract class ParameterSelection implements Selection { return this.value; } + public boolean isContains() { + return this.contains; + } + + public boolean isCaseInsensitive() { + return this.caseInsensitive; + } + + public StringParameterSelection contains(boolean contains) { + this.contains = contains; + return this; + } + + public StringParameterSelection caseInsensitive(boolean caseInsensitive) { + this.caseInsensitive = true; + return this; + } + @Override public void accept(ParameterSelectionVisitor visitor) { visitor.visit(this); diff --git a/src/main/java/li/strolch/model/query/QueryVisitor.java b/src/main/java/li/strolch/model/query/QueryVisitor.java index d6efcec67..c5e9b128a 100644 --- a/src/main/java/li/strolch/model/query/QueryVisitor.java +++ b/src/main/java/li/strolch/model/query/QueryVisitor.java @@ -17,11 +17,10 @@ package li.strolch.model.query; /** * @author Robert von Burg - * */ public interface QueryVisitor { - public void visitAnd(AndSelection andSelection); + public void visitAnd(AndSelection andSelection); - public void visitOr(OrSelection orSelection); + public void visitOr(OrSelection orSelection); } diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java b/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java index 4756beb3e..b7bf67fdb 100644 --- a/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java +++ b/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java @@ -18,7 +18,7 @@ package li.strolch.model.query; /** * @author Robert von Burg */ -public interface StrolchElementSelectionVisitor extends QueryVisitor{ +public interface StrolchElementSelectionVisitor extends QueryVisitor { public void visit(StrolchTypeNavigation navigation); diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index dff521c08..01e377347 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -31,7 +31,7 @@ public abstract class StrolchQuery { this.selections = new ArrayList<>(); } - public void addSelection(BooleanSelection selection) { + public void addSelection(BooleanSelection selection) { this.selections.add(selection); } diff --git a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java index 4ac7c3cc5..a9bd73f74 100644 --- a/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/AbstractToSaxWriterVisitor.java @@ -44,21 +44,21 @@ public abstract class AbstractToSaxWriterVisitor { writeStartStrolchElement(tag, isEmpty, element); if (!isEmpty) { writeParameterBags(element); - writer.writeEndElement(); + this.writer.writeEndElement(); } } protected void writeStartStrolchElement(String tag, boolean empty, StrolchElement element) throws XMLStreamException { if (empty) - writer.writeEmptyElement(tag); + this.writer.writeEmptyElement(tag); else - writer.writeStartElement(tag); + this.writer.writeStartElement(tag); - writer.writeAttribute(Tags.ID, element.getId()); + this.writer.writeAttribute(Tags.ID, element.getId()); if (!StringHelper.isEmpty(element.getName())) - writer.writeAttribute(Tags.NAME, element.getName()); - writer.writeAttribute(Tags.TYPE, element.getType()); + this.writer.writeAttribute(Tags.NAME, element.getName()); + this.writer.writeAttribute(Tags.TYPE, element.getType()); } protected void writeParameters(ParameterizedElement element) throws XMLStreamException { @@ -70,13 +70,13 @@ public abstract class AbstractToSaxWriterVisitor { writeStartStrolchElement(Tags.PARAMETER, true, parameter); if (!Parameter.INTERPRETATION_NONE.equals(parameter.getInterpretation())) - writer.writeAttribute(Tags.INTERPRETATION, parameter.getInterpretation()); + this.writer.writeAttribute(Tags.INTERPRETATION, parameter.getInterpretation()); if (!Parameter.UOM_NONE.equals(parameter.getUom())) - writer.writeAttribute(Tags.UOM, parameter.getUom()); + this.writer.writeAttribute(Tags.UOM, parameter.getUom()); if (parameter.isHidden()) - writer.writeAttribute(Tags.HIDDEN, Boolean.toString(parameter.isHidden())); + this.writer.writeAttribute(Tags.HIDDEN, Boolean.toString(parameter.isHidden())); - writer.writeAttribute(Tags.VALUE, parameter.getValueAsString()); + this.writer.writeAttribute(Tags.VALUE, parameter.getValueAsString()); } } @@ -89,7 +89,7 @@ public abstract class AbstractToSaxWriterVisitor { writeStartStrolchElement(Tags.PARAMETER_BAG, isEmpty, parameterBag); if (!isEmpty) { writeParameters(parameterBag); - writer.writeEndElement(); + this.writer.writeEndElement(); } } } diff --git a/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java index 8ac0200a0..cf4f089d4 100644 --- a/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/OrderToSaxWriterVisitor.java @@ -39,7 +39,7 @@ public class OrderToSaxWriterVisitor extends AbstractToSaxWriterVisitor implemen try { writeElement(Tags.ORDER, order); } catch (XMLStreamException e) { - String msg = "Failed to write Order {0} due to {1}"; + String msg = "Failed to write Order {0} due to {1}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, order.getLocator(), e.getMessage()); throw new StrolchException(msg, e); } diff --git a/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java b/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java index f98098f29..8f6783802 100644 --- a/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java +++ b/src/main/java/li/strolch/model/xml/ResourceToSaxWriterVisitor.java @@ -39,7 +39,7 @@ public class ResourceToSaxWriterVisitor extends AbstractToSaxWriterVisitor imple try { writeElement(Tags.RESOURCE, resource); } catch (XMLStreamException e) { - String msg = "Failed to write Resource {0} due to {1}"; + String msg = "Failed to write Resource {0} due to {1}"; //$NON-NLS-1$ msg = MessageFormat.format(msg, resource.getLocator(), e.getMessage()); throw new StrolchException(msg, e); }