CameraFactory.java 534 B

123456789101112131415161718192021
  1. package com.gzlh.camera.factory;
  2. import com.gzlh.camera.handler.ICameraHandler;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Service;
  5. import java.util.List;
  6. @Service
  7. public class CameraFactory {
  8. @Autowired
  9. private List<ICameraHandler>handlers;
  10. public ICameraHandler handler(int code){
  11. return handlers.stream().filter(h->h.brandType().getCode()==code)
  12. .findAny().orElseThrow(()->new IllegalArgumentException("不支持交互"));
  13. }
  14. }