package com.boying.util; import com.baomidou.mybatisplus.core.toolkit.BeanUtils; import com.boying.entity.EnterPark; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * @author kdq * @version 1.0.0 * @ClassName PlateComparator.java * @Description TODO * @createTime 2024年04月19日 15:57:00 */ public class PlateComparator { public static List> getList(String carNo, List enterParkList) { List> list = new ArrayList<>(); for (EnterPark enterPark : enterParkList) { int i = compareLicensePlates(carNo, enterPark.getCarNo()); if (i<=2){ Map map = BeanUtils.beanToMap(enterPark); map.put("count",i); // 新增次数 list.add(map); } } return list; } public static int compareLicensePlates(String oldLicensePlate, String newLicensePlate) { int length = Math.min(oldLicensePlate.length(), newLicensePlate.length()); int count = 0; for (int i = 0; i < length; i++) { if (oldLicensePlate.charAt(i) != newLicensePlate.charAt(i)) { count ++; } } // 如果新车牌比旧车牌长,则追加新车牌多出的字符 if (newLicensePlate.length() > oldLicensePlate.length()) { count++; } return count; } }