Skip to content
Snippets Groups Projects
Commit 9b94d9eb authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

Add documentation for boundary creater, checker

parent 55ebe9d9
Branches
Tags
No related merge requests found
Showing
with 293 additions and 12 deletions
......@@ -9,6 +9,12 @@ import de.unikoblenz.fgbks.base.utils.boundary.impl.IntegerBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.LongBoundary;
import java.util.Optional;
/**
* The combine creator implementation of {@link BoundaryBiCreaterType#APPEND} for {@link
* AbstractGrowingBoundary}. <br> The result is a new boundary with the combined range of both
* boundaries, or an empty optional, if the creation is not possible. Both boundaries are not in
* contact. <br> In: {@code b1: [10..30[; b2: [30..50]} <br> Out: {@code ]10..50[} <br>
*/
public class BiCreaterAppend extends AbstractBoundaryBiCreater<AbstractGrowingBoundary> {
private static final BiCreaterAppend instance = new BiCreaterAppend();
......@@ -17,6 +23,11 @@ public class BiCreaterAppend extends AbstractBoundaryBiCreater<AbstractGrowingBo
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterAppend getInstance() {
return instance;
}
......
......@@ -9,6 +9,12 @@ import de.unikoblenz.fgbks.base.utils.boundary.impl.DoubleBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.IntegerBoundary;
import java.util.Optional;
/**
* The between creator implementation of {@link BoundaryBiCreaterType#BETWEEN} for {@link
* AbstractGrowingBoundary}. <br> The result is a new boundary with boundary between the both
* boundaries, or an empty optional, if the creation is not possible. <br> In: {@code b1: [10..20];
* b2: [30..50]} <br> Out: {@code ]20..30[} <br>
*/
public class BiCreaterBetween extends AbstractBoundaryBiCreater<AbstractGrowingBoundary> {
private static final BiCreaterBetween instance = new BiCreaterBetween();
......@@ -17,6 +23,11 @@ public class BiCreaterBetween extends AbstractBoundaryBiCreater<AbstractGrowingB
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterBetween getInstance() {
return instance;
}
......@@ -34,9 +45,9 @@ public class BiCreaterBetween extends AbstractBoundaryBiCreater<AbstractGrowingB
}
// no space between the two bounds
if (b1.getUpperBound().equals(b2.getLowerBound())
&& !b1.getUpperBound().equals(b2.getLowerBound())
&& !b1.getUpperBound().equals(b2.getLowerBound())
|| b2.getUpperBound().equals(b1.getLowerBound())
&& !b2.getUpperBound().equals(b1.getLowerBound())) {
&& !b2.getUpperBound().equals(b1.getLowerBound())) {
return Optional.empty();
}
if (b1 instanceof IntegerBoundary) {
......@@ -45,11 +56,11 @@ public class BiCreaterBetween extends AbstractBoundaryBiCreater<AbstractGrowingB
int b2L = (int) b1.getLowerBound();
int b2U = (int) b1.getUpperBound();
if (b1U + 1 == b2L
&& b1.getUpperBoundType() == INCLUSIVE
&& b2.getLowerBoundType() == INCLUSIVE
&& b1.getUpperBoundType() == INCLUSIVE
&& b2.getLowerBoundType() == INCLUSIVE
|| b2U + 1 == b1L
&& b2.getUpperBoundType() == INCLUSIVE
&& b1.getLowerBoundType() == INCLUSIVE) {
&& b2.getUpperBoundType() == INCLUSIVE
&& b1.getLowerBoundType() == INCLUSIVE) {
return Optional.empty();
}
}
......@@ -59,11 +70,11 @@ public class BiCreaterBetween extends AbstractBoundaryBiCreater<AbstractGrowingB
long b2L = (long) b1.getLowerBound();
long b2U = (long) b1.getUpperBound();
if (b1U + 1 == b2L
&& b1.getUpperBoundType() == INCLUSIVE
&& b2.getLowerBoundType() == INCLUSIVE
&& b1.getUpperBoundType() == INCLUSIVE
&& b2.getLowerBoundType() == INCLUSIVE
|| b2U + 1 == b1L
&& b2.getUpperBoundType() == INCLUSIVE
&& b1.getLowerBoundType() == INCLUSIVE) {
&& b2.getUpperBoundType() == INCLUSIVE
&& b1.getLowerBoundType() == INCLUSIVE) {
return Optional.empty();
}
}
......
......@@ -8,6 +8,12 @@ import static de.unikoblenz.fgbks.base.utils.boundary.checker.BoundaryCheckType.
import de.unikoblenz.fgbks.base.utils.boundary.AbstractGrowingBoundary;
import java.util.Optional;
/**
* The combine creator implementation of {@link BoundaryBiCreaterType#COMBINE} for {@link
* AbstractGrowingBoundary}. <br> The result is a new boundary with the combined range of both
* boundaries, or an empty optional, if the creation is not possible. <br> In: {@code b1: [10..20];
* b2: [15..30]} <br> Out: {@code [10..30]} <br>
*/
public class BiCreaterCombine extends AbstractBoundaryBiCreater<AbstractGrowingBoundary> {
private static final BiCreaterCombine instance = new BiCreaterCombine();
......@@ -16,6 +22,11 @@ public class BiCreaterCombine extends AbstractBoundaryBiCreater<AbstractGrowingB
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterCombine getInstance() {
return instance;
}
......
......@@ -6,6 +6,12 @@ import static de.unikoblenz.fgbks.base.utils.boundary.checker.BoundaryCheckType.
import de.unikoblenz.fgbks.base.utils.boundary.AbstractGrowingBoundary;
import java.util.Optional;
/**
* The intersection creator implementation of {@link BoundaryBiCreaterType#INTERSECTION} for {@link
* AbstractGrowingBoundary}. <br> The result is a new boundary with intersection of both boundaries,
* or an empty optional, if the creation is not possible. <br> In: {@code b1: [10..20]; b2:
* [15..30]} <br> Out: {@code [15..20]} <br>
*/
public class BiCreaterIntersection extends AbstractBoundaryBiCreater<AbstractGrowingBoundary> {
private static final BiCreaterIntersection instance = new BiCreaterIntersection();
......@@ -14,6 +20,11 @@ public class BiCreaterIntersection extends AbstractBoundaryBiCreater<AbstractGro
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterIntersection getInstance() {
return instance;
}
......
......@@ -9,6 +9,12 @@ import de.unikoblenz.fgbks.base.utils.boundary.impl.IntegerBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.LongBoundary;
import java.util.Optional;
/**
* The lower bound creator implementation of {@link BoundaryBiCreaterType#LOWER_BOUNDS} for {@link
* AbstractGrowingBoundary}. <br> The result is a new boundary with the lower bounds, or an empty
* optional, if the creation is not possible. <br> In: {@code b1: [10..20]; b2: [15..30]} <br> Out:
* {@code [10..15[} <br>
*/
public class BiCreaterLowerBounds extends AbstractBoundaryBiCreater<AbstractGrowingBoundary> {
private static final BiCreaterLowerBounds instance = new BiCreaterLowerBounds();
......@@ -17,6 +23,11 @@ public class BiCreaterLowerBounds extends AbstractBoundaryBiCreater<AbstractGrow
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterLowerBounds getInstance() {
return instance;
}
......
......@@ -7,6 +7,12 @@ import de.unikoblenz.fgbks.base.utils.boundary.Boundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.StringBoundary;
import java.util.Optional;
/**
* The between creator implementation of {@link BoundaryBiCreaterType#BETWEEN} for {@link
* StringBoundary}. <br> The result is a new boundary with boundary between the both boundaries, or
* an empty optional, if the creation is not possible. The boundaries are not in contact. <br> In:
* {@code b1: "a"; b2: "b"} <br> Out: {@code not("a","b")} <br>
*/
public class BiCreaterStringAppend extends AbstractBoundaryBiCreater<StringBoundary> {
private static final BiCreaterStringAppend instance = new BiCreaterStringAppend();
......@@ -15,6 +21,11 @@ public class BiCreaterStringAppend extends AbstractBoundaryBiCreater<StringBound
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterStringAppend getInstance() {
return instance;
}
......
......@@ -6,6 +6,12 @@ import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
/**
* The between creator implementation of {@link BoundaryBiCreaterType#BETWEEN} for {@link
* StringBoundary}. <br> The result is a new boundary with boundary between the both boundaries, or
* an empty optional, if the creation is not possible. <br> In: {@code b1: "a"; b2: "b"} <br> Out:
* {@code not("a","b")} <br>
*/
public class BiCreaterStringBetween extends AbstractBoundaryBiCreater<StringBoundary> {
private static final BiCreaterStringBetween instance = new BiCreaterStringBetween();
......@@ -14,6 +20,11 @@ public class BiCreaterStringBetween extends AbstractBoundaryBiCreater<StringBoun
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterStringBetween getInstance() {
return instance;
}
......
......@@ -6,6 +6,12 @@ import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
/**
* The combine creator implementation of {@link BoundaryBiCreaterType#COMBINE} for {@link
* StringBoundary}. <br> The result is a new boundary with the combined range of both boundaries, or
* an empty optional, if the creation is not possible. <br> In: {@code b1: "a"; b2: "b"} <br> Out:
* {@code "a","b"} <br>
*/
public class BiCreaterStringCombine extends AbstractBoundaryBiCreater<StringBoundary> {
private static final BiCreaterStringCombine instance = new BiCreaterStringCombine();
......@@ -14,6 +20,11 @@ public class BiCreaterStringCombine extends AbstractBoundaryBiCreater<StringBoun
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterStringCombine getInstance() {
return instance;
}
......
......@@ -10,6 +10,12 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
/**
* The intersection creator implementation of {@link BoundaryBiCreaterType#INTERSECTION} for {@link
* StringBoundary}. <br> The result is a new boundary with intersection of both boundaries, or an
* empty optional, if the creation is not possible. <br> In: {@code b1: "a" b2: "a","b"} <br> Out:
* {@code "a"} <br>
*/
public class BiCreaterStringIntersection extends AbstractBoundaryBiCreater<StringBoundary> {
private static final BiCreaterStringIntersection instance = new BiCreaterStringIntersection();
......@@ -18,6 +24,11 @@ public class BiCreaterStringIntersection extends AbstractBoundaryBiCreater<Strin
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterStringIntersection getInstance() {
return instance;
}
......
......@@ -9,6 +9,11 @@ import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
/**
* The lower bound creator implementation of {@link BoundaryBiCreaterType#LOWER_BOUNDS} for {@link
* StringBoundary}. <br> The result is a new boundary with the lower bounds, or an empty optional,
* if the creation is not possible. <br> In: {@code b1: "a","b"; b2: "a"}<br> Out: {@code "b"} <br>
*/
public class BiCreaterStringLowerBounds extends AbstractBoundaryBiCreater<StringBoundary> {
private static final BiCreaterStringLowerBounds instance = new BiCreaterStringLowerBounds();
......@@ -17,6 +22,11 @@ public class BiCreaterStringLowerBounds extends AbstractBoundaryBiCreater<String
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterStringLowerBounds getInstance() {
return instance;
}
......
......@@ -3,6 +3,11 @@ package de.unikoblenz.fgbks.base.utils.boundary.bicreater;
import de.unikoblenz.fgbks.base.utils.boundary.impl.StringBoundary;
import java.util.Optional;
/**
* The upper bound creator implementation of {@link BoundaryBiCreaterType#UPPER_BOUNDS} for {@link
* StringBoundary}. <br> The result is a new boundary is always empty. See {@link
* BiCreaterStringLowerBounds} instead.
*/
public class BiCreaterStringUpperBounds extends AbstractBoundaryBiCreater<StringBoundary> {
private static final BiCreaterStringUpperBounds instance = new BiCreaterStringUpperBounds();
......@@ -11,6 +16,11 @@ public class BiCreaterStringUpperBounds extends AbstractBoundaryBiCreater<String
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterStringUpperBounds getInstance() {
return instance;
}
......
......@@ -9,6 +9,12 @@ import de.unikoblenz.fgbks.base.utils.boundary.impl.IntegerBoundary;
import de.unikoblenz.fgbks.base.utils.boundary.impl.LongBoundary;
import java.util.Optional;
/**
* The upper bound creator implementation of {@link BoundaryBiCreaterType#UPPER_BOUNDS} for {@link
* AbstractGrowingBoundary}. <br> The result is a new boundary with the upper bounds, or an empty
* optional, if the creation is not possible. <br> In: {@code b1: [10..20]; b2: [15..30]} <br> Out:
* {@code ]20..30]} <br>
*/
public class BiCreaterUpperBounds extends AbstractBoundaryBiCreater<AbstractGrowingBoundary> {
private static final BiCreaterUpperBounds instance = new BiCreaterUpperBounds();
......@@ -17,6 +23,11 @@ public class BiCreaterUpperBounds extends AbstractBoundaryBiCreater<AbstractGrow
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static BiCreaterUpperBounds getInstance() {
return instance;
}
......
......@@ -3,9 +3,27 @@ package de.unikoblenz.fgbks.base.utils.boundary.bicreater;
import de.unikoblenz.fgbks.base.utils.boundary.Boundary;
import java.util.Optional;
/**
* The biCreater interface. Used to create a new Boundary of a given one and an other boundary with
* a modification, specified by the {@link BoundaryBiCreaterType}.
*
* @param <T> the boundary type
*/
public interface BoundaryBiCreater<T extends Boundary> {
/**
* Get the {@link BoundaryBiCreaterType}.
*
* @return the {@link BoundaryBiCreaterType}
*/
BoundaryBiCreaterType getType();
/**
* Perform the creation of a new boundary with the given two boundaries.
*
* @param b1 one boundary
* @param b2 the other boundary
* @return An optional with a new boundary or an empty optional, if the creation fails.
*/
Optional<T> create(T b1, T b2);
}
package de.unikoblenz.fgbks.base.utils.boundary.bicreater;
public enum BoundaryBiCreaterType {
/**
* Type, that indicates, that the creater should create a new boundary, which is the intersection
* of the two boundaries.
*/
INTERSECTION,
/**
* Type, that indicates, that the creater should create a new boundary with the lower bounds of
* both boundaries.
*/
LOWER_BOUNDS,
/**
* Type, that indicates, that the creater should create a new boundary with the upper bounds of
* both boundaries.
*/
UPPER_BOUNDS,
/**
* Type, that indicates, that the creater should create a new boundary, which is between the both
* boundaries.
*/
BETWEEN,
/**
* Type, that indicates, that the creater should create a new boundary, which is a combination of
* the both boundaries. However, both boundaries are not in contact.
*/
APPEND,
COMBINE;
/**
* Type, that indicates, that the creater should create a new boundary, which is a combination of
* the both boundaries. Both boundaries can be in contact. (UNION)
*/
COMBINE
}
......@@ -3,6 +3,9 @@ package de.unikoblenz.fgbks.base.utils.boundary.bicreater;
import de.unikoblenz.fgbks.base.utils.boundary.Boundary;
import java.util.Optional;
/**
* The empty bi creater returns always an empty optional.
*/
public class EmptyBiCreater extends AbstractBoundaryBiCreater<Boundary> {
private static final EmptyBiCreater instance = new EmptyBiCreater();
......@@ -11,6 +14,11 @@ public class EmptyBiCreater extends AbstractBoundaryBiCreater<Boundary> {
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static EmptyBiCreater getInstance() {
return instance;
}
......
......@@ -2,9 +2,27 @@ package de.unikoblenz.fgbks.base.utils.boundary.checker;
import de.unikoblenz.fgbks.base.utils.boundary.Boundary;
/**
* The checker interface. Used to check something between two boundaries, specified by the {@link
* BoundaryCheckType}.
*
* @param <T> the boundary type
*/
public interface BoundaryCheck<T extends Boundary> {
/**
* Get the {@link BoundaryCheckType}.
*
* @return the {@link BoundaryCheckType}
*/
BoundaryCheckType getType();
/**
* Perform the check between the two boundaries.
*
* @param b1 one boundary
* @param b2 the other boundary
* @return true, if the check return true.
*/
boolean check(T b1, T b2);
}
package de.unikoblenz.fgbks.base.utils.boundary.checker;
public enum BoundaryCheckType {
/**
* Type, that indicates, that the checker should check, if one boundary is equal to the other
* boundary.
*/
IS_EQUAL,
/**
* Type, that indicates, that the checker should check, if one boundary subsumes the other
* boundary or the other boundary subsumes the first boundary.
*/
IS_SUBSUMPTION,
/**
* Type, that indicates, that the checker should check, if one boundary subsumes the other
* boundary.
*/
SUBSUMES,
/**
* Type, that indicates, that the checker should check, if one boundary is in contact to the other
* boundary.
*/
IS_IN_CONTACT,
/**
* Type, that indicates, that the checker should check, if one boundary is not in contact to the
* other boundary.
*/
IS_NOT_IN_CONTACT,
IS_OVERLAPPING;
/**
* Type, that indicates, that the checker should check, if one boundary is overlapping with the
* other boundary.
*/
IS_OVERLAPPING
}
......@@ -2,6 +2,17 @@ package de.unikoblenz.fgbks.base.utils.boundary.checker;
import de.unikoblenz.fgbks.base.utils.boundary.AbstractGrowingBoundary;
/**
* The equal checker implementation of {@link BoundaryCheckType#IS_EQUAL} for {@link
* AbstractGrowingBoundary}. <br> The check returns true, if the first boundary is equal to the
* other boundary. <br> E.g: <br>
*
* <ul>
* <li>b1 = "= 1"; b2 = "= 1" -> true
* <li>b1 = "<= 1"; b2 = "< 2" -> true (Integer or Long) / false (others)
* <li>b1 = "[0..20]"; b2 = "[4..22]" -> false
* </ul>
*/
public class CheckEqual extends AbstractBoundaryCheck<AbstractGrowingBoundary> {
private static final CheckEqual instance = new CheckEqual();
......@@ -10,6 +21,11 @@ public class CheckEqual extends AbstractBoundaryCheck<AbstractGrowingBoundary> {
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static CheckEqual getInstance() {
return instance;
}
......@@ -24,6 +40,7 @@ public class CheckEqual extends AbstractBoundaryCheck<AbstractGrowingBoundary> {
return checkEqual(b1, b2);
}
/** see {@link CheckEqual} */
public static boolean checkEqual(AbstractGrowingBoundary b1, AbstractGrowingBoundary b2) {
if (b1 == b2) {
return true;
......
......@@ -4,6 +4,19 @@ import static de.unikoblenz.fgbks.base.utils.boundary.BoundType.INCLUSIVE;
import de.unikoblenz.fgbks.base.utils.boundary.AbstractGrowingBoundary;
/**
* The in contact checker implementation of {@link BoundaryCheckType#IS_IN_CONTACT} for {@link
* AbstractGrowingBoundary}. <br> The check returns true, if the first boundary is in contact with
* the other boundary.
* <br>
* E.g: <br>
*
* <ul>
* <li>b1 = "= 1"; b2 = "= 1" -> true
* <li>b1 = "<= 1"; b2 = "< 2" -> true
* <li>b1 = "[0..20]"; b2 = "]20..22]" -> false
* </ul>
*/
public class CheckInContact extends AbstractBoundaryCheck<AbstractGrowingBoundary> {
private static final CheckInContact instance = new CheckInContact();
......@@ -12,6 +25,11 @@ public class CheckInContact extends AbstractBoundaryCheck<AbstractGrowingBoundar
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static CheckInContact getInstance() {
return instance;
}
......@@ -26,6 +44,9 @@ public class CheckInContact extends AbstractBoundaryCheck<AbstractGrowingBoundar
return checkInContact(b1, b2);
}
/**
* see {@link CheckInContact}
*/
public static boolean checkInContact(AbstractGrowingBoundary b1, AbstractGrowingBoundary b2) {
// TODO: check raw types
if (b1.getLowerBound().compareTo(b2.getLowerBound()) <= 0) {
......
......@@ -2,6 +2,19 @@ package de.unikoblenz.fgbks.base.utils.boundary.checker;
import de.unikoblenz.fgbks.base.utils.boundary.AbstractGrowingBoundary;
/**
* The subsumes checker implementation of {@link BoundaryCheckType#IS_SUBSUMPTION} for {@link
* AbstractGrowingBoundary}. <br> The check returns true, if the first boundary completely subsumes
* (not equal) the other boundary or the other way around.
* <br>
* E.g: <br>
*
* <ul>
* <li>b1 = "[0..20]"; b2 = "[4..19]" -> true
* <li>b1 = "[4..19]"; b2 = "[1..19]" -> true
* <li>b1 = "[0..20]"; b2 = "[4..22]" -> false
* </ul>
*/
public class CheckIsSubsumption extends AbstractBoundaryCheck<AbstractGrowingBoundary> {
private static final CheckIsSubsumption instance = new CheckIsSubsumption();
......@@ -10,6 +23,11 @@ public class CheckIsSubsumption extends AbstractBoundaryCheck<AbstractGrowingBou
super();
}
/**
* Get the current instance of this class.
*
* @return the singleton instance
*/
public static CheckIsSubsumption getInstance() {
return instance;
}
......@@ -24,6 +42,9 @@ public class CheckIsSubsumption extends AbstractBoundaryCheck<AbstractGrowingBou
return checkIsSubsumption(b1, b2);
}
/**
* see {@link CheckIsSubsumption}
*/
public static boolean checkIsSubsumption(AbstractGrowingBoundary b1, AbstractGrowingBoundary b2) {
return CheckSubsumes.checkSubsumes(b1, b2) || CheckSubsumes.checkSubsumes(b2, b1);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment