mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
cargo fmt
This commit is contained in:
@@ -19,60 +19,59 @@ use std::collections::HashMap;
|
||||
/**
|
||||
* @author Guenther Grau
|
||||
*/
|
||||
pub struct BarcodeValue(HashMap<u32,u32>);
|
||||
// private final Map<Integer,Integer> values = new HashMap<>();
|
||||
pub struct BarcodeValue(HashMap<u32, u32>);
|
||||
// private final Map<Integer,Integer> values = new HashMap<>();
|
||||
|
||||
impl BarcodeValue {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an occurrence of a value
|
||||
*/
|
||||
pub fn setValue(&mut self, value:u32) {
|
||||
let mut confidence = if let Some(value) = self.0.get(&value) {
|
||||
*value
|
||||
}else {
|
||||
0
|
||||
};
|
||||
confidence+=1;
|
||||
self.0.insert(value, confidence);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the maximum occurrence of a set value and returns all values which were set with this occurrence.
|
||||
* @return an array of int, containing the values with the highest occurrence, or null, if no value was set
|
||||
*/
|
||||
pub fn getValue(&self) -> Vec<u32> {
|
||||
let mut maxConfidence = -1_i32;
|
||||
let mut result = Vec::new();
|
||||
for (key,value) in &self.0 {
|
||||
// for (Entry<Integer,Integer> entry : values.entrySet()) {
|
||||
if *value as i32 > maxConfidence {
|
||||
maxConfidence = *value as i32;
|
||||
result.clear();
|
||||
result.push(*key);
|
||||
} else if *value as i32 == maxConfidence {
|
||||
result.push(*key);
|
||||
}
|
||||
impl BarcodeValue {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
/**
|
||||
* Add an occurrence of a value
|
||||
*/
|
||||
pub fn setValue(&mut self, value: u32) {
|
||||
let mut confidence = if let Some(value) = self.0.get(&value) {
|
||||
*value
|
||||
} else {
|
||||
0
|
||||
};
|
||||
confidence += 1;
|
||||
self.0.insert(value, confidence);
|
||||
}
|
||||
|
||||
pub fn getConfidence(&self, value:u32) -> u32{
|
||||
if let Some(v) = self.0.get(&value) {
|
||||
*v
|
||||
}else {
|
||||
0
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determines the maximum occurrence of a set value and returns all values which were set with this occurrence.
|
||||
* @return an array of int, containing the values with the highest occurrence, or null, if no value was set
|
||||
*/
|
||||
pub fn getValue(&self) -> Vec<u32> {
|
||||
let mut maxConfidence = -1_i32;
|
||||
let mut result = Vec::new();
|
||||
for (key, value) in &self.0 {
|
||||
// for (Entry<Integer,Integer> entry : values.entrySet()) {
|
||||
if *value as i32 > maxConfidence {
|
||||
maxConfidence = *value as i32;
|
||||
result.clear();
|
||||
result.push(*key);
|
||||
} else if *value as i32 == maxConfidence {
|
||||
result.push(*key);
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn getConfidence(&self, value: u32) -> u32 {
|
||||
if let Some(v) = self.0.get(&value) {
|
||||
*v
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BarcodeValue {
|
||||
fn default() -> Self {
|
||||
Self(Default::default())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user