cargo fmt

This commit is contained in:
Henry Schimke
2022-12-15 13:24:07 -06:00
parent c167442e5b
commit 919826b3ec
14 changed files with 417 additions and 274 deletions

View File

@@ -1,69 +0,0 @@
/*
* Copyright (C) 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.zxing.oned.rss.expanded;
import java.util.ArrayList;
import java.util.List;
/**
* One row of an RSS Expanded Stacked symbol, consisting of 1+ expanded pairs.
*/
final class ExpandedRow {
private final List<ExpandedPair> pairs;
private final int rowNumber;
ExpandedRow(List<ExpandedPair> pairs, int rowNumber) {
this.pairs = new ArrayList<>(pairs);
this.rowNumber = rowNumber;
}
List<ExpandedPair> getPairs() {
return this.pairs;
}
int getRowNumber() {
return this.rowNumber;
}
boolean isEquivalent(List<ExpandedPair> otherPairs) {
return this.pairs.equals(otherPairs);
}
@Override
public String toString() {
return "{ " + pairs + " }";
}
/**
* Two rows are equal if they contain the same pairs in the same order.
*/
@Override
public boolean equals(Object o) {
if (!(o instanceof ExpandedRow)) {
return false;
}
ExpandedRow that = (ExpandedRow) o;
return this.pairs.equals(that.pairs);
}
@Override
public int hashCode() {
return pairs.hashCode();
}
}

View File

@@ -24,7 +24,10 @@
* http://www.piramidepse.com/ * http://www.piramidepse.com/
*/ */
use crate::oned::rss::expanded::{binary_util, decoders::{AbstractExpandedDecoder, abstract_expanded_decoder::createDecoder}}; use crate::oned::rss::expanded::{
binary_util,
decoders::{abstract_expanded_decoder::createDecoder, AbstractExpandedDecoder},
};
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)

View File

@@ -26,7 +26,10 @@
use crate::{common::BitArray, Exceptions}; use crate::{common::BitArray, Exceptions};
use super::{GeneralAppIdDecoder, AnyAIDecoder, AI01AndOtherAIs, AI013103decoder, AI01320xDecoder, AI01392xDecoder, AI01393xDecoder, AI013x0x1xDecoder}; use super::{
AI013103decoder, AI01320xDecoder, AI01392xDecoder, AI01393xDecoder, AI013x0x1xDecoder,
AI01AndOtherAIs, AnyAIDecoder, GeneralAppIdDecoder,
};
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
@@ -55,9 +58,11 @@ pub trait AbstractExpandedDecoder {
// fn new(information:&BitArray) -> Self where Self:Sized; // fn new(information:&BitArray) -> Self where Self:Sized;
} }
pub fn createDecoder<'a>( information:&'a BitArray) -> Result<Box<dyn AbstractExpandedDecoder + 'a>,Exceptions>{ pub fn createDecoder<'a>(
information: &'a BitArray,
) -> Result<Box<dyn AbstractExpandedDecoder + 'a>, Exceptions> {
if information.get(1) { if information.get(1) {
return Ok(Box::new(AI01AndOtherAIs::new(information))) return Ok(Box::new(AI01AndOtherAIs::new(information)));
} }
if !information.get(2) { if !information.get(2) {
return Ok(Box::new(AnyAIDecoder::new(information))); return Ok(Box::new(AnyAIDecoder::new(information)));
@@ -65,33 +70,87 @@ pub fn createDecoder<'a>( information:&'a BitArray) -> Result<Box<dyn AbstractEx
// let gen_decode = GeneralAppIdDecoder::new(information); // let gen_decode = GeneralAppIdDecoder::new(information);
let fourBitEncodationMethod = GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 4); let fourBitEncodationMethod =
GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 4);
match fourBitEncodationMethod { match fourBitEncodationMethod {
4 => return Ok(Box::new(AI013103decoder::new(information))), 4 => return Ok(Box::new(AI013103decoder::new(information))),
5 => return Ok(Box::new(AI01320xDecoder::new(information))), 5 => return Ok(Box::new(AI01320xDecoder::new(information))),
_=>{}, _ => {}
} }
let fiveBitEncodationMethod = GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 5); let fiveBitEncodationMethod =
GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 5);
match fiveBitEncodationMethod { match fiveBitEncodationMethod {
12 => return Ok(Box::new(AI01392xDecoder::new(information))), 12 => return Ok(Box::new(AI01392xDecoder::new(information))),
13 => return Ok(Box::new(AI01393xDecoder::new(information))), 13 => return Ok(Box::new(AI01393xDecoder::new(information))),
_=>{}, _ => {}
} }
let sevenBitEncodationMethod = GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 7); let sevenBitEncodationMethod =
GeneralAppIdDecoder::extractNumericValueFromBitArrayWithInformation(information, 1, 7);
match sevenBitEncodationMethod { match sevenBitEncodationMethod {
56=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "11".to_owned()))), 56 => {
57=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "11".to_owned()))), return Ok(Box::new(AI013x0x1xDecoder::new(
58=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "13".to_owned()))), information,
59=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "13".to_owned()))), "310".to_owned(),
60=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "15".to_owned()))), "11".to_owned(),
61=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "15".to_owned()))), )))
62=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "310".to_owned(), "17".to_owned()))), }
63=> return Ok(Box::new( AI013x0x1xDecoder::new(information, "320".to_owned(), "17".to_owned()))), 57 => {
_=>{}, return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"320".to_owned(),
"11".to_owned(),
)))
}
58 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"310".to_owned(),
"13".to_owned(),
)))
}
59 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"320".to_owned(),
"13".to_owned(),
)))
}
60 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"310".to_owned(),
"15".to_owned(),
)))
}
61 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"320".to_owned(),
"15".to_owned(),
)))
}
62 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"310".to_owned(),
"17".to_owned(),
)))
}
63 => {
return Ok(Box::new(AI013x0x1xDecoder::new(
information,
"320".to_owned(),
"17".to_owned(),
)))
}
_ => {}
} }
Err(Exceptions::IllegalStateException(format!("unknown decoder: {}" , information))) Err(Exceptions::IllegalStateException(format!(
"unknown decoder: {}",
information
)))
} }

