package com.zy.asrs.utils; import java.util.regex.Pattern; public class CodeDetectionUtil { /** * 检测货架码 */ public static boolean barcodeDetection(String barcode, int code) { Pattern pattern = Pattern.compile("\\d{" + code + "}");//位数字 return pattern.matcher(barcode).matches(); } /** * 检测小车地码 */ public static boolean carCodeDetection(String carCode) { return carCode.contains("_"); } /** * 检测数组最大值及其索引 */ public static int[] crnCodeDetectionMax(int[] arr) { int max = arr[0]; int index = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; index = i; } } return new int[]{index, max}; } /** * 检测数组最大值及其索引 */ public static int[] crnCodeDetectionMaxT(int[] arr,Integer crnNoIndex) { int max = arr[0]; if (crnNoIndex == 0){ max = arr[1]; } int index = 0; for (int i = 0; i < arr.length; i++) { if (crnNoIndex == i){ continue; } if (arr[i] > max) { max = arr[i]; index = i; } } return new int[]{index, max}; } /** * 检测数组最小值及其索引 */ public static int[] crnCodeDetectionMin(int[] arr) { int min = arr[0]; int index = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] < min) { min = arr[i]; index = i; } } return new int[]{index, min}; } // public static void main(String[] args) { // System.out.println("barcodeDetection:" + "22222222===>" + barcodeDetection("22222222", 7)); // System.out.println("barcodeDetection:" + "222222===>" + barcodeDetection("222222", 7)); // System.out.println("barcodeDetection:" + "111===>" + barcodeDetection("111", 7)); // System.out.println("barcodeDetection:" + "DB_123ss===>" + barcodeDetection("DB_123ss", 7)); // System.out.println("barcodeDetection:" + "12_1231===>" + barcodeDetection("12_1231", 7)); // System.out.println("barcodeDetection:" + "DB_123456===>" + barcodeDetection("DB_123456", 7)); // // System.out.println("carCodeDetection:" + "22222222===>" + carCodeDetection("22222222")); // System.out.println("carCodeDetection:" + "222222===>" + carCodeDetection("222222")); // System.out.println("carCodeDetection:" + "111===>" + carCodeDetection("111")); // System.out.println("carCodeDetection:" + "DB_123ss===>" + carCodeDetection("DB_123ss")); // System.out.println("carCodeDetection:" + "12_1231===>" + carCodeDetection("12_1231")); // System.out.println("carCodeDetection:" + "DB_123456===>" + carCodeDetection("DB_123456")); // } }