class ComponentRepoVersionServiceImpl implements ComponentRepoVersionService {

	@Override
	public Optional<ComponentRepoVersion> findLatestVersion(Integer componentRepoId) {
		List<ComponentRepoVersion> allVersions = componentRepoVersionDao.findAllByComponentRepoId(componentRepoId);
		if(allVersions.isEmpty()) {
			return Optional.empty();
		}
		// 要先过滤掉 master 版本
		List<ComponentRepoVersion> filtered = allVersions.stream().filter(apiRepoVersion -> !apiRepoVersion.getVersion().equals("master")).collect(Collectors.toList());
		if(filtered.isEmpty()) {
			return Optional.empty();
		}
		// 最新版本在最前面
		filtered.sort(new Comparator<ComponentRepoVersion>() {
			@Override
			public int compare(ComponentRepoVersion version1, ComponentRepoVersion version2) {
				return Version.compare(Version.parseVersion(version2.getVersion()), Version.parseVersion(version1.getVersion()));
			}
		});
		return Optional.of(filtered.get(0));
	}

}