Java Code Examples for

The following examples show how to use . 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:    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()
    if (common.isEmpty()) {
        return any();
    return new StreamPreferredProperties(distribution, Optional.of(common), false);
Example 2
Source File:    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 =;
  if (updated.size() == targets.size()) {
    return false;
  return false;
Example 3
Source File:    From tac-kbp-eal with MIT License 6 votes vote down vote up
private void assertExactlyTwoSubdirectories(final File outputStoreDir) throws IOException {
  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 =
  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:    From nomulus with Apache License 2.0 4 votes vote down vote up
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);
        "current user: %s (%s)", currentUser, isUserAdmin ? "admin" : "not admin");
    clientId = oauthService.getClientId(availableOauthScopeArray);
    logger.atInfo().log("client ID: %s", clientId);
    authorizedScopes =
    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:
  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(
Example 5
Source File:    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));