| | |
| | | package com.zy.acs.manager.core.domain; |
| | | |
| | | import com.zy.acs.common.utils.GsonUtils; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import lombok.Data; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Created by vincent on 11/5/2024 |
| | |
| | | |
| | | private boolean avoidable; |
| | | |
| | | public BlockVehicleDto() { |
| | | } |
| | | |
| | | public BlockVehicleDto(String vehicle, boolean avoidable) { |
| | | this.vehicle = vehicle; |
| | | this.avoidable = avoidable; |
| | | } |
| | | |
| | | @Override |
| | | public boolean equals(Object o) { |
| | | if (this == o) return true; |
| | | if (o == null || getClass() != o.getClass()) return false; |
| | | BlockVehicleDto that = (BlockVehicleDto) o; |
| | | return Objects.equals(vehicle, that.vehicle); |
| | | } |
| | | |
| | | @Override |
| | | public int hashCode() { |
| | | return Objects.hash(vehicle); |
| | | } |
| | | |
| | | public static boolean customContain(List<BlockVehicleDto> list, String vehicle) { |
| | | if (Cools.isEmpty(list, vehicle)) { |
| | | return false; |
| | | } |
| | | for (BlockVehicleDto dto : list) { |
| | | if (dto.getVehicle().equals(vehicle)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | List<BlockVehicleDto> blockVehicleList = new ArrayList<>(); |
| | | blockVehicleList.add(new BlockVehicleDto("1", true)); |
| | | blockVehicleList.add(new BlockVehicleDto("2", true)); |
| | | // blockVehicleList.add(new BlockVehicleDto("3", false)); |
| | | // blockVehicleList.add(new BlockVehicleDto("4", false)); |
| | | // blockVehicleList.add(new BlockVehicleDto("5", false)); |
| | | // blockVehicleList.add(new BlockVehicleDto("5", true)); |
| | | // blockVehicleList.add(new BlockVehicleDto("4", true)); |
| | | |
| | | System.out.println(GsonUtils.toJson(blockVehicleList)); |
| | | System.out.println(GsonUtils.toJson(blockVehicleList.stream().distinct().collect(Collectors.toList()))); |
| | | |
| | | System.out.println(blockVehicleList.stream().anyMatch(blockVehicleDto -> !blockVehicleDto.isAvoidable())); |
| | | |
| | | String blockAgvNo = blockVehicleList.stream() |
| | | .filter(BlockVehicleDto::isAvoidable) |
| | | .map(BlockVehicleDto::getVehicle) |
| | | .findFirst().orElse(null); |
| | | System.out.println(blockAgvNo); |
| | | } |
| | | |
| | | } |