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

@@ -168,7 +168,7 @@ impl BitArray {
pub fn setRange(&mut self, start: usize, end: usize) -> Result<(), Exceptions> {
let mut end = end;
if end < start || end > self.size {
return Err(Exceptions::IllegalArgumentException(None));
return Err(Exceptions::illegalArgumentEmpty());
}
if end == start {
return Ok(());
@@ -211,7 +211,7 @@ impl BitArray {
pub fn isRange(&self, start: usize, end: usize, value: bool) -> Result<bool, Exceptions> {
let mut end = end;
if end < start || end > self.size {
return Err(Exceptions::IllegalArgumentException(None));
return Err(Exceptions::illegalArgumentEmpty());
}
if end == start {
return Ok(true); // empty range matches
@@ -253,9 +253,9 @@ impl BitArray {
*/
pub fn appendBits(&mut self, value: u32, num_bits: usize) -> Result<(), Exceptions> {
if num_bits > 32 {
return Err(Exceptions::IllegalArgumentException(Some(
return Err(Exceptions::illegalArgument(
"num bits must be between 0 and 32".to_owned(),
)));
));
}
if num_bits == 0 {
@@ -286,9 +286,7 @@ impl BitArray {
pub fn xor(&mut self, other: &BitArray) -> Result<(), Exceptions> {
if self.size != other.size {
return Err(Exceptions::IllegalArgumentException(Some(
"Sizes don't match".to_owned(),
)));
return Err(Exceptions::illegalArgument("Sizes don't match".to_owned()));
}
for i in 0..self.bits.len() {
//for (int i = 0; i < bits.length; i++) {