@Override public List<? extends Region> childRegions() { return getAllCounties(); } }
/** * 获得所有县级地区 * @return 所有县级地区 */ public List<County> getAllCounties() { List<County> counties = new LinkedList<>(); for (City city : getAllCities()) { counties.addAll(city.getAllCounties()); } return new ArrayList<>(counties); }
/** * 获得所有县级地区 * @return 该省所有县级地区 */ public List<County> getAllCounties() { List<County> counties = new LinkedList<>(); for (City city : getAllCities()) { counties.addAll(city.getAllCounties()); } return new ArrayList<>(counties); }
@Override public County randomValue(RandomGeneratorRegistry randomGeneratorRegistry, MockPlaceholder mockPlaceholder, MockCache mockCache) { List<County> counties; Optional<String> provinceOptional = mockPlaceholder.getParameter(PARAMETER_PROVINCE, String.class); if (provinceOptional.isPresent()) { Optional<Province> provinceByName = chinaRegionProvider.getChina().getProvinceByName(provinceOptional.get()); if(provinceByName.isPresent()) { Optional<String> cityOptional = mockPlaceholder.getParameter(PARAMETER_CITY, String.class); if(cityOptional.isPresent()) { Optional<City> cityByName = provinceByName.get().getCityByName(cityOptional.get()); if(cityByName.isPresent()) { counties = cityByName.get().getAllCounties(); } else { throw new MockException("address random generator city attribute \"%s\" value is not exist.", cityOptional.get()); } } else { counties = provinceByName.get().getAllCounties(); } } else { throw new MockException("address random generator province attribute \"%s\" value is not exist.", provinceOptional.get()); } } else { counties = chinaRegionProvider.getChina().getAllCounties(); } return counties.get(RandomUtils.nextInt(0, counties.size())); }