下面列出了java.util.Map#copyOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@JsonCreator
public MemoryPoolInfo(
@JsonProperty("maxBytes") long maxBytes,
@JsonProperty("reservedBytes") long reservedBytes,
@JsonProperty("reservedRevocableBytes") long reservedRevocableBytes,
@JsonProperty("queryMemoryReservations") Map<QueryId, Long> queryMemoryReservations,
@JsonProperty("queryMemoryAllocations") Map<QueryId, List<MemoryAllocation>> queryMemoryAllocations,
@JsonProperty("queryMemoryRevocableReservations") Map<QueryId, Long> queryMemoryRevocableReservations)
{
this.maxBytes = maxBytes;
this.reservedBytes = reservedBytes;
this.reservedRevocableBytes = reservedRevocableBytes;
this.queryMemoryReservations = Map.copyOf(queryMemoryReservations);
this.queryMemoryAllocations = Map.copyOf(queryMemoryAllocations);
this.queryMemoryRevocableReservations = Map.copyOf(queryMemoryRevocableReservations);
}
private LockedApplication(Lock lock, TenantAndApplicationId id, Instant createdAt, DeploymentSpec deploymentSpec,
ValidationOverrides validationOverrides,
Optional<IssueId> deploymentIssueId, Optional<IssueId> ownershipIssueId, Optional<User> owner,
OptionalInt majorVersion, ApplicationMetrics metrics, Set<PublicKey> deployKeys,
OptionalLong projectId, Optional<ApplicationVersion> latestVersion,
Map<InstanceName, Instance> instances) {
this.lock = lock;
this.id = id;
this.createdAt = createdAt;
this.deploymentSpec = deploymentSpec;
this.validationOverrides = validationOverrides;
this.deploymentIssueId = deploymentIssueId;
this.ownershipIssueId = ownershipIssueId;
this.owner = owner;
this.majorVersion = majorVersion;
this.metrics = metrics;
this.deployKeys = deployKeys;
this.projectId = projectId;
this.latestVersion = latestVersion;
this.instances = Map.copyOf(instances);
}
private Identity(
String user,
Set<String> groups,
Optional<Principal> principal,
Map<String, SelectedRole> roles,
Map<String, String> extraCredentials,
Optional<Runnable> onDestroy)
{
this.user = requireNonNull(user, "user is null");
this.groups = Set.copyOf(requireNonNull(groups, "groups is null"));
this.principal = requireNonNull(principal, "principal is null");
this.roles = Map.copyOf(requireNonNull(roles, "roles is null"));
this.extraCredentials = Map.copyOf(requireNonNull(extraCredentials, "extraCredentials is null"));
this.onDestroy = requireNonNull(onDestroy, "onDestroy is null");
}
private ConnectorIdentity(
String user,
Set<String> groups,
Optional<Principal> principal,
Optional<SelectedRole> role,
Map<String, String> extraCredentials)
{
this.user = requireNonNull(user, "user is null");
this.groups = Set.copyOf(requireNonNull(groups, "groups is null"));
this.principal = requireNonNull(principal, "principal is null");
this.role = requireNonNull(role, "role is null");
this.extraCredentials = Map.copyOf(requireNonNull(extraCredentials, "extraCredentials is null"));
}
public AggregationApplicationResult(
T handle,
List<ConnectorExpression> projections,
List<Assignment> assignments,
Map<ColumnHandle, ColumnHandle> groupingColumnMapping)
{
this.handle = requireNonNull(handle, "handle is null");
requireNonNull(groupingColumnMapping, "goupingSetMapping is null");
requireNonNull(projections, "projections is null");
requireNonNull(assignments, "assignment is null");
this.groupingColumnMapping = Map.copyOf(groupingColumnMapping);
this.projections = List.copyOf(projections);
this.assignments = List.copyOf(assignments);
}
public DeploymentMetrics(double queriesPerSecond, double writesPerSecond, double documentCount,
double queryLatencyMillis, double writeLatencyMills, Optional<Instant> instant,
Map<Warning, Integer> warnings) {
this.queriesPerSecond = queriesPerSecond;
this.writesPerSecond = writesPerSecond;
this.documentCount = documentCount;
this.queryLatencyMillis = queryLatencyMillis;
this.writeLatencyMills = writeLatencyMills;
this.instant = Objects.requireNonNull(instant, "instant must be non-null");
this.warnings = Map.copyOf(Objects.requireNonNull(warnings, "warnings must be non-null"));
if (warnings.entrySet().stream().anyMatch(kv -> kv.getValue() < 0)) {
throw new IllegalArgumentException("Warning count must be non-negative. Got " + warnings);
}
}
@Override
public Map<String, String> getTokenFilterParams(int index) {
if (index < 0 || index > tfParamsList.size()) {
throw new IllegalArgumentException();
}
return Map.copyOf(tfParamsList.get(index));
}
private RotationStatus(Map<RotationId, Targets> status) {
this.status = Map.copyOf(Objects.requireNonNull(status));
}
public RestPayloadException(final Map<String, List<String>> failures) {
super((String) null);
this.failures = Map.copyOf(failures);
}
@Override
public Map<IdT, ValueT> asMap() {
return Map.copyOf(cache.asMap());
}
/**
* Returns the field data of this document.
*/
public Map<String, String[]> getFieldValues() {
return Map.copyOf(fieldValues);
}
public Targets(Map<ZoneId, RotationState> targets, Instant lastUpdated) {
this.targets = Map.copyOf(Objects.requireNonNull(targets, "states must be non-null"));
this.lastUpdated = Objects.requireNonNull(lastUpdated, "lastUpdated must be non-null");
}
/**
* Returns value of this attribute.
*/
public Map<String, String> getAttValues() {
return Map.copyOf(attValues);
}
public Context(Map<String, ?> point) {
this.point = Map.copyOf(point);
}
/**
* Reloads the internal SPI list from the given {@link ClassLoader}.
* Changes to the service list are visible after the method ends, all
* iterators (e.g., from {@link #availableServices()},...) stay consistent.
*
* <p><b>NOTE:</b> Only new service providers are added, existing ones are
* never removed or replaced.
*
* <p><em>This method is expensive and should only be called for discovery
* of new service providers on the given classpath/classloader!</em>
*/
public synchronized void reload(ClassLoader classloader) {
Objects.requireNonNull(classloader, "classloader");
final LinkedHashMap<String,Class<? extends S>> services = new LinkedHashMap<>(this.services);
final LinkedHashSet<String> originalNames = new LinkedHashSet<>(this.originalNames);
ServiceLoader.load(clazz, classloader).stream().map(ServiceLoader.Provider::type).forEachOrdered(service -> {
String name = null;
String originalName = null;
Throwable cause = null;
try {
originalName = lookupSPIName(service);
name = originalName.toLowerCase(Locale.ROOT);
if (!isValidName(originalName)) {
throw new ServiceConfigurationError("The name " + originalName + " for " + service.getName() +
" is invalid: Allowed characters are (English) alphabet, digits, and underscore. It should be started with an alphabet.");
}
} catch (NoSuchFieldException | IllegalAccessException | IllegalStateException e) {
cause = e;
}
if (name == null) {
throw new ServiceConfigurationError("The class name " + service.getName() +
" has no service name field: [public static final String NAME]", cause);
}
// only add the first one for each name, later services will be ignored
// this allows to place services before others in classpath to make
// them used instead of others
//
// TODO: Should we disallow duplicate names here?
// Allowing it may get confusing on collisions, as different packages
// could contain same factory class, which is a naming bug!
// When changing this be careful to allow reload()!
if (!services.containsKey(name)) {
services.put(name, service);
// preserve (case-sensitive) original name for reference
originalNames.add(originalName);
}
});
// make sure that the number of lookup keys is same to the number of original names.
// in fact this constraint should be met in existence checks of the lookup map key,
// so this is more like an assertion rather than a status check.
if (services.keySet().size() != originalNames.size()) {
throw new ServiceConfigurationError("Service lookup key set is inconsistent with original name set!");
}
this.services = Map.copyOf(services);
this.originalNames = Set.copyOf(originalNames);
}
/** Get information about which bytes have been read. */
public Map<String, FixedBitSet> getReadBytes() {
return Map.copyOf(readBytes);
}
void setDiagnostics(Map<String, String> diagnostics) {
this.diagnostics = Map.copyOf(Objects.requireNonNull(diagnostics));
}
@JsonCreator
public NodeTargetVersions(@JsonProperty("versions") Map<NodeType, String> vespaVersions,
@JsonProperty("osVersions") Map<NodeType, String> osVersions) {
this.vespaVersions = Map.copyOf(vespaVersions);
this.osVersions = Map.copyOf(osVersions);
}
Map<FileReference, Double> downloadStatus() {
synchronized (downloads) {
return Map.copyOf(downloadStatus);
}
}
/**
* Constructs a new AbstractMappingStrategies object.
*
* @param strategies the key-value pairs of the returned mapping strategies.
* @throws NullPointerException if {@code strategies} is {@code null}.
*/
protected MappingStrategies(final Map<String, MappingStrategy> strategies) {
this.strategies = Map.copyOf(checkNotNull(strategies, "strategies"));
}