From c21f96a5aee83eea9f3a89a76c306580bf689e31 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 4 Aug 2014 14:50:36 +0200 Subject: [PATCH] [New] added StrolchQuery.getSelection() and cleaned up some constants --- .../strolch/model/StrolchModelConstants.java | 23 +++++++++++ src/main/java/li/strolch/model/Tags.java | 1 - .../li/strolch/model/parameter/Parameter.java | 10 +++-- .../model/query/ParameterSelection.java | 3 +- .../li/strolch/model/query/StrolchQuery.java | 38 ++++++++++++------- 5 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 src/main/java/li/strolch/model/StrolchModelConstants.java diff --git a/src/main/java/li/strolch/model/StrolchModelConstants.java b/src/main/java/li/strolch/model/StrolchModelConstants.java new file mode 100644 index 000000000..ae993ddfb --- /dev/null +++ b/src/main/java/li/strolch/model/StrolchModelConstants.java @@ -0,0 +1,23 @@ +package li.strolch.model; + +import li.strolch.model.parameter.Parameter; + +public class StrolchModelConstants { + + /** + * The type to set on {@link StrolchRootElement StrolchRootElements} when defining a template for a type of element + */ + public static final String TEMPLATE = "Template"; //$NON-NLS-1$ + + /** + * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference + * to a {@link Resource} + */ + public static final String INTERPRETATION_RESOURCE_REF = "Resource-Ref"; //$NON-NLS-1$ + + /** + * This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference + * to an {@link Order} + */ + public static final String INTERPRETATION_ORDER_REF = "Order-Ref"; //$NON-NLS-1$ +} diff --git a/src/main/java/li/strolch/model/Tags.java b/src/main/java/li/strolch/model/Tags.java index 879b36a56..eb79a8fc2 100644 --- a/src/main/java/li/strolch/model/Tags.java +++ b/src/main/java/li/strolch/model/Tags.java @@ -40,5 +40,4 @@ public class Tags { public static final String INCLUDE_FILE = "IncludeFile"; public static final String FILE = "file"; - public static final String TEMPLATE = "Template"; } diff --git a/src/main/java/li/strolch/model/parameter/Parameter.java b/src/main/java/li/strolch/model/parameter/Parameter.java index 3eae2ef9f..00b55a53a 100644 --- a/src/main/java/li/strolch/model/parameter/Parameter.java +++ b/src/main/java/li/strolch/model/parameter/Parameter.java @@ -17,6 +17,7 @@ package li.strolch.model.parameter; import li.strolch.model.ParameterizedElement; import li.strolch.model.StrolchElement; +import li.strolch.model.StrolchModelConstants; import li.strolch.model.visitor.ParameterVisitor; /** @@ -104,6 +105,7 @@ public interface Parameter extends StrolchElement { * * @return */ + @Override public ParameterizedElement getParent(); /** @@ -116,8 +118,8 @@ public interface Parameter extends StrolchElement { * this {@link Parameter} means. Currently there are three definitions, but any String value can be used: *
    *
  • {@link Parameter#INTERPRETATION_NONE}
  • - *
  • {@link Parameter#INTERPRETATION_ORDER_REF}
  • - *
  • {@link Parameter#INTERPRETATION_RESOURCE_REF}
  • + *
  • {@link StrolchModelConstants#INTERPRETATION_ORDER_REF}
  • + *
  • {@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}
  • *
* * @return string value @@ -129,8 +131,8 @@ public interface Parameter extends StrolchElement { * {@link Parameter} means. Currently there are three definitions, but any String value can be used: *
    *
  • {@link Parameter#INTERPRETATION_NONE}
  • - *
  • {@link Parameter#INTERPRETATION_ORDER_REF}
  • - *
  • {@link Parameter#INTERPRETATION_RESOURCE_REF}
  • + *
  • {@link StrolchModelConstants#INTERPRETATION_ORDER_REF}
  • + *
  • {@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}
  • *
* * @param interpretation diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java index f326ee62a..9829d51b9 100644 --- a/src/main/java/li/strolch/model/query/ParameterSelection.java +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -57,6 +57,7 @@ public abstract class ParameterSelection implements Selection { accept((ParameterSelectionVisitor) visitor); } + @SuppressWarnings("nls") @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -243,7 +244,7 @@ public abstract class ParameterSelection implements Selection { public DateRangeParameterSelection(String bagKey, String paramKey, Date from, Date to) { super(bagKey, paramKey); - DBC.PRE.assertFalse("Either 'to' or 'from' must be set! Both can not be null!", from == null && to == null); + DBC.PRE.assertFalse("Either 'to' or 'from' must be set! Both can not be null!", from == null && to == null); //$NON-NLS-1$ this.from = from; this.to = to; } diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java index daba941ed..ec0977d38 100644 --- a/src/main/java/li/strolch/model/query/StrolchQuery.java +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -28,43 +28,55 @@ public abstract class StrolchQuery { public StrolchQuery(Navigation navigation) { this.navigation = navigation; } - + public boolean hasNavigation() { - return navigation != null; - } - - public boolean hasSelection() { - return selection != null && selection.hasSelection(); + return this.navigation != null; } - public void select(Selection selection) { - DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections", + public boolean hasSelection() { + return this.selection != null && this.selection.hasSelection(); + } + + public Selection getSelection() { + 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); this.selection = selection; } + /** + * @deprecated use {@link #with(Selection)} instead + */ + @Deprecated + public void select(Selection selection) { + with(selection); + } + public AndSelection and() { - DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); + DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$ 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); + DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$ 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); + DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$ this.selection = new NotSelection(selection); } public void accept(T visitor) { - DBC.PRE.assertNotNull("No navigation set!", this.navigation); - DBC.PRE.assertNotNull("No selection defined!", this.selection); + DBC.PRE.assertNotNull("No navigation set!", this.navigation); //$NON-NLS-1$ + DBC.PRE.assertNotNull("No selection defined!", this.selection); //$NON-NLS-1$ this.navigation.accept(visitor); this.selection.accept(visitor); }