mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
refactor to use exception helper factories
This commit is contained in:
@@ -65,9 +65,9 @@ impl BitMatrix {
|
||||
*/
|
||||
pub fn new(width: u32, height: u32) -> Result<Self, Exceptions> {
|
||||
if width < 1 || height < 1 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"Both dimensions must be greater than 0".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
Ok(Self {
|
||||
width,
|
||||
@@ -137,12 +137,12 @@ impl BitMatrix {
|
||||
if string_representation
|
||||
.chars()
|
||||
.nth(pos)
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
== '\n'
|
||||
|| string_representation
|
||||
.chars()
|
||||
.nth(pos)
|
||||
.ok_or(Exceptions::IllegalStateException(None))?
|
||||
.ok_or(Exceptions::illegalStateEmpty())?
|
||||
== '\r'
|
||||
{
|
||||
if bitsPos > rowStartPos {
|
||||
@@ -151,9 +151,9 @@ impl BitMatrix {
|
||||
first_run = false;
|
||||
rowLength = bitsPos - rowStartPos;
|
||||
} else if bitsPos - rowStartPos != rowLength {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"row lengths do not match".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
rowStartPos = bitsPos;
|
||||
nRows += 1;
|
||||
@@ -168,10 +168,10 @@ impl BitMatrix {
|
||||
bits[bitsPos] = false;
|
||||
bitsPos += 1;
|
||||
} else {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(format!(
|
||||
return Err(Exceptions::illegalArgument(format!(
|
||||
"illegal character encountered: {}",
|
||||
string_representation[pos..].to_owned()
|
||||
))));
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,9 +182,9 @@ impl BitMatrix {
|
||||
// first_run = false;
|
||||
rowLength = bitsPos - rowStartPos;
|
||||
} else if bitsPos - rowStartPos != rowLength {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"row lengths do not match".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
nRows += 1;
|
||||
}
|
||||
@@ -311,9 +311,9 @@ impl BitMatrix {
|
||||
pub fn xor(&mut self, mask: &BitMatrix) -> Result<(), Exceptions> {
|
||||
if self.width != mask.width || self.height != mask.height || self.row_size != mask.row_size
|
||||
{
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"input matrix dimensions do not match".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
// let mut rowArray = BitArray::with_size(self.width as usize);
|
||||
for y in 0..self.height {
|
||||
@@ -363,16 +363,16 @@ impl BitMatrix {
|
||||
// ));
|
||||
// }
|
||||
if height < 1 || width < 1 {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"height and width must be at least 1".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
let right = left + width;
|
||||
let bottom = top + height;
|
||||
if bottom > self.height || right > self.width {
|
||||
return Err(Exceptions::IllegalArgumentException(Some(
|
||||
return Err(Exceptions::illegalArgument(
|
||||
"the region must fit inside the matrix".to_owned(),
|
||||
)));
|
||||
));
|
||||
}
|
||||
for y in top..bottom {
|
||||
//for (int y = top; y < bottom; y++) {
|
||||
@@ -444,9 +444,9 @@ impl BitMatrix {
|
||||
self.rotate180();
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(Exceptions::IllegalArgumentException(Some(
|
||||
_ => Err(Exceptions::illegalArgument(
|
||||
"degrees must be a multiple of 0, 90, 180, or 270".to_owned(),
|
||||
))),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user