Merge branch 'main' into pr/point_refactor

This commit is contained in:
Vukašin Stepanović
2023-02-16 16:43:24 +00:00
132 changed files with 1048 additions and 1329 deletions

View File

@@ -39,7 +39,7 @@ pub trait AbstractRSSReaderTrait: OneDReader {
return Ok(value as u32);
}
}
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFound)
}
/**

View File

@@ -53,23 +53,13 @@ pub fn buildBitArrayFromString(data: &str) -> Result<BitArray> {
// for (int i = 0; i < dotsAndXs.length(); ++i) {
if i % 9 == 0 {
// spaces
if dotsAndXs
.chars()
.nth(i)
.ok_or(Exceptions::ParseException(None))?
!= ' '
{
return Err(Exceptions::IllegalStateException(Some(
"space expected".to_owned(),
)));
if dotsAndXs.chars().nth(i).ok_or(Exceptions::parse)? != ' ' {
return Err(Exceptions::illegalStateWith("space expected"));
}
continue;
}
let currentChar = dotsAndXs
.chars()
.nth(i)
.ok_or(Exceptions::ParseException(None))?;
let currentChar = dotsAndXs.chars().nth(i).ok_or(Exceptions::parse)?;
if currentChar == 'X' || currentChar == 'x' {
binary.set(counter);
}
@@ -91,12 +81,7 @@ pub fn buildBitArrayFromStringWithoutSpaces(data: &str) -> Result<BitArray> {
sb.push(' ');
let mut i = 0;
while i < 8 && current < dotsAndXs_length {
sb.push(
dotsAndXs
.chars()
.nth(current)
.ok_or(Exceptions::ParseException(None))?,
);
sb.push(dotsAndXs.chars().nth(current).ok_or(Exceptions::parse)?);
current += 1;
i += 1;

View File

@@ -152,7 +152,7 @@ pub fn createDecoder<'a>(
_ => {}
}
Err(Exceptions::IllegalStateException(Some(format!(
Err(Exceptions::illegalStateWith(format!(
"unknown decoder: {information}"
))))
)))
}

View File

@@ -39,7 +39,7 @@ impl AI01decoder for AI01392xDecoder<'_> {}
impl AbstractExpandedDecoder for AI01392xDecoder<'_> {
fn parseInformation(&mut self) -> Result<String> {
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
return Err(crate::Exceptions::NotFoundException(None));
return Err(crate::Exceptions::notFound);
}
let mut buf = String::new();

View File

@@ -39,7 +39,7 @@ impl AI01decoder for AI01393xDecoder<'_> {}
impl AbstractExpandedDecoder for AI01393xDecoder<'_> {
fn parseInformation(&mut self) -> Result<String> {
if self.information.getSize() < Self::HEADER_SIZE + Self::GTIN_SIZE as usize {
return Err(crate::Exceptions::NotFoundException(None));
return Err(crate::Exceptions::notFound);
}
let mut buf = String::new();

View File

@@ -57,7 +57,7 @@ impl AbstractExpandedDecoder for AI013x0x1xDecoder<'_> {
if self.information.getSize()
!= Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::WEIGHT_SIZE + Self::DATE_SIZE
{
return Err(crate::Exceptions::NotFoundException(None));
return Err(crate::Exceptions::notFound);
}
let mut buf = String::new();

View File

@@ -53,7 +53,7 @@ impl AbstractExpandedDecoder for AI013x0xDecoder<'_> {
if self.information.getSize()
!= Self::HEADER_SIZE + Self::GTIN_SIZE as usize + Self::WEIGHT_SIZE
{
return Err(crate::Exceptions::NotFoundException(None));
return Err(crate::Exceptions::notFound);
}
let mut buf = String::new();

View File

@@ -52,7 +52,7 @@ impl DecodedNumeric {
if
/*firstDigit < 0 ||*/
firstDigit > 10 || /*secondDigit < 0 ||*/ secondDigit > 10 {
return Err(Exceptions::FormatException(None));
return Err(Exceptions::format);
}
Ok(Self {

View File

@@ -146,7 +146,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String> {
// Processing 2-digit AIs
if rawInformation.chars().count() < 2 {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
let lookup: String = rawInformation.chars().take(2).collect();
@@ -159,7 +159,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String> {
}
if rawInformation.chars().count() < 3 {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
let firstThreeDigits: String = rawInformation.chars().take(3).collect();
@@ -172,7 +172,7 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String> {
}
if rawInformation.chars().count() < 4 {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
let threeDigitPlusDigitDataLength = THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.get(&firstThreeDigits);
@@ -192,18 +192,18 @@ pub fn parseFieldsInGeneralPurpose(rawInformation: &str) -> Result<String> {
return processFixedAI(4, ffdl.length, rawInformation);
}
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFound)
}
fn processFixedAI(aiSize: usize, fieldSize: usize, rawInformation: &str) -> Result<String> {
if rawInformation.chars().count() < aiSize {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
let ai: String = rawInformation.chars().take(aiSize).collect();
if rawInformation.chars().count() < aiSize + fieldSize {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
let field: String = rawInformation

View File

@@ -198,7 +198,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
if let Some(r) = result.getDecodedInformation() {
Ok(r.clone())
} else {
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFound)
}
}
@@ -344,8 +344,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
if (5..15).contains(&fiveBitValue) {
return Ok(DecodedChar::new(
pos + 5,
char::from_u32('0' as u32 + fiveBitValue - 5)
.ok_or(Exceptions::ParseException(None))?,
char::from_u32('0' as u32 + fiveBitValue - 5).ok_or(Exceptions::parse)?,
));
}
@@ -354,14 +353,14 @@ impl<'a> GeneralAppIdDecoder<'_> {
if (64..90).contains(&sevenBitValue) {
return Ok(DecodedChar::new(
pos + 7,
char::from_u32(sevenBitValue + 1).ok_or(Exceptions::ParseException(None))?,
char::from_u32(sevenBitValue + 1).ok_or(Exceptions::parse)?,
));
}
if (90..116).contains(&sevenBitValue) {
return Ok(DecodedChar::new(
pos + 7,
char::from_u32(sevenBitValue + 7).ok_or(Exceptions::ParseException(None))?,
char::from_u32(sevenBitValue + 7).ok_or(Exceptions::parse)?,
));
}
@@ -388,7 +387,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
250 => '?',
251 => '_',
252 => ' ',
_ => return Err(Exceptions::FormatException(None)),
_ => return Err(Exceptions::format),
};
Ok(DecodedChar::new(pos + 8, c))
@@ -423,8 +422,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
if (5..15).contains(&fiveBitValue) {
return Ok(DecodedChar::new(
pos + 5,
char::from_u32('0' as u32 + fiveBitValue - 5)
.ok_or(Exceptions::ParseException(None))?,
char::from_u32('0' as u32 + fiveBitValue - 5).ok_or(Exceptions::parse)?,
));
}
@@ -433,7 +431,7 @@ impl<'a> GeneralAppIdDecoder<'_> {
if (32..58).contains(&sixBitValue) {
return Ok(DecodedChar::new(
pos + 6,
char::from_u32(sixBitValue + 33).ok_or(Exceptions::ParseException(None))?,
char::from_u32(sixBitValue + 33).ok_or(Exceptions::parse)?,
));
}
@@ -444,9 +442,9 @@ impl<'a> GeneralAppIdDecoder<'_> {
61 => '.',
62 => '/',
_ => {
return Err(Exceptions::IllegalStateException(Some(format!(
return Err(Exceptions::illegalStateWith(format!(
"Decoding invalid alphanumeric value: {sixBitValue}"
))))
)))
}
};

View File

@@ -224,7 +224,7 @@ impl Reader for RSSExpandedReader {
Ok(result)
} else {
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFound)
}
}
}
@@ -294,9 +294,7 @@ impl RSSExpandedReader {
if let Ok(to_add) = to_add_res {
self.pairs.push(to_add);
} else if self.pairs.is_empty() {
return Err(to_add_res
.err()
.unwrap_or(Exceptions::IllegalStateException(None)));
return Err(to_add_res.err().unwrap_or(Exceptions::illegalState));
} else {
// exit this loop when retrieveNextPair() fails and throws
done = true;
@@ -328,7 +326,7 @@ impl RSSExpandedReader {
// }
}
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFound)
}
fn checkRows(&mut self, reverse: bool) -> Option<Vec<ExpandedPair>> {
@@ -372,10 +370,7 @@ impl RSSExpandedReader {
) -> Result<Vec<ExpandedPair>> {
for i in currentRow..self.rows.len() {
// for (int i = currentRow; i < rows.size(); i++) {
let row = self
.rows
.get(i)
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
let row = self.rows.get(i).ok_or(Exceptions::indexOutOfBounds)?;
self.pairs.clear();
for collectedRow in &collectedRows.clone() {
// for (ExpandedRow collectedRow : collectedRows) {
@@ -403,7 +398,7 @@ impl RSSExpandedReader {
}
}
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFound)
}
/// Whether the pairs form a valid find pattern sequence,
@@ -541,17 +536,17 @@ impl RSSExpandedReader {
let firstPoints = pairs
.get(0)
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
.ok_or(Exceptions::indexOutOfBounds)?
.getFinderPattern()
.as_ref()
.ok_or(Exceptions::IllegalStateException(None))?
.ok_or(Exceptions::illegalState)?
.getPoints();
let lastPoints = pairs
.last()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
.ok_or(Exceptions::indexOutOfBounds)?
.getFinderPattern()
.as_ref()
.ok_or(Exceptions::IllegalStateException(None))?
.ok_or(Exceptions::illegalState)?
.getPoints();
let mut result = RXingResult::new(
@@ -650,9 +645,7 @@ impl RSSExpandedReader {
let leftChar = self.decodeDataCharacter(
row,
pattern
.as_ref()
.ok_or(Exceptions::NotFoundException(None))?,
pattern.as_ref().ok_or(Exceptions::notFound)?,
isOddPattern,
true,
)?;
@@ -660,18 +653,16 @@ impl RSSExpandedReader {
if !previousPairs.is_empty()
&& previousPairs
.last()
.ok_or(Exceptions::NotFoundException(None))?
.ok_or(Exceptions::notFound)?
.mustBeLast()
{
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
let rightChar = self
.decodeDataCharacter(
row,
pattern
.as_ref()
.ok_or(Exceptions::NotFoundException(None))?,
pattern.as_ref().ok_or(Exceptions::notFound)?,
isOddPattern,
false,
)
@@ -701,13 +692,11 @@ impl RSSExpandedReader {
} else if previousPairs.is_empty() {
rowOffset = 0;
} else {
let lastPair = previousPairs
.last()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?;
let lastPair = previousPairs.last().ok_or(Exceptions::indexOutOfBounds)?;
rowOffset = lastPair
.getFinderPattern()
.as_ref()
.ok_or(Exceptions::IllegalStateException(None))?
.ok_or(Exceptions::illegalState)?
.getStartEnd()[1] as i32;
}
let mut searchingEvenPair = previousPairs.len() % 2 != 0;
@@ -759,7 +748,7 @@ impl RSSExpandedReader {
isWhite = !isWhite;
}
}
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFound)
}
fn reverseCounters(counters: &mut [u32]) {
@@ -856,7 +845,7 @@ impl RSSExpandedReader {
let expectedElementWidth: f32 =
(pattern.getStartEnd()[1] - pattern.getStartEnd()[0]) as f32 / 15.0;
if (elementWidth - expectedElementWidth).abs() / expectedElementWidth > 0.3 {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
for (i, counter) in counters.iter().enumerate() {
@@ -865,12 +854,12 @@ impl RSSExpandedReader {
let mut count = (value + 0.5) as i32; // Round
if count < 1 {
if value < 0.3 {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
count = 1;
} else if count > 8 {
if value > 8.7 {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
count = 8;
}
@@ -910,7 +899,7 @@ impl RSSExpandedReader {
let checksumPortion = oddChecksumPortion + evenChecksumPortion;
if (oddSum & 0x01) != 0 || !(4..=13).contains(&oddSum) {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
let group = ((13 - oddSum) / 2) as usize;
@@ -958,12 +947,12 @@ impl RSSExpandedReader {
1 => {
if oddParityBad {
if evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
decrementOdd = true;
} else {
if !evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
decrementEven = true;
}
@@ -971,12 +960,12 @@ impl RSSExpandedReader {
-1 => {
if oddParityBad {
if evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
incrementOdd = true;
} else {
if !evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
incrementEven = true;
}
@@ -984,7 +973,7 @@ impl RSSExpandedReader {
0 => {
if oddParityBad {
if !evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
// Both bad
if oddSum < evenSum {
@@ -995,16 +984,16 @@ impl RSSExpandedReader {
incrementEven = true;
}
} else if evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
}
_ => return Err(Exceptions::NotFoundException(None)),
_ => return Err(Exceptions::notFound),
}
if incrementOdd {
if decrementOdd {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
Self::increment(&mut self.oddCounts, &self.oddRoundingErrors);
}
@@ -1013,7 +1002,7 @@ impl RSSExpandedReader {
}
if incrementEven {
if decrementEven {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
Self::increment(&mut self.evenCounts, &self.oddRoundingErrors);
}

View File

@@ -64,12 +64,12 @@ impl OneDReader for RSS14Reader {
if right.getCount() > 1 && self.checkChecksum(left, right) {
return self
.constructRXingResult(left, right)
.ok_or(Exceptions::IllegalStateException(None));
.ok_or(Exceptions::illegalState);
}
}
}
}
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFound)
}
}
impl Reader for RSS14Reader {
@@ -123,7 +123,7 @@ impl Reader for RSS14Reader {
Ok(result)
} else {
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFound)
}
}
}
@@ -340,7 +340,7 @@ impl RSS14Reader {
if outsideChar {
if (oddSum & 0x01) != 0 || !(4..=12).contains(&oddSum) {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
let group = ((12 - oddSum) / 2) as usize;
let oddWidest = Self::OUTSIDE_ODD_WIDEST[group];
@@ -355,7 +355,7 @@ impl RSS14Reader {
))
} else {
if (evenSum & 0x01) != 0 || !(4..=10).contains(&evenSum) {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
let group = ((10 - evenSum) / 2) as usize;
let oddWidest = Self::INSIDE_ODD_WIDEST[group];
@@ -414,7 +414,7 @@ impl RSS14Reader {
isWhite = !isWhite;
}
}
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFound)
}
fn parseFoundFinderPattern(
@@ -511,12 +511,12 @@ impl RSS14Reader {
1 => {
if oddParityBad {
if evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
decrementOdd = true;
} else {
if !evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
decrementEven = true;
}
@@ -524,12 +524,12 @@ impl RSS14Reader {
-1 => {
if oddParityBad {
if evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
incrementOdd = true;
} else {
if !evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
incrementEven = true;
}
@@ -537,7 +537,7 @@ impl RSS14Reader {
0 => {
if oddParityBad {
if !evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
// Both bad
if oddSum < evenSum {
@@ -548,15 +548,15 @@ impl RSS14Reader {
incrementEven = true;
}
} else if evenParityBad {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
}
_ => return Err(Exceptions::NotFoundException(None)),
_ => return Err(Exceptions::notFound),
}
if incrementOdd {
if decrementOdd {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
Self::increment(&mut self.oddCounts, &self.oddRoundingErrors);
}
@@ -565,7 +565,7 @@ impl RSS14Reader {
}
if incrementEven {
if decrementEven {
return Err(Exceptions::NotFoundException(None));
return Err(Exceptions::notFound);
}
Self::increment(&mut self.evenCounts, &self.evenRoundingErrors);
}