Java Code Examples for com.google.common.collect.ImmutableSet#containsAll()

The following examples show how to use com.google.common.collect.ImmutableSet#containsAll() . 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: StreamPreferredProperties.java    From presto with Apache License 2.0 6 votes vote down vote up
public StreamPreferredProperties constrainTo(Iterable<Symbol> symbols)
{
    if (partitioningColumns.isEmpty()) {
        return this;
    }

    ImmutableSet<Symbol> availableSymbols = ImmutableSet.copyOf(symbols);
    if (exactColumnOrder) {
        if (availableSymbols.containsAll(partitioningColumns.get())) {
            return this;
        }
        return any();
    }

    List<Symbol> common = partitioningColumns.get().stream()
            .filter(availableSymbols::contains)
            .collect(toImmutableList());
    if (common.isEmpty()) {
        return any();
    }
    return new StreamPreferredProperties(distribution, Optional.of(common), false);
}
 
Example 2
Source File: CleanProjectTargetsSyncAction.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static boolean isDeletedTarget(
    RunConfiguration configuration, ImmutableSet<Label> deleted) {
  if (!(configuration instanceof BlazeCommandRunConfiguration)) {
    return false;
  }
  BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) configuration;
  ImmutableList<? extends TargetExpression> targets = config.getTargets();
  if (targets.isEmpty()) {
    return false;
  }
  if (deleted.containsAll(targets)) {
    return true;
  }
  ImmutableList<TargetExpression> updated =
      targets.stream().filter(deleted::contains).collect(toImmutableList());
  if (updated.size() == targets.size()) {
    return false;
  }
  config.setTargets(updated);
  return false;
}
 
Example 3
Source File: ValidateSystemOutput.java    From tac-kbp-eal with MIT License 6 votes vote down vote up
private void assertExactlyTwoSubdirectories(final File outputStoreDir) throws IOException {
  checkArgument(outputStoreDir.isDirectory());
  if (!new File(outputStoreDir, "arguments").isDirectory()) {
    throw new IOException(
        "Expected system output to be contain a subdirectory named 'arguments'");
  }
  if (!new File(outputStoreDir, "linking").isDirectory()) {
    throw new IOException("Expected system output to be contain a subdirectory named 'linking'");
  }
  final ImmutableSet<String> subdirectoryNames =
      FluentIterable.from(ImmutableList.copyOf(outputStoreDir.listFiles()))
          .transform(FileUtils.toNameFunction())
          .toSet();
  final boolean hasValidDirectoryStructure = subdirectoryNames.containsAll(REQUIRED_SUBDIRS)
      && ALLOWED_SUBDIRS.containsAll(subdirectoryNames);

  if (!hasValidDirectoryStructure) {
    throw new IOException(
        "Invalid subdirectories ) " + subdirectoryNames + ". Required are: " + REQUIRED_SUBDIRS
        + "; allowed are " + ALLOWED_SUBDIRS);
  }
}
 
Example 4
Source File: OAuthAuthenticationMechanism.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
public AuthResult authenticate(HttpServletRequest request) {

  // Make sure that there is an Authorization header in Bearer form. OAuthService also accepts
  // tokens in the request body and URL string, but we should not use those, since they are more
  // likely to be logged than the Authorization header. Checking to make sure there's a token also
  // avoids unnecessary RPCs, since OAuthService itself does not check whether the header is
  // present. In theory, there could be more than one Authorization header, but we only check the
  // first one, because there's not a legitimate use case for having more than one, and
  // OAuthService itself only looks at the first one anyway.
  String header = request.getHeader(AUTHORIZATION);
  if ((header == null) || !header.startsWith(BEARER_PREFIX)) {
    if (header != null) {
      logger.atInfo().log("invalid authorization header");
    }
    return AuthResult.create(NONE);
  }
  // Assume that, if a bearer token is found, it's what OAuthService will use to attempt
  // authentication. This is not technically guaranteed by the contract of OAuthService; see
  // OAuthTokenInfo for more information.
  String rawAccessToken = header.substring(BEARER_PREFIX.length());

  // Get the OAuth information. The various oauthService method calls use a single cached
  // authentication result, so we can call them one by one.
  User currentUser;
  boolean isUserAdmin;
  String clientId;
  ImmutableSet<String> authorizedScopes;
  try {
    String[] availableOauthScopeArray = availableOauthScopes.toArray(new String[0]);
    currentUser = oauthService.getCurrentUser(availableOauthScopeArray);
    isUserAdmin = oauthService.isUserAdmin(availableOauthScopeArray);
    logger.atInfo().log(
        "current user: %s (%s)", currentUser, isUserAdmin ? "admin" : "not admin");
    clientId = oauthService.getClientId(availableOauthScopeArray);
    logger.atInfo().log("client ID: %s", clientId);
    authorizedScopes =
        ImmutableSet.copyOf(oauthService.getAuthorizedScopes(availableOauthScopeArray));
    logger.atInfo().log("authorized scope(s): %s", authorizedScopes);
  } catch (OAuthRequestException | OAuthServiceFailureException e) {
    logger.atInfo().withCause(e).log("unable to get OAuth information");
    return AuthResult.create(NONE);
  }
  if ((currentUser == null) || (clientId == null) || (authorizedScopes == null)) {
    return AuthResult.create(NONE);
  }

  // Make sure that the client ID matches, to avoid a confused deputy attack; see:
  // http://stackoverflow.com/a/17439317/1179226
  if (!allowedOauthClientIds.contains(clientId)) {
    logger.atInfo().log("client ID is not allowed");
    return AuthResult.create(NONE);
  }

  // Make sure that all required scopes are present.
  if (!authorizedScopes.containsAll(requiredOauthScopes)) {
    logger.atInfo().log("required scope(s) missing");
    return AuthResult.create(NONE);
  }

  // Create the {@link AuthResult}, including the OAuth token info.
  return AuthResult.create(
      USER,
      UserAuthInfo.create(
          currentUser,
          isUserAdmin,
          OAuthTokenInfo.create(
              ImmutableSet.copyOf(authorizedScopes),
              clientId,
              rawAccessToken)));
}
 
Example 5
Source File: ConfigSettingSelectable.java    From buck with Apache License 2.0 4 votes vote down vote up
private <T> boolean refines(ImmutableSet<T> values, ImmutableSet<T> otherValues) {
  return (values.size() > otherValues.size() && values.containsAll(otherValues));
}