match puck barcodes only with alphanum and case ignore

This commit is contained in:
2022-04-12 11:48:03 +02:00
parent 263341f9a4
commit 57f2f38e9b
2 changed files with 30 additions and 3 deletions

View File

@@ -0,0 +1,28 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package ch.psi.mxsc;
/**
*
* @author panepucci
*/
public class BarcodeMatcher {
public static boolean matchBarcodes(String one, String two) {
String one_c = one.replaceAll("[^0-9a-zA-Z]", "");
String two_c = two.replaceAll("[^0-9a-zA-Z]", "");
return one_c.equalsIgnoreCase(two_c);
}
public static void main(String[] args) {
String one = "Astx-0023";
String two = "ASTX_0023";
String three = "Astx-0032";
System.out.println("one == two: " + matchBarcodes(one, two));
System.out.println("one == three: " + matchBarcodes(one, three));
System.out.println("two == three: " + matchBarcodes(two, three));
}
}

View File

@@ -188,9 +188,8 @@ public class PuckLoadingDialog extends JDialog {
void makeVisible(String datamatrix){
if (datamatrix!=null){
datamatrix = datamatrix.trim();
for (int i=0; i<model.getRowCount(); i++){
if (datamatrix.equals(model.getValueAt(i, INDEX_DATAMATRIX))){
if (BarcodeMatcher.matchBarcodes(datamatrix, (String)model.getValueAt(i, INDEX_DATAMATRIX))) {
int index = table.convertRowIndexToView(i);
SwingUtils.scrollToVisible(table, index, 0);
table.setRowSelectionInterval(index, index);
@@ -203,7 +202,7 @@ public class PuckLoadingDialog extends JDialog {
void makeVisible(Puck puck){
if (puck!=null){
for (int i=0; i<model.getRowCount(); i++){
if (puck.getName().equals(model.getValueAt(i, INDEX_POSITION))){
if (BarcodeMatcher.matchBarcodes(puck.getName(), (String)model.getValueAt(i, INDEX_POSITION))) {
int index = table.convertRowIndexToView(i);
SwingUtils.scrollToVisible(table, index, 0);
table.setRowSelectionInterval(index, index);