refactor to use exception helper factories

This commit is contained in:
Vukašin Stepanović
2023-02-15 10:46:13 +00:00
parent 3e27279dc8
commit 722ce78fd0
132 changed files with 966 additions and 1132 deletions

View File

@@ -44,7 +44,7 @@ impl BoundingBox {
let leftUnspecified = topLeft.is_none() || bottomLeft.is_none();
let rightUnspecified = topRight.is_none() || bottomRight.is_none();
if leftUnspecified && rightUnspecified {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFoundEmpty());
}
let newTopLeft;
@@ -53,21 +53,21 @@ impl BoundingBox {
let newBottomRight;
if leftUnspecified {
newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?;
newBottomRight = bottomRight.ok_or(Exceptions::IllegalStateException(None))?;
newTopRight = topRight.ok_or(Exceptions::illegalStateEmpty())?;
newBottomRight = bottomRight.ok_or(Exceptions::illegalStateEmpty())?;
newTopLeft = RXingResultPoint::new(0.0, newTopRight.getY());
newBottomLeft = RXingResultPoint::new(0.0, newBottomRight.getY());
} else if rightUnspecified {
newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?;
newBottomLeft = bottomLeft.ok_or(Exceptions::IllegalStateException(None))?;
newTopLeft = topLeft.ok_or(Exceptions::illegalStateEmpty())?;
newBottomLeft = bottomLeft.ok_or(Exceptions::illegalStateEmpty())?;
newTopRight = RXingResultPoint::new(image.getWidth() as f32 - 1.0, newTopLeft.getY());
newBottomRight =
RXingResultPoint::new(image.getWidth() as f32 - 1.0, newBottomLeft.getY());
} else {
newTopLeft = topLeft.ok_or(Exceptions::IllegalStateException(None))?;
newTopRight = topRight.ok_or(Exceptions::IllegalStateException(None))?;
newBottomLeft = bottomLeft.ok_or(Exceptions::IllegalStateException(None))?;
newBottomRight = bottomRight.ok_or(Exceptions::IllegalStateException(None))?;
newTopLeft = topLeft.ok_or(Exceptions::illegalStateEmpty())?;
newTopRight = topRight.ok_or(Exceptions::illegalStateEmpty())?;
newBottomLeft = bottomLeft.ok_or(Exceptions::illegalStateEmpty())?;
newBottomRight = bottomRight.ok_or(Exceptions::illegalStateEmpty())?;
}
Ok(BoundingBox {
@@ -104,17 +104,17 @@ impl BoundingBox {
if leftBox.is_none() {
return Ok(rightBox
.as_ref()
.ok_or(Exceptions::IllegalStateException(None))?
.ok_or(Exceptions::illegalStateEmpty())?
.clone());
}
if rightBox.is_none() {
return Ok(leftBox
.as_ref()
.ok_or(Exceptions::IllegalStateException(None))?
.ok_or(Exceptions::illegalStateEmpty())?
.clone());
}
let leftBox = leftBox.ok_or(Exceptions::IllegalStateException(None))?;
let rightBox = rightBox.ok_or(Exceptions::IllegalStateException(None))?;
let leftBox = leftBox.ok_or(Exceptions::illegalStateEmpty())?;
let rightBox = rightBox.ok_or(Exceptions::illegalStateEmpty())?;
BoundingBox::new(
leftBox.image,