spring ResourcePatternHints 源码
spring ResourcePatternHints 代码
文件路径:/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHints.java
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aot.hint;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.springframework.lang.Nullable;
/**
* A collection of {@link ResourcePatternHint} describing whether
* resources should be made available at runtime through a matching
* mechanism or inclusion/exclusion.
*
* @author Stephane Nicoll
* @author Brian Clozel
* @since 6.0
*/
public final class ResourcePatternHints {
private final List<ResourcePatternHint> includes;
private final List<ResourcePatternHint> excludes;
private ResourcePatternHints(Builder builder) {
this.includes = new ArrayList<>(builder.includes);
this.excludes = new ArrayList<>(builder.excludes);
}
/**
* Return the include patterns to use to identify the resources to match.
* @return the include patterns
*/
public List<ResourcePatternHint> getIncludes() {
return this.includes;
}
/**
* Return the exclude patterns to use to identify the resources to match.
* @return the exclude patterns
*/
public List<ResourcePatternHint> getExcludes() {
return this.excludes;
}
/**
* Builder for {@link ResourcePatternHints}.
*/
public static class Builder {
private final Set<ResourcePatternHint> includes = new LinkedHashSet<>();
private final Set<ResourcePatternHint> excludes = new LinkedHashSet<>();
Builder() {
}
/**
* Includes the resources matching the specified pattern.
* @param reachableType the type that should be reachable for this hint to apply
* @param includes the include patterns (see {@link ResourcePatternHint} documentation)
* @return {@code this}, to facilitate method chaining
*/
public Builder includes(@Nullable TypeReference reachableType, String... includes) {
List<ResourcePatternHint> newIncludes = Arrays.stream(includes)
.map(include -> new ResourcePatternHint(include, reachableType)).toList();
this.includes.addAll(newIncludes);
return this;
}
/**
* Includes the resources matching the specified pattern.
* @param includes the include patterns (see {@link ResourcePatternHint} documentation)
* @return {@code this}, to facilitate method chaining
*/
public Builder includes(String... includes) {
return includes(null, includes);
}
/**
* Exclude resources matching the specified pattern.
* @param reachableType the type that should be reachable for this hint to apply
* @param excludes the excludes pattern (see {@link ResourcePatternHint} documentation)
* @return {@code this}, to facilitate method chaining
*/
public Builder excludes(TypeReference reachableType, String... excludes) {
List<ResourcePatternHint> newExcludes = Arrays.stream(excludes)
.map(include -> new ResourcePatternHint(include, reachableType)).toList();
this.excludes.addAll(newExcludes);
return this;
}
/**
* Exclude resources matching the specified pattern.
* @param excludes the excludes pattern (see {@link ResourcePatternHint} documentation)
* @return {@code this}, to facilitate method chaining
*/
public Builder excludes(String... excludes) {
return excludes(null, excludes);
}
/**
* Creates a {@link ResourcePatternHints} based on the state of this
* builder.
* @return a resource pattern hint
*/
ResourcePatternHints build() {
return new ResourcePatternHints(this);
}
}
}
相关信息
相关文章
spring AbstractTypeReference 源码
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
7、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