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

@@ -65,7 +65,7 @@ impl C40Encoder {
context.updateSymbolInfoWithLength(curCodewordCount);
let available = context
.getSymbolInfo()
.ok_or(Exceptions::IllegalStateException(None))?
.ok_or(Exceptions::illegalStateEmpty())?
.getDataCapacity() as usize
- curCodewordCount;
@@ -140,7 +140,7 @@ impl C40Encoder {
context.updateSymbolInfoWithLength(curCodewordCount);
let available = context
.getSymbolInfo()
.ok_or(Exceptions::IllegalStateException(None))?
.ok_or(Exceptions::illegalStateEmpty())?
.getDataCapacity() as usize
- curCodewordCount;
let rest = buffer.chars().count() % 3;
@@ -182,9 +182,7 @@ impl C40Encoder {
context: &mut EncoderContext,
buffer: &mut String,
) -> Result<(), Exceptions> {
context.writeCodewords(
&Self::encodeToCodewords(buffer).ok_or(Exceptions::FormatException(None))?,
);
context.writeCodewords(&Self::encodeToCodewords(buffer).ok_or(Exceptions::formatEmpty())?);
buffer.replace_range(0..3, "");
// buffer.delete(0, 3);
Ok(())
@@ -207,7 +205,7 @@ impl C40Encoder {
context.updateSymbolInfoWithLength(curCodewordCount);
let available = context
.getSymbolInfo()
.ok_or(Exceptions::IllegalStateException(None))?
.ok_or(Exceptions::illegalStateEmpty())?
.getDataCapacity() as usize
- curCodewordCount;
@@ -236,9 +234,9 @@ impl C40Encoder {
context.writeCodeword(C40_UNLATCH);
}
} else {
return Err(Exceptions::IllegalStateException(Some(
return Err(Exceptions::illegalState(
"Unexpected case. Please report!".to_owned(),
)));
));
}
context.signalEncoderChange(ASCII_ENCODATION);