分享一下平时写得比较规范的代码片段
@Data
@Configuration
@ConfigurationProperties(prefix = "swagger")
public class SwaggerProperties{
private Boolean enabled = true;
private List<String> basePath = Collections.emptyList();
private List<String> excludePath = Collections.emptyList();
private List<String> basePackage = Collections.emptyList();
private String title = "标题";
private String description = "描述";
private String version = "版本";
private String termsOfServiceUrl = "http://www.bocloud.com/terms";
private Contact contact = new Contact("Author", "http://www.bocloud.com", "author@bocloud.com");
private String license = "协议";
private String licenseUrl = "http://www.bocloud.com/license";
public ApiInfo apiInfo(){
return new ApiInfo(title, description, version, termsOfServiceUrl, contact.toString(), license, licenseUrl);
}
public Predicate<String> excludePath(){
return excludePath.stream()
.map(PathSelectors::regex)
.map(Predicates::not)
.reduce(Predicates::or)
.orElseGet(Predicates::alwaysFalse);
}
public Predicate<String> basePath(){
return basePath.stream()
.map(PathSelectors::regex)
.reduce(Predicates::or)
.orElseGet(Predicates::alwaysFalse);
}
public Optional<Predicate<RequestHandler>> apis(){
return basePackage.stream()
.map(RequestHandlerSelectors::basePackage)
.reduce(Predicates::or);
}
public Predicate<String> paths(){
return Predicates.or(excludePath(), basePath());
}
}