Java Code Examples for java.util.Map#copyOf()

The following examples show how to use java.util.Map#copyOf() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: presto   File: MemoryPoolInfo.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source Project: vespa   File: LockedApplication.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source Project: presto   File: Identity.java    License: Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 4
Source Project: presto   File: ConnectorIdentity.java    License: Apache License 2.0 5 votes vote down vote up
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"));
}
 
Example 5
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);
}
 
Example 6
Source Project: vespa   File: DeploymentMetrics.java    License: Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 7
@Override
public Map<String, String> getTokenFilterParams(int index) {
  if (index < 0 || index > tfParamsList.size()) {
    throw new IllegalArgumentException();
  }
  return Map.copyOf(tfParamsList.get(index));
}
 
Example 8
Source Project: vespa   File: RotationStatus.java    License: Apache License 2.0 4 votes vote down vote up
private RotationStatus(Map<RotationId, Targets> status) {
    this.status = Map.copyOf(Objects.requireNonNull(status));
}
 
Example 9
public RestPayloadException(final Map<String, List<String>> failures) {
    super((String) null);
    this.failures = Map.copyOf(failures);
}
 
Example 10
@Override
public Map<IdT, ValueT> asMap() {
  return Map.copyOf(cache.asMap());
}
 
Example 11
Source Project: lucene-solr   File: SearchResults.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns the field data of this document.
 */
public Map<String, String[]> getFieldValues() {
  return Map.copyOf(fieldValues);
}
 
Example 12
Source Project: vespa   File: RotationStatus.java    License: Apache License 2.0 4 votes vote down vote up
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");
}
 
Example 13
Source Project: lucene-solr   File: Analysis.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns value of this attribute.
 */
public Map<String, String> getAttValues() {
  return Map.copyOf(attValues);
}
 
Example 14
Source Project: vespa   File: ApplicationRepositoryTest.java    License: Apache License 2.0 4 votes vote down vote up
public Context(Map<String, ?> point) {
    this.point = Map.copyOf(point);
}
 
Example 15
Source Project: lucene-solr   File: AnalysisSPILoader.java    License: Apache License 2.0 4 votes vote down vote up
/** 
 * 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);
}
 
Example 16
/** Get information about which bytes have been read. */
public Map<String, FixedBitSet> getReadBytes() {
  return Map.copyOf(readBytes);
}
 
Example 17
Source Project: lucene-solr   File: SegmentInfo.java    License: Apache License 2.0 4 votes vote down vote up
void setDiagnostics(Map<String, String> diagnostics) {
  this.diagnostics = Map.copyOf(Objects.requireNonNull(diagnostics));
}
 
Example 18
Source Project: vespa   File: NodeTargetVersions.java    License: Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 19
Source Project: vespa   File: FileReferenceDownloader.java    License: Apache License 2.0 4 votes vote down vote up
Map<FileReference, Double> downloadStatus() {
    synchronized (downloads) {
        return Map.copyOf(downloadStatus);
    }
}
 
Example 20
Source Project: ditto   File: MappingStrategies.java    License: Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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"));
}