match puck barcodes only with alphanum and case ignore
This commit is contained in:
28
src/main/java/ch/psi/mxsc/BarcodeMatcher.java
Normal file
28
src/main/java/ch/psi/mxsc/BarcodeMatcher.java
Normal 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));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user