diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/UniqueIdGenerator.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/UniqueIdGenerator.java index 2a1291c0cad41261a504ab6c7f065a4be774699d..ae83ef609ffc140f3619e0884efc91841c78c853 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/UniqueIdGenerator.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/UniqueIdGenerator.java @@ -11,7 +11,9 @@ public class UniqueIdGenerator { private UniqueIdGenerator() {} /** - * Return the next id. This method is synchronized. + * Get the next id. This method is synchronized. + * + * @return the next unique id */ public static synchronized long getNextId() { return id++; diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/AbstractBoundary.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/AbstractBoundary.java index 7e95f7012406985fec9e440fd78420e1aef6709b..8b30da4ba1db3c3b35314d417e388b93e64f3c29 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/AbstractBoundary.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/AbstractBoundary.java @@ -13,6 +13,11 @@ import java.util.Map; import java.util.Optional; import org.apache.commons.lang3.Validate; +/** + * The abstract class for a boundary object, which implements the {@link Boundary} interface. + * + * @param <T> the comparable value type + */ public abstract class AbstractBoundary<T extends Comparable<? super T>> implements Boundary { private HashMap<BoundaryCheckType, BoundaryCheck> checkFunctions; @@ -21,6 +26,12 @@ public abstract class AbstractBoundary<T extends Comparable<? super T>> implemen private Class<T> type; protected String text; + /** + * Create a new boundary with the given type and the given text. This constructor parse the text. + * + * @param text the text as string, which will be parsed to the new boundary + * @param type the type of the boundary + */ protected AbstractBoundary(String text, Class<T> type) { this.text = text; this.type = type; @@ -31,20 +42,30 @@ public abstract class AbstractBoundary<T extends Comparable<? super T>> implemen createrFunctions = new HashMap<>(getCreater()); } + /** + * Create a new boundary with the given type. This constructor parse the empty text value. + * + * @param type the type of the boundary + */ protected AbstractBoundary(Class<T> type) { this("", type); } + /** + * {@inheritDoc} + */ @Override public String getText() { return text; } + /** {@inheritDoc} */ @Override public VTypeRef getTypeRef() { return VTypeRef.getTypeRefFromJavaClass(type); } + /** {@inheritDoc} */ @Override public boolean checkWith(BoundaryCheckType checkType, Boundary other) { if (other instanceof InvalidBoundary) { @@ -57,6 +78,7 @@ public abstract class AbstractBoundary<T extends Comparable<? super T>> implemen return checkFunction.check(this, other); // TODO, remove RAW type } + /** {@inheritDoc} */ @Override public Optional<Boundary> create(BoundaryCreaterType createrType) { BoundaryCreater creater = getCreaterFunction(createrType); @@ -66,6 +88,7 @@ public abstract class AbstractBoundary<T extends Comparable<? super T>> implemen return creater.create(this); } + /** {@inheritDoc} */ @Override public Optional<Boundary> createBi(BoundaryBiCreaterType biCreaterType, Boundary other) { if (other instanceof InvalidBoundary) { @@ -78,22 +101,54 @@ public abstract class AbstractBoundary<T extends Comparable<? super T>> implemen return biCreater.create(this, other); // TODO, remove RAW type } + /** + * Check, if the {@link BoundaryCheckType} is a valid operation for this boundary. + * + * @param checkType the {@link BoundaryCheckType} + * @param other the other bounday + * @return true, if the operation is valid. + */ public boolean isValidOperation(BoundaryCheckType checkType, Boundary other) { return this.getTypeRef() == other.getTypeRef() && isValidOperation(checkType); } + /** + * Check, if the {@link BoundaryCheckType} is a valid operation for this boundary. + * + * @param checkType the {@link BoundaryCheckType} + * @return true, if the operation is valid. + */ public boolean isValidOperation(BoundaryCheckType checkType) { return checkFunctions.containsKey(Validate.notNull(checkType)); } + /** + * Check, if the {@link BoundaryBiCreaterType} is a valid operation for this boundary. + * + * @param combineType the {@link BoundaryBiCreaterType} + * @param other the other bounday + * @return true, if the operation is valid. + */ public boolean isValidOperation(BoundaryBiCreaterType combineType, Boundary other) { return this.getTypeRef() == other.getTypeRef() && isValidOperation(combineType); } - public boolean isValidOperation(BoundaryBiCreaterType combineTyp) { - return biCreaterFunctions.containsKey(Validate.notNull(combineTyp)); + /** + * Check, if the {@link BoundaryBiCreaterType} is a valid operation for this boundary. + * + * @param combineType the {@link BoundaryBiCreaterType} + * @return true, if the operation is valid. + */ + public boolean isValidOperation(BoundaryBiCreaterType combineType) { + return biCreaterFunctions.containsKey(Validate.notNull(combineType)); } + /** + * Check, if the {@link BoundaryCreaterType} is a valid operation for this boundary. + * + * @param createrType the {@link BoundaryCreaterType} + * @return true, if the operation is valid. + */ public boolean isValidOperation(BoundaryCreaterType createrType) { return createrFunctions.containsKey(Validate.notNull(createrType)); } @@ -110,14 +165,39 @@ public abstract class AbstractBoundary<T extends Comparable<? super T>> implemen return biCreaterFunctions.get(biCreaterTypeType); } + /** + * Parse the boundary object from the given text. + * + * @param text the text as string + */ protected abstract void parse(String text); - protected abstract void validate(); - + /** + * Check, if the boundary is a valid boundary. + * + * @throws {@link BoundaryParseException} + */ + protected abstract void validate() throws BoundaryParseException; + + /** + * Get the map of Checker. + * + * @return the map of {@link BoundaryCheckType}: {@link BoundaryCheck} + */ protected abstract Map<BoundaryCheckType, BoundaryCheck> getChecker(); + /** + * Get the map of biCreater. + * + * @return the map of {@link BoundaryBiCreaterType}: {@link BoundaryBiCreater} + */ protected abstract Map<BoundaryBiCreaterType, BoundaryBiCreater> getBiCreater(); + /** + * Get the map of creater. + * + * @return the map of {@link BoundaryCreaterType}: {@link BoundaryCreater} + */ protected abstract Map<BoundaryCreaterType, BoundaryCreater> getCreater(); @Override diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/AbstractGrowingBoundary.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/AbstractGrowingBoundary.java index 1672df6b515e3a1ae3ec9d7f4c1d1520699ad4d4..a2b70f2ba5cbe56d42b584b61ee9e3a3204aa8ff 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/AbstractGrowingBoundary.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/AbstractGrowingBoundary.java @@ -42,6 +42,11 @@ import java.util.Map; import java.util.Objects; import org.apache.commons.lang3.Validate; +/** + * This abstract boundary is for growing boundaries, like numbers or dates. + * + * @param <T> the type of the boundary + */ public abstract class AbstractGrowingBoundary<T extends Comparable<? super T>> extends AbstractBoundary<T> { @@ -71,18 +76,38 @@ public abstract class AbstractGrowingBoundary<T extends Comparable<? super T>> protected T upperBound; protected BoundType upperBoundType; + /** + * Get the current lower bound of the boundary. + * + * @return the lower bound + */ public T getLowerBound() { return lowerBound; } + /** + * Get the current upper bound of the boundary. + * + * @return the lower bound + */ public T getUpperBound() { return upperBound; } + /** + * Get the {@link BoundType} of the lower bound. + * + * @return the lower {@link BoundType} + */ public BoundType getLowerBoundType() { return lowerBoundType; } + /** + * Get the {@link BoundType} of the upper bound. + * + * @return the upper {@link BoundType} + */ public BoundType getUpperBoundType() { return upperBoundType; } @@ -95,8 +120,11 @@ public abstract class AbstractGrowingBoundary<T extends Comparable<? super T>> super(type); } + /** + * {@inheritDoc} + */ @Override - protected void validate() { + protected void validate() throws BoundaryParseException { Validate.notNull(lowerBound); Validate.notNull(upperBound); if (lowerBound.equals(getMinValue())) { @@ -108,13 +136,13 @@ public abstract class AbstractGrowingBoundary<T extends Comparable<? super T>> Validate.notNull(lowerBoundType); Validate.notNull(upperBoundType); if (lowerBound.compareTo(upperBound) > 0) { - throw new IllegalArgumentException( + throw new BoundaryParseException( String.format("Lower bound %s is greater than upper bound %s.", lowerBound, upperBound)); } // if equal -> both must be INCLUSIVE! if (upperBound.equals(lowerBound) && (lowerBoundType != INCLUSIVE || upperBoundType != INCLUSIVE)) { - throw new IllegalArgumentException("If bounds are equal -> both bounds must be INCLUSIVE!"); + throw new BoundaryParseException("If bounds are equal -> both bounds must be INCLUSIVE!"); } } @@ -187,20 +215,88 @@ public abstract class AbstractGrowingBoundary<T extends Comparable<? super T>> return upperBound.compareTo((T) o.upperBound); } + /** + * Get the minimum possible value of the boundary (-INFINITY). + * + * @return the minimum value + */ public abstract T getMinValue(); + /** + * Get the maximum possible value of the boundary (INFINITY). + * + * @return the maximum value + */ public abstract T getMaxValue(); - public abstract AbstractGrowingBoundary getCopy( + /** + * Get a copy of the boundary. + * + * @param boundary the original boundary + * @return a copy of the given boundary + */ + public AbstractGrowingBoundary<T> getCopy(AbstractGrowingBoundary<T> boundary) { + return getCopy( + boundary.lowerBound, boundary.upperBound, boundary.lowerBoundType, boundary.upperBoundType); + } + + /** + * Get a copy of the boundary. + * + * @param lowerBound the lower bound + * @param upperBound the upper bound + * @param lowerBoundType the lower {@link BoundType} + * @param upperBoundType the upper {@link BoundType} + * @return a copy of the given boundary + */ + public abstract AbstractGrowingBoundary<T> getCopy( T lowerBound, T upperBound, BoundType lowerBoundType, BoundType upperBoundType); + /** + * The structure of the parsed text of the boundary looks like <br> + * + * <ul> + * <li>"= 10"<br> + * {lowerBound=10; upperBound=10; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"<= 10"<br> + * {lowerBound=-INFINITY; upperBound=10; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"< 10"<br> + * {lowerBound=-INFINITY; upperBound=10; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"> 10"<br> + * {lowerBound=10; upperBound=INFINITY; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>">= 10"<br> + * {lowerBound=10; upperBound=INFINITY; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"[10..20]" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"]10..20]" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"]10..20[" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"[10..20[" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"" (empty String) <br> + * {lowerBound=-INFINITY; upperBound=INFINITY; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * </ul> + * + * @return the parsed text as string + */ @Override public String getParsedText() { if (lowerBound.equals(getMinValue()) && upperBound.equals(getMaxValue())) { return ""; } if (lowerBound.equals(upperBound)) { - return "=" + lowerBound; + return "= " + lowerBound; } StringBuilder sb = new StringBuilder(); if (lowerBound.equals(getMinValue())) { diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundType.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundType.java index 7f55b425770291aa3c885e78eed6d3197dda7e7f..4240bdb056ed3267cde1ae69e852ef688136e249 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundType.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundType.java @@ -1,14 +1,42 @@ package de.unikoblenz.fgbks.base.utils.boundary; +/** + * The BoundType determines, if the border of a boundary is {@link BoundType#INCLUSIVE} or {@link + * BoundType#EXCLUSIVE}. + */ public enum BoundType { + /** + * The bound of the boundary is inclusive, means, that a value, which is exact at the bound, the + * value is inside the boundary. <br> Example: <br> value = 10; boundary = <=10 -> {@link + * BoundType} is INCLUSIVE. So the value is inside the boundary. + */ INCLUSIVE, + /** + * The bound of the boundary is exclusive, means, that a value, which is exact at the bound, the + * value is outside the boundary. <br> + * Example: <br> + * value = 10; boundary = <10 -> {@link BoundType} is EXCLUSIVE. So the value is outside the + * boundary. + */ EXCLUSIVE; - public BoundType getOp() { - return this == INCLUSIVE ? EXCLUSIVE : INCLUSIVE; + /** + * Get the opposite of the {@link BoundType}. + * + * @return {@link BoundType#INCLUSIVE}, if {@code other} is {@link BoundType#EXCLUSIVE}, else + * {@link BoundType#EXCLUSIVE} + */ + public static BoundType getOp(BoundType other) { + return other.getOp(); } - public static BoundType getOp(BoundType boundType) { - return boundType.getOp(); + /** + * Get the opposite of the {@link BoundType}. + * + * @return {@link BoundType#INCLUSIVE}, if current is {@link BoundType#EXCLUSIVE}, else {@link + * BoundType#EXCLUSIVE} + */ + public BoundType getOp() { + return this == INCLUSIVE ? EXCLUSIVE : INCLUSIVE; } } diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/Boundary.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/Boundary.java index 29f997b69ee74d8a8cd531fbb194468be99f56be..4ae022a3368a74daf44aa2d499da2e70991a04e5 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/Boundary.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/Boundary.java @@ -1,22 +1,69 @@ package de.unikoblenz.fgbks.base.utils.boundary; +import de.unikoblenz.fgbks.base.utils.boundary.bicreater.BoundaryBiCreater; import de.unikoblenz.fgbks.base.utils.boundary.bicreater.BoundaryBiCreaterType; +import de.unikoblenz.fgbks.base.utils.boundary.checker.BoundaryCheck; import de.unikoblenz.fgbks.base.utils.boundary.checker.BoundaryCheckType; +import de.unikoblenz.fgbks.base.utils.boundary.creater.BoundaryCreater; import de.unikoblenz.fgbks.base.utils.boundary.creater.BoundaryCreaterType; import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VTypeRef; import java.util.Optional; +/** + * A boundary express a set of values, which are in a given range or between given bounds. + */ public interface Boundary extends Comparable<Boundary> { + /** + * Get the {@link VTypeRef} of the current boundary. + * + * @return the typeRef + */ VTypeRef getTypeRef(); + /** + * Get the original text as string the boundary was parsed from. + * + * @return the original text as string + */ String getText(); + /** + * Get the text as string, representing the boundary. + * + * @return the boundary as text representation + */ String getParsedText(); + /** + * Perform a {@link BoundaryCheck} operation with an other boundary. The boundaries should be from + * the same type. All possible checks are listed in {@link BoundaryCheckType}. + * + * @param checkType a {@link BoundaryCheckType} + * @param other the other Boundary + * @return true, if the check returns true + */ boolean checkWith(BoundaryCheckType checkType, Boundary other); + /** + * Perform a {@link BoundaryCreater} operation, which creates a new boundary from the given one. + * All possible checks are listed in {@link BoundaryCreaterType}. + * + * @param createType a {@link BoundaryCreaterType} + * @return a optional with a new boundary with new bounds created by the {@link BoundaryCreater}. + * The optional is empty, if no new boundary could be created. + */ Optional<Boundary> create(BoundaryCreaterType createType); - Optional<Boundary> createBi(BoundaryBiCreaterType combineType, Boundary other); + /** + * Perform a {@link BoundaryBiCreater} operation, which creates a new boundary from the given one + * and an {@code other} boundary. Both boundary should be from the same boundary type. All + * possible checks are listed in {@link BoundaryBiCreaterType}. + * + * @param biCreaterType a {@link BoundaryCreaterType} + * @param other the other boundary + * @return a optional with a new boundary with new bounds created by the {@link + * BoundaryBiCreater}. The optional is empty, if no new boundary could be created. + */ + Optional<Boundary> createBi(BoundaryBiCreaterType biCreaterType, Boundary other); } diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundaryOperationNotSupportedException.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundaryOperationNotSupportedException.java index 11eb6fa9ad307d3635e044344bfd7b39768aeeb4..65db45926ee6ef8cbdaa145042e202a8dab71ea7 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundaryOperationNotSupportedException.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundaryOperationNotSupportedException.java @@ -1,5 +1,9 @@ package de.unikoblenz.fgbks.base.utils.boundary; +/** + * This exception is thrown, if the {@link Boundary#checkWith}, {@link Boundary#create} or {@link + * Boundary#createBi} operation can not be executed. + */ public class BoundaryOperationNotSupportedException extends UnsupportedOperationException { public BoundaryOperationNotSupportedException() { diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundaryParseException.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundaryParseException.java index 911d3f6541a5ea8e7d885db0b4d63b86df06ee0e..bd127d9ab854557f9faaa519b3d32831dcf28b76 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundaryParseException.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/BoundaryParseException.java @@ -1,5 +1,8 @@ package de.unikoblenz.fgbks.base.utils.boundary; +/** + * This exception is thrown, if the {@link Boundary} can not be parsed. + */ public class BoundaryParseException extends RuntimeException { public BoundaryParseException() {} diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/BooleanBoundary.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/BooleanBoundary.java index 8a8c2cfb07906e60ed90c4778595e9f635ba027c..cf9f8a3b26da1cb60576a8eba5e995a1bd230894 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/BooleanBoundary.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/BooleanBoundary.java @@ -6,8 +6,17 @@ import de.unikoblenz.fgbks.base.utils.boundary.AbstractGrowingBoundary; import de.unikoblenz.fgbks.base.utils.boundary.BoundType; import de.unikoblenz.fgbks.base.utils.boundary.BoundaryParseException; +/** + * A Boolean boundary can be only true, false or both (true and false = empty String). + */ public class BooleanBoundary extends AbstractGrowingBoundary<Boolean> { + /** + * Parse the input text to a new Boolean boundary. See {@link BooleanBoundary} for the required + * structure. + * + * @param text the text, which will be parsed to the new BooleanBoundary object + */ public BooleanBoundary(String text) { super(text, Boolean.TYPE); } @@ -27,7 +36,7 @@ public class BooleanBoundary extends AbstractGrowingBoundary<Boolean> { } @Override - public AbstractGrowingBoundary getCopy( + public AbstractGrowingBoundary<Boolean> getCopy( Boolean lowerBound, Boolean upperBound, BoundType lowerBoundType, BoundType upperBoundType) { BooleanBoundary v = new BooleanBoundary(); v.lowerBound = lowerBound; @@ -54,6 +63,11 @@ public class BooleanBoundary extends AbstractGrowingBoundary<Boolean> { } } + /** + * Get the boolean boundary: "true", "false" or "". + * + * @return the string representation of the boolean Boundary + */ @Override public String getParsedText() { return lowerBound != upperBound ? "" : lowerBound.toString(); diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/DateBoundary.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/DateBoundary.java index 16bfd8d81c309c900edf2198b2b7ab95dad1aab6..e04296bf18860d65525ba24522db65ec63fdb85c 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/DateBoundary.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/DateBoundary.java @@ -17,10 +17,28 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang3.Validate; +/** + * The date boundary is ether a single date or a INCLUSIVE range between to dates (or between + * -INFINITY and +INFINITY). The date boundary is represented as {@link LocalDateTime}. The text + * representation matches the pattern {@link DateBoundary#datePatternString} and looks like: <br> + * + * <ul> + * <li>{@code "date and time("yyyy-MM-ddThh:mm:ss")"} <br> + * exact date + * <li>{@code "< date and time("yyyy-MM-ddThh:mm:ss")"} <br> + * lower than the given date + * <li>{@code "> date and time("yyyy-MM-ddThh:mm:ss")"} <br> + * higher than the given date + * <li>{@code "[date and time("yyyy-MM-ddThh:mm:ss")..date and time("yyyy-MM-ddThh:mm:ss")]"} <br> + * between the two given dates {@link BoundType#INCLUSIVE} + * <li>{@code "" (Empty string)}<br> + * All dates. + * </ul> + */ public class DateBoundary extends AbstractGrowingBoundary<LocalDateTime> { public static final String dateGroupName = "datetime"; - private static final String datePatternString = + public static final String datePatternString = "^date and time\\(\"(?<" + dateGroupName + ">(?:19|20)\\d{2}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\d|3[01])T(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d)\"\\)$"; @@ -43,6 +61,12 @@ public class DateBoundary extends AbstractGrowingBoundary<LocalDateTime> { .toFormatter(); } + /** + * Parse the input text to a new Date boundary. See {@link DateBoundary} for the required + * structure. + * + * @param text the text, which will be parsed to the new Dateoundary object + */ public DateBoundary(String text) { super(text, LocalDateTime.class); } diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/DoubleBoundary.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/DoubleBoundary.java index 6dd524516b15a82e1b473c735bee305cc8801627..34f35fbdcf13c6ce63ecd310cca9d31ca11a9262 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/DoubleBoundary.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/DoubleBoundary.java @@ -8,8 +8,50 @@ import de.unikoblenz.fgbks.base.utils.boundary.BoundType; import de.unikoblenz.fgbks.base.utils.boundary.BoundaryParseException; import org.apache.commons.lang3.Validate; +/** + * The double boundary is a rage between two double values. And looks as string representation like + * + * <ul> + * <li>"= 10.0"<br> + * {lowerBound=10.0; upperBound=10.0; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"<= 10.0"<br> + * {lowerBound=-INFINITY; upperBound=10.0; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"< 10.0"<br> + * {lowerBound=-INFINITY; upperBound=10.0; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"> 10.0"<br> + * {lowerBound=10.0; upperBound=INFINITY; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>">= 10.0"<br> + * {lowerBound=10.0; upperBound=INFINITY; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"[10.0..20.0]" <br> + * {lowerBound=10.0; upperBound=20.0; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"]10.0..20.0]" <br> + * {lowerBound=10.0; upperBound=20; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"]10.0..20.0[" <br> + * {lowerBound=10.0; upperBound=20.0; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"[10.0..20.0[" <br> + * {lowerBound=10.0; upperBound=20.0; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"" (empty String) <br> + * {lowerBound=-INFINITY; upperBound=INFINITY; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * </ul> + */ public class DoubleBoundary extends AbstractGrowingBoundary<Double> { + /** + * Parse the input text to a new Boolean boundary. See {@link DoubleBoundary} for the required + * structure. + * + * @param text the text, which will be parsed to the new DoubleBoundary object + */ public DoubleBoundary(String text) { super(text, Double.TYPE); } diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/IntegerBoundary.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/IntegerBoundary.java index 79c53c5036bd3c448ed7e8fec720f3d2356351d0..5c480ebc6586717ebff743be19486c76608d60dd 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/IntegerBoundary.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/IntegerBoundary.java @@ -8,8 +8,51 @@ import de.unikoblenz.fgbks.base.utils.boundary.BoundType; import de.unikoblenz.fgbks.base.utils.boundary.BoundaryParseException; import org.apache.commons.lang3.Validate; +/** + * The integer boundary is a rage between two integer values. And looks as string representation + * like + * + * <ul> + * <li>"= 10"<br> + * {lowerBound=10; upperBound=10; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"<= 10"<br> + * {lowerBound=-INFINITY; upperBound=10; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"< 10"<br> + * {lowerBound=-INFINITY; upperBound=10; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"> 10"<br> + * {lowerBound=10; upperBound=INFINITY; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>">= 10"<br> + * {lowerBound=10; upperBound=INFINITY; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"[10..20]" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"]10..20]" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"]10..20[" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"[10..20[" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"" (empty String) <br> + * {lowerBound=-INFINITY; upperBound=INFINITY; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * </ul> + */ public class IntegerBoundary extends AbstractGrowingBoundary<Integer> { + /** + * Parse the input text to a new Integer boundary. See {@link IntegerBoundary} for the required + * structure. + * + * @param text the text, which will be parsed to the new IntegerBoundary object + */ public IntegerBoundary(String text) { super(text, Integer.TYPE); } diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/InvalidBoundary.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/InvalidBoundary.java index 7a9cfafbf0756959bc9bed6cb2b9c732aa17a21c..c314d0544a6807023ca083fc9b02e8f48c422460 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/InvalidBoundary.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/InvalidBoundary.java @@ -7,12 +7,21 @@ import de.unikoblenz.fgbks.base.utils.boundary.creater.BoundaryCreaterType; import de.unikoblenz.fgbks.core.dmn.domain.vdmn.VTypeRef; import java.util.Optional; +/** + * A invalid boundary, which is used, if e.g. no boundary can be parsed. + */ public class InvalidBoundary implements Boundary { private static InvalidBoundary instance = new InvalidBoundary(); - private InvalidBoundary() {} + private InvalidBoundary() { + } + /** + * Get the singleton instance of the invalid boundary. + * + * @return the invalid boundary instance + */ public static InvalidBoundary getInstance() { return instance; } @@ -43,7 +52,7 @@ public class InvalidBoundary implements Boundary { } @Override - public Optional<Boundary> createBi(BoundaryBiCreaterType combineType, Boundary other) { + public Optional<Boundary> createBi(BoundaryBiCreaterType biCreaterType, Boundary other) { return Optional.empty(); } diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/LongBoundary.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/LongBoundary.java index 06e316d3b3b2d4192968b1b7006290591fb71388..d46eca6a36ab18b89c343a925dceb1f278a88555 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/LongBoundary.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/LongBoundary.java @@ -8,8 +8,50 @@ import de.unikoblenz.fgbks.base.utils.boundary.BoundType; import de.unikoblenz.fgbks.base.utils.boundary.BoundaryParseException; import org.apache.commons.lang3.Validate; +/** + * The long boundary is a rage between two long values. And looks as string representation like + * + * <ul> + * <li>"= 10"<br> + * {lowerBound=10; upperBound=10; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"<= 10"<br> + * {lowerBound=-INFINITY; upperBound=10; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"< 10"<br> + * {lowerBound=-INFINITY; upperBound=10; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"> 10"<br> + * {lowerBound=10; upperBound=INFINITY; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>">= 10"<br> + * {lowerBound=10; upperBound=INFINITY; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"[10..20]" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"]10..20]" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * <li>"]10..20[" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#EXCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"[10..20[" <br> + * {lowerBound=10; upperBound=20; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#EXCLUSIVE}) + * <li>"" (empty String) <br> + * {lowerBound=-INFINITY; upperBound=INFINITY; lowerBoundType={@link BoundType#INCLUSIVE}, + * upperBoundType={@link BoundType#INCLUSIVE}) + * </ul> + */ public class LongBoundary extends AbstractGrowingBoundary<Long> { + /** + * Parse the input text to a new Long boundary. See {@link LongBoundary} for the required + * structure. + * + * @param text the text, which will be parsed to the new LongBoundary object + */ public LongBoundary(String text) { super(text, Long.TYPE); } @@ -19,7 +61,7 @@ public class LongBoundary extends AbstractGrowingBoundary<Long> { } @Override - public AbstractGrowingBoundary getCopy( + public AbstractGrowingBoundary<Long> getCopy( Long lowerBound, Long upperBound, BoundType lowerBoundType, BoundType upperBoundType) { LongBoundary v = new LongBoundary(); v.lowerBound = lowerBound; diff --git a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/StringBoundary.java b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/StringBoundary.java index 54c225d89813637b2d167b3181beb8a4cdeb7f42..973d8d55fa13640d987333d466fcda376c715eb4 100644 --- a/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/StringBoundary.java +++ b/dmnverifierapi/src/main/java/de/unikoblenz/fgbks/base/utils/boundary/impl/StringBoundary.java @@ -50,6 +50,16 @@ import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.lang3.Validate; +/** + * String Boundary, representing a set of strings. If the boundary contains all possible string, the + * method {@link StringBoundary#matchesAny()} returns true. The method {@link + * StringBoundary#getValues()} returns all string, which are in the boundary, or if {@link + * StringBoundary#matchesNoneOfValues} returns true, which are not in the boundary. <br> + * + * <p>Only value "a": <br> + * {@code "a"} <br> Value "a" or value "b": <br> {@code "a","b"} <br> Not value "a" and not value + * "b": <br> {@code not("a","b")} <br> All values: <br> {@code (empty String)} + */ public class StringBoundary extends AbstractBoundary<String> { private static HashMap<BoundaryCheckType, BoundaryCheck> checkerMap = new HashMap<>(); @@ -79,6 +89,12 @@ public class StringBoundary extends AbstractBoundary<String> { // sorted list of cached hashes of valuesHashes private int[] valuesHashes; + /** + * Parse the input text to a new String boundary. See {@link StringBoundary} for the required + * structure or use {@link StringBoundary#getBuilder()} to create a StringBoundary with a builder. + * + * @param text the text, which will be parsed to the new StringBoundary object + */ public StringBoundary(String text) { super(text, String.class); } @@ -92,26 +108,53 @@ public class StringBoundary extends AbstractBoundary<String> { return o.getText().compareTo(o.getText()); } + /** + * Get a new builder object of the StringBoundary. + * + * @return a new builder + */ + public static Builder getBuilder() { + return new StringBoundary().new Builder(); + } + + /** + * Get the boolean, if the StringBoundary matches none of the values. + * + * @return true, if the StringBoundary matches none of the values + */ public boolean matchesNoneOfValues() { return matchesNoneOfValues; } + /** + * Get the boolean, if the StringBoundary matches all possible values. + * + * @return true, if the StringBoundary matches all possible values + */ public boolean matchesAny() { return matchesAny; } + /** + * Get all the values, which are representing the String boundary. The created array is a copy of + * the original one. + * + * @return all values as String array + */ public String[] getValues() { return values.clone(); // performance ? } + /** + * Get all the hashes of the string values as sorted array. The created array is a copy of the + * original one. + * + * @return all hashes of the values as int array + */ public int[] getValuesHashes() { return valuesHashes.clone(); // performance ? } - public int getAmountOfElements() { - return values.length; - } - @Override protected void parse(String text) { matchesNoneOfValues = false; @@ -144,9 +187,15 @@ public class StringBoundary extends AbstractBoundary<String> { Arrays.sort(valuesHashes); } - @Override - protected void validate() { - Validate.noNullElements(values); + /** + * Get the amount of string values. This method is preferred to get the size of the result from + * the {@link StringBoundary#getValues()} method, because {@link StringBoundary#getValues()} + * creates a copy of the array. + * + * @return the size of the array from {@link StringBoundary#getValues()}. + */ + public int getAmountOfElements() { + return values.length; } @Override @@ -164,6 +213,19 @@ public class StringBoundary extends AbstractBoundary<String> { return Collections.unmodifiableMap(createrMap); } + @Override + protected void validate() { + try { + Validate.noNullElements(values); + } catch (Exception e) { + throw new BoundaryParseException( + "String value " + getText() + " could not be parsed to a StringBoundary"); + } + } + + /** + * {@inheritDoc} + */ @Override public String getParsedText() { return (matchesNoneOfValues ? "not(" : "") @@ -171,10 +233,7 @@ public class StringBoundary extends AbstractBoundary<String> { + (matchesNoneOfValues ? ")" : ""); } - public static Builder getBuilder() { - return new StringBoundary().new Builder(); - } - + /** Builder to create new {@link StringBoundary}s. */ public class Builder extends DefaultBuilder<StringBoundary> { private Set<String> buildingValues; @@ -185,32 +244,53 @@ public class StringBoundary extends AbstractBoundary<String> { value.matchesNoneOfValues = false; } + /** See {@link StringBoundary#matchesNoneOfValues()}. */ public Builder matchesNoneOfValues(boolean matchesNoneOfValues) { value.matchesNoneOfValues = matchesNoneOfValues; return this; } + /** See {@link StringBoundary#matchesAny()}. */ public Builder matchesAny(boolean matchAny) { value.matchesAny = matchAny; return this; } + /** + * Add a value to the StringBoundary. + * + * @param value the String value + * @return the current builder + */ public Builder addValue(String value) { buildingValues.add(Validate.notNull(value)); return this; } + /** + * Add values to the StringBoundary. + * + * @param values the String values + * @return the current builder + */ public Builder addValues(Collection<String> values) { buildingValues.addAll(Validate.noNullElements(values)); return this; } + /** + * Add values to the StringBoundary. + * + * @param values the String values + * @return the current builder + */ public Builder addValues(String[] values) { return addValues(Validate.notNull(Arrays.asList(values))); } @Override - public StringBoundary build() { + protected void validate() { + super.validate(); value.values = buildingValues.toArray(new String[0]); if (value.matchesAny) { value.matchesNoneOfValues = false; @@ -218,6 +298,16 @@ public class StringBoundary extends AbstractBoundary<String> { } value.calcHashes(); value.text = value.getParsedText(); + value.validate(); + } + + /** + * Build the StringBoundary. + * + * @return a new instance of the {@link StringBoundary} + */ + @Override + public StringBoundary build() { return super.build(); } }