Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
67214f92
Commit
67214f92
authored
Apr 15, 2025
by
Riegel
Browse files
Refactor: Add Visitors for ValidationError checking
parent
e015765c
Changes
7
Show whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/check/Checkable.java
View file @
67214f92
...
@@ -24,6 +24,9 @@ import java.util.HashMap;
...
@@ -24,6 +24,9 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
de.hft.stuttgart.citydoctor2.utils.CheckErrorFound
;
import
de.hft.stuttgart.citydoctor2.utils.ContainsAnyErrorVisitor
;
import
de.hft.stuttgart.citydoctor2.utils.ContainsErrorVisitor
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
...
@@ -106,6 +109,15 @@ public abstract class Checkable implements Serializable {
...
@@ -106,6 +109,15 @@ public abstract class Checkable implements Serializable {
* @return true if an error has been found with the given check
* @return true if an error has been found with the given check
*/
*/
public
boolean
containsError
(
CheckId
checkIdentifier
)
{
public
boolean
containsError
(
CheckId
checkIdentifier
)
{
try
{
ContainsErrorVisitor
.
checkCityObject
(
this
,
checkIdentifier
);
}
catch
(
CheckErrorFound
c
)
{
return
true
;
}
return
false
;
}
public
boolean
hasError
(
CheckId
checkIdentifier
)
{
CheckResult
cs
=
getCheckResult
(
checkIdentifier
);
CheckResult
cs
=
getCheckResult
(
checkIdentifier
);
if
(
cs
==
null
)
{
if
(
cs
==
null
)
{
return
false
;
return
false
;
...
@@ -165,7 +177,7 @@ public abstract class Checkable implements Serializable {
...
@@ -165,7 +177,7 @@ public abstract class Checkable implements Serializable {
*
*
* @return true if it has an error, otherwise false
* @return true if it has an error, otherwise false
*/
*/
public
boolean
hasAnyError
()
{
public
boolean
hasAnyError
WithoutDependencies
()
{
for
(
CheckResult
cr
:
checkResults
.
values
())
{
for
(
CheckResult
cr
:
checkResults
.
values
())
{
if
(
cr
.
getResultStatus
()
==
ResultStatus
.
ERROR
)
{
if
(
cr
.
getResultStatus
()
==
ResultStatus
.
ERROR
)
{
return
true
;
return
true
;
...
@@ -216,6 +228,15 @@ public abstract class Checkable implements Serializable {
...
@@ -216,6 +228,15 @@ public abstract class Checkable implements Serializable {
* have any error.
* have any error.
*/
*/
public
boolean
containsAnyError
()
{
public
boolean
containsAnyError
()
{
try
{
ContainsAnyErrorVisitor
.
checkObject
(
this
);
}
catch
(
CheckErrorFound
c
)
{
return
true
;
}
return
false
;
}
public
boolean
hasAnyError
()
{
for
(
CheckResult
cr
:
checkResults
.
values
())
{
for
(
CheckResult
cr
:
checkResults
.
values
())
{
if
(
cr
.
getResultStatus
()
==
ResultStatus
.
ERROR
if
(
cr
.
getResultStatus
()
==
ResultStatus
.
ERROR
||
cr
.
getResultStatus
()
==
ResultStatus
.
DEPENDENCIES_NOT_MET
)
{
||
cr
.
getResultStatus
()
==
ResultStatus
.
DEPENDENCIES_NOT_MET
)
{
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/datastructure/LinkedPolygon.java
View file @
67214f92
...
@@ -77,8 +77,8 @@ public class LinkedPolygon extends Polygon {
...
@@ -77,8 +77,8 @@ public class LinkedPolygon extends Polygon {
}
}
@Override
@Override
public
boolean
hasAnyError
()
{
public
boolean
hasAnyError
WithoutDependencies
()
{
return
poly
.
hasAnyError
();
return
poly
.
hasAnyError
WithoutDependencies
();
}
}
@Override
@Override
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/utils/CheckErrorFound.java
0 → 100644
View file @
67214f92
package
de.hft.stuttgart.citydoctor2.utils
;
public
class
CheckErrorFound
extends
Throwable
{
public
CheckErrorFound
()
{
super
(
"CheckError was found"
,
null
,
true
,
false
);
}
}
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/utils/ContainsAnyErrorVisitor.java
0 → 100644
View file @
67214f92
package
de.hft.stuttgart.citydoctor2.utils
;
import
de.hft.stuttgart.citydoctor2.check.AbstractCheck
;
import
de.hft.stuttgart.citydoctor2.check.Checkable
;
public
class
ContainsAnyErrorVisitor
extends
AbstractCheck
{
public
static
void
checkObject
(
Checkable
checkable
)
throws
CheckErrorFound
{
checkable
.
accept
(
new
ContainsAnyErrorVisitor
());
}
@Override
public
void
check
(
Checkable
checkable
)
{
if
(
checkable
.
hasAnyErrorWithoutDependencies
())
{
ThrowUtils
.
sneakyThrow
(
new
CheckErrorFound
());
}
}
}
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/utils/ContainsErrorVisitor.java
0 → 100644
View file @
67214f92
package
de.hft.stuttgart.citydoctor2.utils
;
import
de.hft.stuttgart.citydoctor2.check.AbstractCheck
;
import
de.hft.stuttgart.citydoctor2.check.CheckId
;
import
de.hft.stuttgart.citydoctor2.check.Checkable
;
import
de.hft.stuttgart.citydoctor2.datastructure.CityObject
;
public
class
ContainsErrorVisitor
extends
AbstractCheck
{
private
CheckId
checkId
;
public
static
void
checkCityObject
(
Checkable
checkable
,
CheckId
checkIdentifier
)
throws
CheckErrorFound
{
checkable
.
accept
(
new
ContainsErrorVisitor
(
checkIdentifier
));
}
@Override
public
void
check
(
Checkable
checkable
)
{
if
(
checkable
.
hasError
(
checkId
))
{
ThrowUtils
.
sneakyThrow
(
new
CheckErrorFound
());
}
}
public
ContainsErrorVisitor
(
CheckId
checkIdentifier
)
{
super
();
checkId
=
checkIdentifier
;
}
}
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/utils/ThrowUtils.java
0 → 100644
View file @
67214f92
package
de.hft.stuttgart.citydoctor2.utils
;
public
class
ThrowUtils
{
private
ThrowUtils
()
{
}
@SuppressWarnings
(
"unchecked"
)
private
static
<
T
extends
Throwable
>
void
uncheckThrowable
(
Throwable
t
)
throws
T
{
throw
(
T
)
t
;
}
/**
* Throws a Throwable as an unchecked generic Throwable
*/
public
static
void
sneakyThrow
(
Throwable
t
)
{
uncheckThrowable
(
t
);
}
}
CityDoctorParent/CityDoctorValidation/src/test/java/de/hft/stuttgart/citydoctor2/checks/geometry/NullAreaCheckTest.java
View file @
67214f92
...
@@ -90,7 +90,7 @@ public class NullAreaCheckTest {
...
@@ -90,7 +90,7 @@ public class NullAreaCheckTest {
LinearRing
r
=
setupErrorGeometry
();
LinearRing
r
=
setupErrorGeometry
();
NullAreaCheck
nac
=
new
NullAreaCheck
();
NullAreaCheck
nac
=
new
NullAreaCheck
();
nac
.
check
(
r
);
nac
.
check
(
r
);
Assert
.
assertTrue
(
r
.
hasAnyError
());
Assert
.
assertTrue
(
r
.
hasAnyError
WithoutDependencies
());
}
}
...
@@ -100,7 +100,7 @@ public class NullAreaCheckTest {
...
@@ -100,7 +100,7 @@ public class NullAreaCheckTest {
LinearRing
r
=
setupValidGeometry
();
LinearRing
r
=
setupValidGeometry
();
NullAreaCheck
nac
=
new
NullAreaCheck
();
NullAreaCheck
nac
=
new
NullAreaCheck
();
nac
.
check
(
r
);
nac
.
check
(
r
);
Assert
.
assertFalse
(
r
.
hasAnyError
());
Assert
.
assertFalse
(
r
.
hasAnyError
WithoutDependencies
());
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment