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

The following examples show how to use java.util.Set#copyOf() . 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 File: ExtendedSocketOptions.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
protected ExtendedSocketOptions(Set<SocketOption<?>> options) {
    this.options = options;
    var datagramOptions = new HashSet<SocketOption<?>>();
    var serverStreamOptions = new HashSet<SocketOption<?>>();
    var clientStreamOptions = new HashSet<SocketOption<?>>();
    for (var option : options) {
        if (isDatagramOption(option)) {
            datagramOptions.add(option);
        }
        if (isStreamOption(option, true)) {
            serverStreamOptions.add(option);
        }
        if (isStreamOption(option, false)) {
            clientStreamOptions.add(option);
        }
    }
    this.datagramOptions = Set.copyOf(datagramOptions);
    this.serverStreamOptions = Set.copyOf(serverStreamOptions);
    this.clientStreamOptions = Set.copyOf(clientStreamOptions);
}
 
Example 2
Source File: BlueprintValidatorUtil.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public static void validateHostGroupsMatch(Set<HostGroup> hostGroupsInRequest, Set<String> hostGroupsInBlueprint) {
    Set<String> hostGroupNamesInRequest = hostGroupsInRequest.stream().map(HostGroup::getName).collect(Collectors.toSet());
    Set<String> missingFromRequest = Set.copyOf(Sets.difference(hostGroupsInBlueprint, hostGroupNamesInRequest));
    Set<String> unknownHostGroups = Set.copyOf(Sets.difference(hostGroupNamesInRequest, hostGroupsInBlueprint));
    if (!missingFromRequest.isEmpty()) {
        throw new BlueprintValidationException("The following host groups are missing from the request: "
                + String.join(", ", missingFromRequest));
    }
    if (!unknownHostGroups.isEmpty()) {
        throw new BlueprintValidationException("Unknown host groups are present in the request: "
                + String.join(", ", unknownHostGroups));
    }
}
 
Example 3
Source File: Endpoint.java    From vespa with Apache License 2.0 5 votes vote down vote up
public Endpoint(Optional<String> endpointId, String containerId, Set<String> regions) {
    this.endpointId = Objects.requireNonNull(endpointId, "endpointId must be non-null");
    this.containerId = Objects.requireNonNull(containerId, "containerId must be non-null");
    this.regions = Set.copyOf(
            Objects.requireNonNull(
                    regions.stream().map(RegionName::from).collect(Collectors.toList()),
                    "Missing 'regions' parameter"));

    if (endpointId().length() > endpointMaxLength || !endpointPattern.matcher(endpointId()).matches()) {
        throw new IllegalArgumentException("Invalid endpoint ID: '" + endpointId() + "'");
    }
}
 
Example 4
Source File: SessionConfigurationContext.java    From presto with Apache License 2.0 5 votes vote down vote up
public SessionConfigurationContext(String user, Optional<String> source, Set<String> clientTags, Optional<String> queryType, ResourceGroupId resourceGroupId)
{
    this.user = requireNonNull(user, "user is null");
    this.source = requireNonNull(source, "source is null");
    this.clientTags = Set.copyOf(requireNonNull(clientTags, "clientTags is null"));
    this.queryType = requireNonNull(queryType, "queryType is null");
    this.resourceGroupId = requireNonNull(resourceGroupId, "resourceGroupId");
}
 
Example 5
Source File: Web3EntryPoint.java    From aion with MIT License 5 votes vote down vote up
public Web3EntryPoint(RPCServerMethods rpc, List<String> enabledGroup, List<String> enabledMethods,
    List<String> disabledMethods){
    this.rpc = rpc;
    this.enabledGroup = Set.copyOf(enabledGroup);
    this.enabledMethods = Set.copyOf(enabledMethods);
    this.disabledMethods = Set.copyOf(disabledMethods);
}
 
Example 6
Source File: Output.java    From java with MIT License 5 votes vote down vote up
Output(
    final String secret,
    final String discovered,
    final Set<String> guess,
    final Set<String> misses,
    final List<Part> parts,
    final Status status) {
    this.secret = secret;
    this.discovered = discovered;
    this.guess = Set.copyOf(guess);
    this.misses = Set.copyOf(misses);
    this.parts = List.copyOf(parts);
    this.status = status;
}
 
Example 7
Source File: Output.java    From java with MIT License 5 votes vote down vote up
Output(
    final String secret,
    final String discovered,
    final Set<String> guess,
    final Set<String> misses,
    final List<Part> parts,
    final Status status) {
    this.secret = secret;
    this.discovered = discovered;
    this.guess = Set.copyOf(guess);
    this.misses = Set.copyOf(misses);
    this.parts = List.copyOf(parts);
    this.status = status;
}
 
Example 8
Source File: SessionPreparer.java    From vespa with Apache License 2.0 4 votes vote down vote up
Preparation(HostValidator<ApplicationId> hostValidator, DeployLogger logger, PrepareParams params,
            Optional<ApplicationSet> currentActiveApplicationSet, Path tenantPath,
            File serverDbSessionDir, ApplicationPackage preprocessedApplicationPackage,
            SessionZooKeeperClient sessionZooKeeperClient) {
    this.logger = logger;
    this.params = params;
    this.applicationPackage = preprocessedApplicationPackage;
    this.sessionZooKeeperClient = sessionZooKeeperClient;
    this.applicationId = params.getApplicationId();
    this.dockerImageRepository = params.dockerImageRepository();
    this.vespaVersion = params.vespaVersion().orElse(Vtag.currentVersion);
    this.containerEndpointsCache = new ContainerEndpointsCache(tenantPath, curator);
    this.endpointCertificateMetadataStore = new EndpointCertificateMetadataStore(curator, tenantPath);
    EndpointCertificateRetriever endpointCertificateRetriever = new EndpointCertificateRetriever(secretStore);
    this.endpointCertificateMetadata = params.endpointCertificateMetadata()
            .or(() -> params.tlsSecretsKeyName().map(EndpointCertificateMetadataSerializer::fromString));
    Optional<EndpointCertificateSecrets> endpointCertificateSecrets = endpointCertificateMetadata
            .or(() -> endpointCertificateMetadataStore.readEndpointCertificateMetadata(applicationId))
            .flatMap(endpointCertificateRetriever::readEndpointCertificateSecrets);
    this.containerEndpoints = readEndpointsIfNull(params.containerEndpoints());
    this.athenzDomain = params.athenzDomain();
    this.applicationRolesStore = new ApplicationRolesStore(curator, tenantPath);
    this.applicationRoles = params.applicationRoles()
            .or(() -> applicationRolesStore.readApplicationRoles(applicationId));
    this.properties = new ModelContextImpl.Properties(params.getApplicationId(),
                                                      configserverConfig.multitenant(),
                                                      ConfigServerSpec.fromConfig(configserverConfig),
                                                      HostName.from(configserverConfig.loadBalancerAddress()),
                                                      configserverConfig.ztsUrl() != null ? URI.create(configserverConfig.ztsUrl()) : null,
                                                      configserverConfig.athenzDnsSuffix(),
                                                      configserverConfig.hostedVespa(),
                                                      zone,
                                                      Set.copyOf(containerEndpoints),
                                                      params.isBootstrap(),
                                                      currentActiveApplicationSet.isEmpty(),
                                                      flagSource,
                                                      endpointCertificateSecrets,
                                                      athenzDomain, applicationRoles);
    this.fileDistributionProvider = fileDistributionFactory.createProvider(serverDbSessionDir);
    this.preparedModelsBuilder = new PreparedModelsBuilder(modelFactoryRegistry,
                                                           permanentApplicationPackage,
                                                           configDefinitionRepo,
                                                           fileDistributionProvider,
                                                           hostProvisionerProvider,
                                                           hostValidator,
                                                           logger,
                                                           params,
                                                           currentActiveApplicationSet,
                                                           properties,
                                                           configserverConfig);
}
 
Example 9
Source File: InMemoryKeyValueStorage.java    From besu with Apache License 2.0 4 votes vote down vote up
public Set<Bytes> keySet() {
  return Set.copyOf(hashValueStore.keySet());
}
 
Example 10
Source File: ProviderContent.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
public Set<ProviderNotificationType> getContentTypes() {
    return Set.copyOf(supportedNotificationTypes);
}
 
Example 11
Source File: SystemModuleFinders.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
SystemModuleFinder(Set<ModuleReference> mrefs,
                   Map<String, ModuleReference> nameToModule) {
    this.mrefs = Set.copyOf(mrefs);
    this.nameToModule = Map.copyOf(nameToModule);
}
 
Example 12
Source File: ShallowReference.java    From sling-whiteboard with Apache License 2.0 4 votes vote down vote up
@NotNull
public Set<String> getProvidedResourcePaths() {
    return Set.copyOf(resourcePaths);
}
 
Example 13
Source File: SnapshotClusterStateProvider.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public SnapshotClusterStateProvider(ClusterStateProvider other) throws Exception {
  liveNodes = Set.copyOf(other.getLiveNodes());
  ClusterState otherState = other.getClusterState();
  clusterState = new ClusterState(liveNodes, otherState.getCollectionsMap());
  clusterProperties = new HashMap<>(other.getClusterProperties());
}
 
Example 14
Source File: AutoscaleRecommendation.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public AutoscaleRecommendation(Set<String> timeBasedHostGroups, Set<String> loadBasedHostGroups) {
    this.timeBasedHostGroups = Set.copyOf(timeBasedHostGroups);
    this.loadBasedHostGroups = Set.copyOf(loadBasedHostGroups);
}
 
Example 15
Source File: OverrideProcessor.java    From vespa with Apache License 2.0 4 votes vote down vote up
private Context(Set<InstanceName> instances, Set<Environment> environments, Set<RegionName> regions) {
    this.instances = Set.copyOf(instances);
    this.environments = Set.copyOf(environments);
    this.regions = Set.copyOf(regions);
}
 
Example 16
Source File: AthenzRoleFilter.java    From vespa with Apache License 2.0 4 votes vote down vote up
Set<Role> roles(AthenzPrincipal principal, URI uri) throws Exception {
    Path path = new Path(uri);

    path.matches("/application/v4/tenant/{tenant}/{*}");
    Optional<Tenant> tenant = Optional.ofNullable(path.get("tenant")).map(TenantName::from).flatMap(tenants::get);

    path.matches("/application/v4/tenant/{tenant}/application/{application}/{*}");
    Optional<ApplicationName> application = Optional.ofNullable(path.get("application")).map(ApplicationName::from);

    AthenzIdentity identity = principal.getIdentity();

    Set<Role> roleMemberships = new CopyOnWriteArraySet<>();
    List<Future<?>> futures = new ArrayList<>();

    futures.add(executor.submit(() -> {
        if (athenz.hasHostedOperatorAccess(identity))
            roleMemberships.add(Role.hostedOperator());
    }));

    futures.add(executor.submit(() -> {
        if (athenz.hasHostedSupporterAccess(identity))
            roleMemberships.add(Role.hostedSupporter());
    }));

    futures.add(executor.submit(() -> {
        // Add all tenants that are accessible for this request
        athenz.accessibleTenants(tenants.asList(), new Credentials(principal))
              .forEach(accessibleTenant -> roleMemberships.add(Role.athenzTenantAdmin(accessibleTenant.name())));
    }));

    if (     identity.getDomain().equals(SCREWDRIVER_DOMAIN)
        &&   application.isPresent()
        &&   tenant.isPresent()
        && ! tenant.get().name().value().equals("sandbox"))
        futures.add(executor.submit(() -> {
            if (   tenant.get().type() == Tenant.Type.athenz
                && hasDeployerAccess(identity, ((AthenzTenant) tenant.get()).domain(), application.get()))
                roleMemberships.add(Role.buildService(tenant.get().name(), application.get()));
        }));

    futures.add(executor.submit(() -> {
        if (athenz.hasSystemFlagsAccess(identity, /*dryrun*/false))
            roleMemberships.add(Role.systemFlagsDeployer());
    }));

    futures.add(executor.submit(() -> {
        if (athenz.hasPaymentCallbackAccess(identity))
            roleMemberships.add(Role.paymentProcessor());
    }));

    futures.add(executor.submit(() -> {
        if (athenz.hasAccountingAccess(identity))
            roleMemberships.add(Role.hostedAccountant());
    }));

    // Run last request in handler thread to avoid creating extra thread.
    if (athenz.hasSystemFlagsAccess(identity, /*dryrun*/true))
        roleMemberships.add(Role.systemFlagsDryrunner());

    for (Future<?> future : futures)
        future.get(30, TimeUnit.SECONDS);

    return roleMemberships.isEmpty()
            ? Set.of(Role.everyone())
            : Set.copyOf(roleMemberships);
}
 
Example 17
Source File: SecurityContext.java    From vespa with Apache License 2.0 4 votes vote down vote up
public SecurityContext(Principal principal, Set<Role> roles) {
    this.principal = Objects.requireNonNull(principal);
    this.roles = Set.copyOf(roles);
}
 
Example 18
Source File: ConnectorIdentity.java    From presto with Apache License 2.0 4 votes vote down vote up
public Builder withGroups(Set<String> groups)
{
    this.groups = Set.copyOf(requireNonNull(groups, "groups is null"));
    return this;
}
 
Example 19
Source File: AutoscaleRecommendationV4Response.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public AutoscaleRecommendationV4Response(Set<String> timeBasedHostGroups, Set<String> loadBasedHostGroups) {
    this.timeBasedHostGroups = Set.copyOf(timeBasedHostGroups);
    this.loadBasedHostGroups = Set.copyOf(loadBasedHostGroups);
}
 
Example 20
Source File: MockRedisSet.java    From core-ng-project with Apache License 2.0 4 votes vote down vote up
@Override
public Set<String> members(String key) {
    var value = store.get(key);
    if (value == null) return Set.of();
    return Set.copyOf(value.set());
}