View File

@@ -55,7 +55,11 @@ impl AI01decoder for AI013103decoder<'_> {}
impl<'a> AI013103decoder<'_> { impl<'a> AI013103decoder<'_> {
pub fn new(information: &'a BitArray) -> AI013103decoder<'a> { pub fn new(information: &'a BitArray) -> AI013103decoder<'a> {
AI013103decoder(AI013x0xDecoder::new(information, addWeightCode, checkWeight)) AI013103decoder(AI013x0xDecoder::new(
information,
addWeightCode,
checkWeight,
))
} }
} }
@@ -67,7 +71,6 @@ fn checkWeight( weight: u32) -> u32 {
weight weight
} }
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/ */
@@ -75,19 +78,24 @@ fn checkWeight( weight: u32) -> u32 {
mod AI013103DecoderTest { mod AI013103DecoderTest {
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*; use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
const header: &str = "..X.."; const header: &str = "..X..";
#[test] #[test]
fn test0131031() { fn test0131031() {
let data = format!("{}{}{}", header , compressedGtin900123456798908 , compressed15bitWeight1750); let data = format!(
"{}{}{}",
header, compressedGtin900123456798908, compressed15bitWeight1750
);
let expected = "(01)90012345678908(3103)001750"; let expected = "(01)90012345678908(3103)001750";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
} }
#[test] #[test]
fn test0131032() { fn test0131032() {
let data = format!("{}{}{}",header , compressedGtin900000000000008 , compressed15bitWeight0); let data = format!(
"{}{}{}",
header, compressedGtin900000000000008, compressed15bitWeight0
);
let expected = "(01)90000000000003(3103)000000"; let expected = "(01)90000000000003(3103)000000";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
} }
@@ -95,8 +103,10 @@ mod AI013103DecoderTest {
#[test] #[test]
#[should_panic] #[should_panic]
fn test013103invalid() { fn test013103invalid() {
let data = format!("{}{}{}..",header , compressedGtin900123456798908 , compressed15bitWeight1750 ); let data = format!(
"{}{}{}..",
header, compressedGtin900123456798908, compressed15bitWeight1750
);
assertCorrectBinaryString(&data, ""); assertCorrectBinaryString(&data, "");
} }
} }

View File

@@ -26,17 +26,18 @@
use super::abstract_decoder_test_utils::*; use super::abstract_decoder_test_utils::*;
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/ */
const header: &str = "..X.X"; const header: &str = "..X.X";
#[test] #[test]
fn test0132021() { fn test0132021() {
let data = format!("{}{}{}",header, compressedGtin900123456798908 , compressed15bitWeight1750); let data = format!(
"{}{}{}",
header, compressedGtin900123456798908, compressed15bitWeight1750
);
let expected = "(01)90012345678908(3202)001750"; let expected = "(01)90012345678908(3202)001750";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -44,11 +45,11 @@ use super::abstract_decoder_test_utils::*;
#[test] #[test]
fn test0132031() { fn test0132031() {
let data = format!("{}{}{}",header , compressedGtin900123456798908 , compressed15bitWeight11750); let data = format!(
"{}{}{}",
header, compressedGtin900123456798908, compressed15bitWeight11750
);
let expected = "(01)90012345678908(3203)001750"; let expected = "(01)90012345678908(3203)001750";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
} }

View File

@@ -54,7 +54,11 @@ impl AbstractExpandedDecoder for AI01320xDecoder<'_> {
impl AI01decoder for AI01320xDecoder<'_> {} impl AI01decoder for AI01320xDecoder<'_> {}
impl<'a> AI01320xDecoder<'_> { impl<'a> AI01320xDecoder<'_> {
pub fn new(information: &'a BitArray) -> AI01320xDecoder<'a> { pub fn new(information: &'a BitArray) -> AI01320xDecoder<'a> {
AI01320xDecoder(AI013x0xDecoder::new(information, addWeightCode, checkWeight)) AI01320xDecoder(AI013x0xDecoder::new(
information,
addWeightCode,
checkWeight,
))
} }
} }

View File

@@ -132,7 +132,6 @@ impl<'a> AI013x0x1xDecoder<'_> {
} }
} }
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/ */
@@ -140,7 +139,6 @@ impl<'a> AI013x0x1xDecoder<'_> {
mod AI013X0X1XDecoderTest { mod AI013X0X1XDecoderTest {
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*; use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
const header310x11: &str = "..XXX..."; const header310x11: &str = "..XXX...";
const header320x11: &str = "..XXX..X"; const header320x11: &str = "..XXX..X";
const header310x13: &str = "..XXX.X."; const header310x13: &str = "..XXX.X.";
@@ -152,7 +150,13 @@ mod AI013X0X1XDecoderTest {
#[test] #[test]
fn test01310X1XendDate() { fn test01310X1XendDate() {
let data = format!("{}{}{}{}", header310x11 , compressedGtin900123456798908 , compressed20bitWeight1750 , compressedDateEnd); let data = format!(
"{}{}{}{}",
header310x11,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateEnd
);
let expected = "(01)90012345678908(3100)001750"; let expected = "(01)90012345678908(3100)001750";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -160,8 +164,13 @@ mod AI013X0X1XDecoderTest {
#[test] #[test]
fn test01310X111() { fn test01310X111() {
let data = format!("{}{}{}{}", header310x11 , compressedGtin900123456798908 , compressed20bitWeight1750 , let data = format!(
compressedDateMarch12th2010); "{}{}{}{}",
header310x11,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3100)001750(11)100312"; let expected = "(01)90012345678908(3100)001750(11)100312";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -169,8 +178,13 @@ mod AI013X0X1XDecoderTest {
#[test] #[test]
fn test01320X111() { fn test01320X111() {
let data = format!("{}{}{}{}",header320x11 , compressedGtin900123456798908 , compressed20bitWeight1750 , let data = format!(
compressedDateMarch12th2010); "{}{}{}{}",
header320x11,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3200)001750(11)100312"; let expected = "(01)90012345678908(3200)001750(11)100312";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -178,8 +192,13 @@ mod AI013X0X1XDecoderTest {
#[test] #[test]
fn test01310X131() { fn test01310X131() {
let data = format!("{}{}{}{}", header310x13 , compressedGtin900123456798908 , compressed20bitWeight1750 , let data = format!(
compressedDateMarch12th2010); "{}{}{}{}",
header310x13,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3100)001750(13)100312"; let expected = "(01)90012345678908(3100)001750(13)100312";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -187,8 +206,13 @@ mod AI013X0X1XDecoderTest {
#[test] #[test]
fn test01320X131() { fn test01320X131() {
let data = format!("{}{}{}{}", header320x13 , compressedGtin900123456798908 , compressed20bitWeight1750 , let data = format!(
compressedDateMarch12th2010); "{}{}{}{}",
header320x13,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3200)001750(13)100312"; let expected = "(01)90012345678908(3200)001750(13)100312";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -196,8 +220,13 @@ mod AI013X0X1XDecoderTest {
#[test] #[test]
fn test01310X151() { fn test01310X151() {
let data = format!("{}{}{}{}", header310x15 , compressedGtin900123456798908 , compressed20bitWeight1750 , let data = format!(
compressedDateMarch12th2010); "{}{}{}{}",
header310x15,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3100)001750(15)100312"; let expected = "(01)90012345678908(3100)001750(15)100312";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -205,8 +234,13 @@ mod AI013X0X1XDecoderTest {
#[test] #[test]
fn test01320X151() { fn test01320X151() {
let data = format!("{}{}{}{}", header320x15 , compressedGtin900123456798908 , compressed20bitWeight1750 , let data = format!(
compressedDateMarch12th2010); "{}{}{}{}",
header320x15,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3200)001750(15)100312"; let expected = "(01)90012345678908(3200)001750(15)100312";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -214,8 +248,13 @@ mod AI013X0X1XDecoderTest {
#[test] #[test]
fn test01310X171() { fn test01310X171() {
let data = format!("{}{}{}{}", header310x17 , compressedGtin900123456798908 , compressed20bitWeight1750 , let data = format!(
compressedDateMarch12th2010); "{}{}{}{}",
header310x17,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3100)001750(17)100312"; let expected = "(01)90012345678908(3100)001750(17)100312";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -223,12 +262,15 @@ mod AI013X0X1XDecoderTest {
#[test] #[test]
fn test01320X171() { fn test01320X171() {
let data = format!("{}{}{}{}", header320x17 , compressedGtin900123456798908 , compressed20bitWeight1750 , let data = format!(
compressedDateMarch12th2010); "{}{}{}{}",
header320x17,
compressedGtin900123456798908,
compressed20bitWeight1750,
compressedDateMarch12th2010
);
let expected = "(01)90012345678908(3200)001750(17)100312"; let expected = "(01)90012345678908(3200)001750(17)100312";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
} }
} }

View File

@@ -78,8 +78,11 @@ impl<'a> AI013x0xDecoder<'_> {
const HEADER_SIZE: usize = 4 + 1; const HEADER_SIZE: usize = 4 + 1;
const WEIGHT_SIZE: usize = 15; const WEIGHT_SIZE: usize = 15;
pub fn new(information: &'a BitArray, addWeightCodeFunction: fn(&mut String, u32), pub fn new(
checkWeightFunction: fn(u32) -> u32,) -> AI013x0xDecoder<'a> { information: &'a BitArray,
addWeightCodeFunction: fn(&mut String, u32),
checkWeightFunction: fn(u32) -> u32,
) -> AI013x0xDecoder<'a> {
AI013x0xDecoder { AI013x0xDecoder {
information, information,
decoder: GeneralAppIdDecoder::new(information), decoder: GeneralAppIdDecoder::new(information),

View File

@@ -58,7 +58,6 @@ impl<'a> AnyAIDecoder<'_> {
} }
} }
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
*/ */
@@ -66,12 +65,14 @@ impl<'a> AnyAIDecoder<'_> {
mod AnyAIDecoderTest { mod AnyAIDecoderTest {
use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*; use crate::oned::rss::expanded::decoders::abstract_decoder_test_utils::*;
const HEADER: &str = "....."; const HEADER: &str = ".....";
#[test] #[test]
fn testAnyAIDecoder1() { fn testAnyAIDecoder1() {
let data =format!("{}{}{}{}{}{}{}", HEADER , numeric10 , numeric12 , numeric2alpha , alphaA , alpha2numeric , numeric12); let data = format!(
"{}{}{}{}{}{}{}",
HEADER, numeric10, numeric12, numeric2alpha, alphaA, alpha2numeric, numeric12
);
let expected = "(10)12A12"; let expected = "(10)12A12";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -79,7 +80,10 @@ mod AnyAIDecoderTest {
#[test] #[test]
fn testAnyAIDecoder2() { fn testAnyAIDecoder2() {
let data =format!("{}{}{}{}{}{}{}", HEADER , numeric10 , numeric12 , numeric2alpha , alphaA , alpha2isoiec646 , i646B); let data = format!(
"{}{}{}{}{}{}{}",
HEADER, numeric10, numeric12, numeric2alpha, alphaA, alpha2isoiec646, i646B
);
let expected = "(10)12AB"; let expected = "(10)12AB";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -87,8 +91,19 @@ mod AnyAIDecoderTest {
#[test] #[test]
fn testAnyAIDecoder3() { fn testAnyAIDecoder3() {
let data = format!("{}{}{}{}{}{}{}{}{}{}",HEADER , numeric10 , numeric2alpha , alpha2isoiec646 , i646B , i646C , isoiec6462alpha , let data = format!(
alphaA , alpha2numeric , numeric10); "{}{}{}{}{}{}{}{}{}{}",
HEADER,
numeric10,
numeric2alpha,
alpha2isoiec646,
i646B,
i646C,
isoiec6462alpha,
alphaA,
alpha2numeric,
numeric10
);
let expected = "(10)BCA10"; let expected = "(10)BCA10";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -104,7 +119,10 @@ mod AnyAIDecoderTest {
#[test] #[test]
fn testAnyAIDecoderalphaFNC1() { fn testAnyAIDecoderalphaFNC1() {
let data = format!("{}{}{}{}{}", HEADER, numeric10 , numeric2alpha , alphaA , alphaFNC1); let data = format!(
"{}{}{}{}{}",
HEADER, numeric10, numeric2alpha, alphaA, alphaFNC1
);
let expected = "(10)A"; let expected = "(10)A";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
@@ -112,10 +130,12 @@ mod AnyAIDecoderTest {
#[test] #[test]
fn testAnyAIDecoder646FNC1() { fn testAnyAIDecoder646FNC1() {
let data = format!("{}{}{}{}{}{}{}",HEADER , numeric10 , numeric2alpha , alphaA , isoiec6462alpha , i646B , i646FNC1); let data = format!(
"{}{}{}{}{}{}{}",
HEADER, numeric10, numeric2alpha, alphaA, isoiec6462alpha, i646B, i646FNC1
);
let expected = "(10)AB"; let expected = "(10)AB";
assertCorrectBinaryString(&data, expected); assertCorrectBinaryString(&data, expected);
} }
} }

View File

@@ -197,8 +197,11 @@ impl<'a> GeneralAppIdDecoder<'_> {
} }
} //while (!isFinished); } //while (!isFinished);
if result.getDecodedInformation().is_some(){ Ok(result.getDecodedInformation().as_ref().unwrap().clone())} if result.getDecodedInformation().is_some() {
else {Err(Exceptions::NotFoundException("".to_owned()))} Ok(result.getDecodedInformation().as_ref().unwrap().clone())
} else {
Err(Exceptions::NotFoundException("".to_owned()))
}
} }
fn parseNumericBlock(&mut self) -> Result<BlockParsedRXingResult, Exceptions> { fn parseNumericBlock(&mut self) -> Result<BlockParsedRXingResult, Exceptions> {

View File

@@ -24,8 +24,7 @@
* http://www.piramidepse.com/ * http://www.piramidepse.com/
*/ */
use crate::oned::rss::expanded::{binary_util, decoders::{ abstract_expanded_decoder}}; use crate::oned::rss::expanded::{binary_util, decoders::abstract_expanded_decoder};
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
@@ -33,10 +32,11 @@ use crate::oned::rss::expanded::{binary_util, decoders::{ abstract_expanded_deco
*/ */
#[test] #[test]
fn testNoAi() { fn testNoAi() {
let information = binary_util::buildBitArrayFromString(" .......X ..XX..X. X.X....X .......X ....").expect("build"); let information =
binary_util::buildBitArrayFromString(" .......X ..XX..X. X.X....X .......X ....")
.expect("build");
let mut decoder = abstract_expanded_decoder::createDecoder(&information).expect("create"); let mut decoder = abstract_expanded_decoder::createDecoder(&information).expect("create");
let decoded = decoder.parseInformation().expect("parsed"); let decoded = decoder.parseInformation().expect("parsed");
assert_eq!("(10)12A", decoded); assert_eq!("(10)12A", decoded);
} }

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2010 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use std::fmt::Display;
use super::ExpandedPair;
/**
* One row of an RSS Expanded Stacked symbol, consisting of 1+ expanded pairs.
*/
#[derive(Hash)]
pub struct ExpandedRow {
pairs: Vec<ExpandedPair>,
rowNumber: u32,
}
impl ExpandedRow {
pub fn new(pairs: Vec<ExpandedPair>, rowNumber: u32) -> Self {
Self { pairs, rowNumber }
}
pub fn getPairs(&self) -> &[ExpandedPair] {
&self.pairs
}
pub fn getRowNumber(&self) -> u32 {
self.rowNumber
}
pub fn isEquivalent(&self, otherPairs: &[ExpandedPair]) -> bool {
self.pairs == otherPairs
}
}
impl PartialEq for ExpandedRow {
/**
* Two rows are equal if they contain the same pairs in the same order.
*/
fn eq(&self, other: &Self) -> bool {
self.pairs == other.pairs
}
}
impl Display for ExpandedRow {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{{ ")?;
for p in &self.pairs {
write!(f, "{}", p)?;
}
write!(f, " }}") //{:?} }} " , self.pairs )
}
}

View File

@@ -8,3 +8,6 @@ pub use expanded_pair::*;
#[cfg(test)] #[cfg(test)]
mod expanded_information_decoder_test; mod expanded_information_decoder_test;
mod expanded_row;
pub use expanded_row::*;