下面列出了java.util.List#copyOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private HostSpec(String hostname,
List<String> aliases,
NodeResources realResources,
NodeResources advertisedResurces,
NodeResources requestedResources,
Optional<ClusterMembership> membership,
Optional<Version> version,
Optional<NetworkPorts> networkPorts,
Optional<DockerImage> dockerImageRepo) {
if (hostname == null || hostname.isEmpty()) throw new IllegalArgumentException("Hostname must be specified");
this.hostname = hostname;
this.aliases = List.copyOf(aliases);
this.realResources = Objects.requireNonNull(realResources);
this.advertisedResources = Objects.requireNonNull(advertisedResurces);
this.requestedResources = Objects.requireNonNull(requestedResources, "RequestedResources cannot be null");
this.membership = Objects.requireNonNull(membership);
this.version = Objects.requireNonNull(version, "Version cannot be null but can be empty");
this.networkPorts = Objects.requireNonNull(networkPorts, "Network ports cannot be null but can be empty");
this.dockerImageRepo = Objects.requireNonNull(dockerImageRepo, "Docker image repo cannot be null but can be empty");
}
private PageBuilder(int initialExpectedEntries, int maxPageBytes, List<? extends Type> types, Optional<BlockBuilder[]> templateBlockBuilders)
{
this.types = List.copyOf(requireNonNull(types, "types is null"));
pageBuilderStatus = new PageBuilderStatus(maxPageBytes);
blockBuilders = new BlockBuilder[types.size()];
if (templateBlockBuilders.isPresent()) {
BlockBuilder[] templates = templateBlockBuilders.get();
checkArgument(templates.length == types.size(), "Size of templates and types should match");
for (int i = 0; i < blockBuilders.length; i++) {
blockBuilders[i] = templates[i].newBlockBuilderLike(pageBuilderStatus.createBlockBuilderStatus());
}
}
else {
for (int i = 0; i < blockBuilders.length; i++) {
blockBuilders[i] = types.get(i).createBlockBuilder(pageBuilderStatus.createBlockBuilderStatus(), initialExpectedEntries);
}
}
}
/**
* Constructor for this class specializer.
* @param topClass type mirror for T
* @param keyType type mirror for K
* @param metaType type mirror for S
* @param baseConstructorType principal constructor type
* @param sdAccessor the method used to get the speciesData
* @param sdFieldName the name of the species data field, inject the speciesData object
* @param transformMethods optional list of transformMethods
*/
protected ClassSpecializer(Class<T> topClass,
Class<K> keyType,
Class<S> metaType,
MethodType baseConstructorType,
MemberName sdAccessor,
String sdFieldName,
List<MemberName> transformMethods) {
this.topClass = topClass;
this.keyType = keyType;
this.metaType = metaType;
this.sdAccessor = sdAccessor;
this.transformMethods = List.copyOf(transformMethods);
this.sdFieldName = sdFieldName;
this.baseConstructorType = baseConstructorType.changeReturnType(void.class);
this.factory = makeFactory();
K tsk = topSpeciesKey();
S topSpecies = null;
if (tsk != null && topSpecies == null) {
// if there is a key, build the top species if needed:
topSpecies = findSpecies(tsk);
}
this.topSpecies = topSpecies;
}
public WordModel(final int sequenceNo, final String word, final List<Integer> lineNos, final int useCount, final WordState state, final String note) {
this.lineNos = List.copyOf(lineNos);
this.useCount = useCount;
this.identifier = new SimpleStringProperty(word);
this.sequenceNo = sequenceNo;
this.state = new SimpleObjectProperty<>(state);
this.note = new SimpleStringProperty(note);
}
public GroupHashAggregate(LogicalPlan source, List<Symbol> groupKeys, List<Function> aggregates, long numExpectedRows) {
super(source);
this.numExpectedRows = numExpectedRows;
this.aggregates = List.copyOf(new LinkedHashSet<>(aggregates));
this.outputs = Lists2.concat(groupKeys, this.aggregates);
this.groupKeys = groupKeys;
}
private List<ContainerEndpoint> readEndpointsIfNull(List<ContainerEndpoint> endpoints) {
if (endpoints == null) { // endpoints are only set when prepared via HTTP
endpoints = this.containerEndpointsCache.read(applicationId);
}
return List.copyOf(endpoints);
}
/**
* Returns TokenFilters configurations.
*/
List<ComponentConfig> getTokenFilterConfigs() {
return List.copyOf(tokenFilterConfigs);
}
public List<String> getMessages() {
return List.copyOf(messages);
}
@Test(expected = UnsupportedOperationException.class)
public void whenModifyCopyOfList_thenThrowsException() {
List<Integer> copyList = List.copyOf(Arrays.asList(1, 2, 3, 4));
}
private LoadBalancerAllocation(ApplicationId application, ZoneId zone, List<LoadBalancer> loadBalancers,
DeploymentSpec deploymentSpec) {
this.deployment = new DeploymentId(application, zone);
this.loadBalancers = List.copyOf(loadBalancers);
this.deploymentSpec = deploymentSpec;
}
public AnalysisResult(final String name, final List<WordUse> orderedUses, final List<String> lines) {
this.name = name;
this.orderedUses = List.copyOf(orderedUses);
this.lines = List.copyOf(lines);
}
private Builder(Collection<Type> types)
{
this.types = List.copyOf(requireNonNull(types, "types is null"));
checkArgument(!this.types.isEmpty(), "types is empty");
}
@Override
public List<GoPluginDescriptor> plugins() {
return List.copyOf(idToDescriptorMap.values());
}
private LoadBalancerList(Collection<LoadBalancer> loadBalancers) {
this.loadBalancers = List.copyOf(Objects.requireNonNull(loadBalancers, "loadBalancers must be non-null"));
}
/**
* Returns attributes of this token.
*/
public List<TokenAttribute> getAttributes() {
return List.copyOf(attributes);
}
public JoinUsing(List<String> columns) {
if (columns.isEmpty()) {
throw new IllegalArgumentException("columns must not be empty");
}
this.columns = List.copyOf(columns);
}
@Override
public List<? extends ZoneApi> zones() {
return List.copyOf(zones);
}
@Test(expected = UnsupportedOperationException.class)
public void whenModifyCopyOfList_thenThrowsException() {
List<Integer> copyList = List.copyOf(someIntList);
copyList.add(4);
}
private FilterTableLineEditor(List<String> wantedRules) {
this.wantedRules = List.copyOf(wantedRules);
}
/**
* Displays a showMenuStep so that the user can make a choice
*
* @param textToShow a text that will be shown
* @param menuItems a list containing the elements of the showMenuStep
* @param defaultValue item which is selected by default
* @return the value the user entered (as string)
*/
@Override
public MenuItem menu(String textToShow, List<String> menuItems, String defaultValue) {
final List<String> copiedMenuItems = List.copyOf(menuItems);
return messageSender
.runAndWait(message -> setupUi.showMenuStep(message, textToShow, copiedMenuItems, defaultValue));
}