当前位置: 首页>>代码示例>>Java>>正文


Java Sets.SetView方法代码示例

本文整理汇总了Java中com.google.common.collect.Sets.SetView方法的典型用法代码示例。如果您正苦于以下问题:Java Sets.SetView方法的具体用法?Java Sets.SetView怎么用?Java Sets.SetView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.Sets的用法示例。


在下文中一共展示了Sets.SetView方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveAssignedRoles

import com.google.common.collect.Sets; //导入方法依赖的package包/类
@Transactional
public void saveAssignedRoles(String userId, Set<Role> newRoles) {
    Set<Role> oldRoles = getAssignedRoles(userId);

    Sets.SetView<Role> removedRoles = Sets.difference(oldRoles, newRoles);
    Sets.SetView<Role> addedRoles = Sets.difference(newRoles, oldRoles);

    removedRoles.forEach(role -> {
        store.deleteRole(userId, role);
        logger.logEvent(new RoleDelEvent(Instant.now(), userId, role.getId(), role.getName()));
    });

    addedRoles.forEach(role -> {
        store.addRole(userId, role);
        logger.logEvent(new RoleAddEvent(Instant.now(), userId, role.getId(), role.getName()));
    });
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:18,代码来源:AssignedRoleService.java

示例2: clusterChanged

import com.google.common.collect.Sets; //导入方法依赖的package包/类
@Override
public void clusterChanged(ClusterChangedEvent event) {
    if (!event.metaDataChanged()) {
        return;
    }

    Set<String> newCurrentSchemas = getNewCurrentSchemas(event.state().metaData());
    synchronized (schemas) {
        Sets.SetView<String> nonBuiltInSchemas = Sets.difference(schemas.keySet(), builtInSchemas.keySet());
        Set<String> deleted = Sets.difference(nonBuiltInSchemas, newCurrentSchemas).immutableCopy();
        Set<String> added = Sets.difference(newCurrentSchemas, schemas.keySet()).immutableCopy();

        for (String deletedSchema : deleted) {
            try {
                schemas.remove(deletedSchema).close();
            } catch (Exception e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
        for (String addedSchema : added) {
            schemas.put(addedSchema, getCustomSchemaInfo(addedSchema));
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:ReferenceInfos.java

示例3: convertAndValidate

import com.google.common.collect.Sets; //导入方法依赖的package包/类
public Settings convertAndValidate(String type, Optional<GenericProperties> genericProperties, ParameterContext parameterContext) {
    TypeSettings typeSettings = this.typeSettings.get(type);
    if (typeSettings == null) {
        throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Invalid repository type \"%s\"", type));
    }

    Map<String, SettingsApplier> allSettings = typeSettings.all();

    // create string settings applier for all dynamic settings
    Optional<GenericProperties> dynamicProperties = typeSettings.dynamicProperties(genericProperties);
    if (dynamicProperties.isPresent()) {
        // allSettings are immutable by default, copy map
        allSettings = Maps.newHashMap(allSettings);
        for (String key : dynamicProperties.get().properties().keySet()) {
            allSettings.put(key, new SettingsAppliers.StringSettingsApplier(new StringSetting(key, true)));
        }
    }

    // convert and validate all settings
    Settings settings = GenericPropertiesConverter.settingsFromProperties(
            genericProperties, parameterContext, allSettings).build();

    Set<String> names = settings.getAsMap().keySet();
    Sets.SetView<String> missingRequiredSettings = Sets.difference(typeSettings.required().keySet(), names);
    if (!missingRequiredSettings.isEmpty()) {
        throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                "The following required parameters are missing to create a repository of type \"%s\": [%s]",
                type, Joiner.on(", ").join(missingRequiredSettings)));
    }

    return settings;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:33,代码来源:RepositoryParamValidator.java

示例4: execute

import com.google.common.collect.Sets; //导入方法依赖的package包/类
@Override
public void execute(final Berichtgegevens berichtgegevens) {
    // geautoriseerde acties weten we
    final Set<Actie> geautoriseerdeActies = bepaalActiesVanGeautoriseerdeAttributen(berichtgegevens);
    final Set<Actie> geautoriseerdeActiesMetHandelingen = Sets.newHashSet();
    // acties uit de administratieve handelingen
    final Set<AdministratieveHandeling> geautoriseerdeHandelingen = Sets.newHashSet();
    for (final AdministratieveHandeling handeling : berichtgegevens.getPersoonslijst().getAdministratieveHandelingen()) {
        if (berichtgegevens.isMutatiebericht() && !handeling.getId().equals(berichtgegevens.getParameters().getAdministratieveHandeling())) {
            // voor mutatielevering alleen de huidige handeling in acht nemen
            continue;

        }
        final Collection<Actie> acties = handeling.getActies();
        final Sets.SetView<Actie> gedeeldeActies = Sets.intersection(geautoriseerdeActies, Sets.newHashSet(acties));
        if (!gedeeldeActies.isEmpty()) {
            geautoriseerdeHandelingen.add(handeling);
            geautoriseerdeActiesMetHandelingen.addAll(gedeeldeActies);
        }
    }
    // update LeverPersoon met geautoriseerde acties die ook handelingen hebben
    berichtgegevens.setGeautoriseerdeActies(geautoriseerdeActiesMetHandelingen);
    // update LeverPersoon met geautoriseerde handelingen
    berichtgegevens.setGeautoriseerdeHandelingen(geautoriseerdeHandelingen);

    // verantwoordingattributen alleen leveren als de Actie geautoriseerd is
    for (final MetaAttribuut attribuut : berichtgegevens.getGeautoriseerdeAttributen()) {
        if (attribuut.getAttribuutElement().isVerantwoording() && !geautoriseerdeActiesMetHandelingen.contains(attribuut.<Actie>getWaarde())) {
            berichtgegevens.verwijderAutorisatie(attribuut);
        }
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:33,代码来源:VerantwoordingAutorisatieServiceImpl.java

示例5: doPrincipalAttributesAllowServiceAccess

import com.google.common.collect.Sets; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * Verify presence of service required attributes.
 * <ul>
 *     <li>If no required attributes are specified, authz is granted.</li>
 *     <li>If ALL required attributes must be present, and the principal contains all and there is
 *     at least one attribute value that matches the required, authz is granted.</li>
 *     <li>If ALL required attributes don't have to be present, and there is at least
 *     one principal attribute present whose value matches the required, authz is granted.</li>
 *     <li>Otherwise, access is denied</li>
 * </ul>
 * Note that comparison of principal/required attributes is case-sensitive. Exact matches are required
 * for any individual attribute value.
 */
@Override
public boolean doPrincipalAttributesAllowServiceAccess(final String principal, final Map<String, Object> principalAttributes) {
    if (this.requiredAttributes.isEmpty()) {
        LOGGER.debug("No required attributes are specified");
        return true;
    }
    if (principalAttributes.isEmpty()) {
        LOGGER.debug("No principal attributes are found to satisfy attribute requirements");
        return false;
    }

    if (principalAttributes.size() < this.requiredAttributes.size()) {
        LOGGER.debug("The size of the principal attributes that are [{}] does not match requirements, "
                + "which means the principal is not carrying enough data to grant authorization",
                principalAttributes);
        return false;
    }

    final Map<String, Set<String>> requiredAttrs = this.getRequiredAttributes();
    LOGGER.debug("These required attributes [{}] are examined against [{}] before service can proceed.",
            requiredAttrs, principalAttributes);

    final Sets.SetView<String> difference = Sets.intersection(requiredAttrs.keySet(), principalAttributes.keySet());
    final Set<String> copy = difference.immutableCopy();

    if (this.requireAllAttributes && copy.size() < this.requiredAttributes.size()) {
        LOGGER.debug("Not all required attributes are available to the principal");
        return false;
    }

    for (final String key : copy) {
        final Set<String> requiredValues = this.requiredAttributes.get(key);
        final Set<String> availableValues;

        final Object objVal = principalAttributes.get(key);
        if (objVal instanceof Collection) {
            final Collection valCol = (Collection) objVal;
            availableValues = Sets.newHashSet(valCol.iterator());
        } else {
            availableValues = Sets.newHashSet(objVal.toString());
        }

        final Set<?> differenceInValues;
        final Pattern pattern = RegexUtils.concatenate(requiredValues, this.caseInsensitive);
        if (pattern != null) {
            differenceInValues = Sets.filter(availableValues, Predicates.contains(pattern));
        } else {
            differenceInValues = Sets.intersection(availableValues, requiredValues);
        }

        if (!differenceInValues.isEmpty()) {
            LOGGER.info("Principal is authorized to access the service");
            return true;
        }
    }
    LOGGER.info("Principal is denied access as the required attributes for the registered service are missing");
    return false;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:74,代码来源:DefaultRegisteredServiceAccessStrategy.java

示例6: doPrincipalAttributesAllowServiceAccess

import com.google.common.collect.Sets; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * Verify presence of service required attributes.
 * <ul>
 *     <li>If no required attributes are specified, authz is granted.</li>
 *     <li>If ALL required attributes must be present, and the principal contains all and there is
 *     at least one attribute value that matches the required, authz is granted.</li>
 *     <li>If ALL required attributes don't have to be present, and there is at least
 *     one principal attribute present whose value matches the required, authz is granted.</li>
 *     <li>Otherwise, access is denied</li>
 * </ul>
 * Note that comparison of principal/required attributes is case-sensitive. Exact matches are required
 * for any individual attribute value.
 */
@Override
public boolean doPrincipalAttributesAllowServiceAccess(final Map<String, Object> principalAttributes) {
    if (this.requiredAttributes.isEmpty()) {
        logger.debug("No required attributes are specified");
        return true;
    }
    if (principalAttributes.isEmpty()) {
        logger.debug("No principal attributes are found to satisfy attribute requirements");
        return false;
    }

    if (principalAttributes.size() < this.requiredAttributes.size()) {
        logger.debug("The size of the principal attributes that are [{}] does not match requirements, "
                + "which means the principal is not carrying enough data to grant authorization",
                principalAttributes);
        return false;
    }

    final Map<String, Set<String>> requiredAttrs = this.getRequiredAttributes();
    logger.debug("These required attributes [{}] are examined against [{}] before service can proceed.",
            requiredAttrs, principalAttributes);

    final Sets.SetView<String> difference = Sets.intersection(requiredAttrs.keySet(), principalAttributes.keySet());
    final Set<String> copy = difference.immutableCopy();

    if (this.requireAllAttributes && copy.size() < this.requiredAttributes.size()) {
        logger.debug("Not all required attributes are available to the principal");
        return false;
    }

    for (final String key : copy) {
        final Set<?> requiredValues = this.requiredAttributes.get(key);
        final Set<?> availableValues;

        final Object objVal = principalAttributes.get(key);
        if (objVal instanceof Collection) {
            final Collection valCol = (Collection) objVal;
            availableValues = Sets.newHashSet(valCol.toArray());
        } else {
            availableValues = Collections.singleton(objVal);
        }

        final Sets.SetView<?> differenceInValues = Sets.intersection(availableValues, requiredValues);
        if (!differenceInValues.isEmpty()) {
            logger.info("Principal is authorized to access the service");
            return true;
        }
    }
    logger.info("Principal is denied access as the required attributes for the registered service are missing");
    return false;
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:67,代码来源:DefaultRegisteredServiceAccessStrategy.java

示例7: computeTree2Init

import com.google.common.collect.Sets; //导入方法依赖的package包/类
/**
 * @param enclosingClassPath TreePath to class
 * @param state visitor state
 * @return a map from each initializer <em>i</em> to the fields known to be initialized before
 *     <em>i</em> executes
 */
private Multimap<Tree, Element> computeTree2Init(
    TreePath enclosingClassPath, VisitorState state) {
  ClassTree enclosingClass = (ClassTree) enclosingClassPath.getLeaf();
  ImmutableMultimap.Builder<Tree, Element> builder = ImmutableMultimap.builder();
  // NOTE: this set includes both instance and static fields
  Set<Element> initThusFar = new LinkedHashSet<>();
  Set<MethodTree> constructors = new LinkedHashSet<>();
  AccessPathNullnessAnalysis nullnessAnalysis = getNullnessAnalysis(state);
  // NOTE: we assume the members are returned in their syntactic order.  This has held
  // true in our testing
  for (Tree memberTree : enclosingClass.getMembers()) {
    if (memberTree instanceof VariableTree || memberTree instanceof BlockTree) {
      // putAll does not keep a reference to initThusFar, so we don't need to make a copy here
      builder.putAll(memberTree, initThusFar);
    }
    if (memberTree instanceof BlockTree) {
      BlockTree blockTree = (BlockTree) memberTree;
      // add whatever gets initialized here
      TreePath memberPath = new TreePath(enclosingClassPath, memberTree);
      if (blockTree.isStatic()) {
        initThusFar.addAll(
            nullnessAnalysis.getNonnullStaticFieldsAtExit(memberPath, state.context));
      } else {
        initThusFar.addAll(
            nullnessAnalysis.getNonnullFieldsOfReceiverAtExit(memberPath, state.context));
      }
    }
    if (memberTree instanceof MethodTree) {
      MethodTree methodTree = (MethodTree) memberTree;
      if (isConstructor(methodTree)) {
        constructors.add(methodTree);
      }
    }
  }
  // all the initializer blocks have run before any code inside a constructor
  constructors.stream().forEach((c) -> builder.putAll(c, initThusFar));
  Symbol.ClassSymbol classSymbol = ASTHelpers.getSymbol(enclosingClass);
  FieldInitEntities entities = class2Entities.get(classSymbol);
  if (entities.instanceInitializerMethods().size() == 1) {
    MethodTree initMethod = entities.instanceInitializerMethods().iterator().next();
    // collect the fields that may not be initialized by *some* constructor NC
    Set<Symbol> constructorUninitSymbols = class2ConstructorUninit.get(classSymbol);
    // fields initialized after constructors is initThusFar + (nonNullFields - constructorUninit)
    Sets.SetView<Element> initAfterConstructors =
        Sets.union(
            initThusFar,
            Sets.difference(entities.nonnullInstanceFields(), constructorUninitSymbols));
    builder.putAll(initMethod, initAfterConstructors);
  }
  if (entities.staticInitializerMethods().size() == 1) {
    MethodTree staticInitMethod = entities.staticInitializerMethods().iterator().next();
    // constructors aren't relevant here; just use initThusFar
    builder.putAll(staticInitMethod, initThusFar);
  }
  return builder.build();
}
 
开发者ID:uber,项目名称:NullAway,代码行数:63,代码来源:NullAway.java

示例8: doPrincipalAttributesAllowServiceAccess

import com.google.common.collect.Sets; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * Verify presence of service required attributes.
 * <ul>
 *     <li>If no required attributes are specified, authz is granted.</li>
 *     <li>If ALL required attributes must be present, and the principal contains all and there is
 *     at least one attribute value that matches the required, authz is granted.</li>
 *     <li>If ALL required attributes don't have to be present, and there is at least
 *     one principal attribute present whose value matches the required, authz is granted.</li>
 *     <li>Otherwise, access is denied</li>
 * </ul>
 * Note that comparison of principal/required attributes is case-sensitive. Exact matches are required
 * for any individual attribute value.
 */
@Override
public boolean doPrincipalAttributesAllowServiceAccess(final String principal, final Map<String, Object> principalAttributes) {
    if (this.requiredAttributes.isEmpty()) {
        logger.debug("No required attributes are specified");
        return true;
    }
    if (principalAttributes.isEmpty()) {
        logger.debug("No principal attributes are found to satisfy attribute requirements");
        return false;
    }

    if (principalAttributes.size() < this.requiredAttributes.size()) {
        logger.debug("The size of the principal attributes that are [{}] does not match requirements, "
                + "which means the principal is not carrying enough data to grant authorization",
                principalAttributes);
        return false;
    }

    final Map<String, Set<String>> requiredAttrs = this.getRequiredAttributes();
    logger.debug("These required attributes [{}] are examined against [{}] before service can proceed.",
            requiredAttrs, principalAttributes);

    final Sets.SetView<String> difference = Sets.intersection(requiredAttrs.keySet(), principalAttributes.keySet());
    final Set<String> copy = difference.immutableCopy();

    if (this.requireAllAttributes && copy.size() < this.requiredAttributes.size()) {
        logger.debug("Not all required attributes are available to the principal");
        return false;
    }

    for (final String key : copy) {
        final Set<String> requiredValues = this.requiredAttributes.get(key);
        final Set<String> availableValues;

        final Object objVal = principalAttributes.get(key);
        if (objVal instanceof Collection) {
            final Collection valCol = (Collection) objVal;
            availableValues = Sets.newHashSet(valCol.iterator());
        } else {
            availableValues = Sets.newHashSet(objVal.toString());
        }

        final Set<?> differenceInValues;
        final Pattern pattern = RegexUtils.concatenate(requiredValues, this.caseInsensitive);
        if (pattern != null) {
            differenceInValues = Sets.filter(availableValues, Predicates.contains(pattern));
        } else {
            differenceInValues = Sets.intersection(availableValues, requiredValues);
        }

        if (!differenceInValues.isEmpty()) {
            logger.info("Principal is authorized to access the service");
            return true;
        }
    }
    logger.info("Principal is denied access as the required attributes for the registered service are missing");
    return false;
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:74,代码来源:DefaultRegisteredServiceAccessStrategy.java

示例9: testSampleTaskGroupSanity

import com.google.common.collect.Sets; //导入方法依赖的package包/类
@Test
public void testSampleTaskGroupSanity() {
    // Prepare sample group
    //
    /**
     *
     *   |------------------->B------------|
     *   |                                 |
     *   |                                 ↓
     *   F            ------->C----------->A
     *   |            |                    ^
     *   |            |                    |
     *   |------------>E                   |
     *                |                    |
     *                |                    |
     *                ------->D-------------
     */
    final List<String> groupItems = new ArrayList<>();
    TaskGroup group = createSampleTaskGroup("A", "B",
            "C", "D",
            "E", "F",
            groupItems);

    // Invocation of group should invoke all the tasks
    //
    group.invokeAsync(group.newInvocationContext())
            .subscribe(new Action1<Indexable>() {
                @Override
                public void call(Indexable value) {
                    StringIndexable stringIndexable = toStringIndexable(value);
                    Assert.assertTrue(groupItems.contains(stringIndexable.str()));
                    groupItems.remove(stringIndexable.str());
                }
            });

    Assert.assertEquals(0, groupItems.size());

    Map<String, Set<String>> shouldNotSee = new HashMap<>();

    // NotSeen entries for group-1
    shouldNotSee.put("A", new HashSet<String>());
    shouldNotSee.get("A").addAll(Arrays.asList(new String[] {"B", "C", "D", "E", "F"}));

    shouldNotSee.put("B", new HashSet<String>());
    shouldNotSee.get("B").addAll(Arrays.asList(new String[] {"F"}));

    shouldNotSee.put("C", new HashSet<String>());
    shouldNotSee.get("C").addAll(Arrays.asList(new String[] {"E", "F"}));

    shouldNotSee.put("D", new HashSet<String>());
    shouldNotSee.get("D").addAll(Arrays.asList(new String[] {"E", "F"}));

    shouldNotSee.put("E", new HashSet<String>());
    shouldNotSee.get("E").addAll(Arrays.asList(new String[] {"F"}));

    shouldNotSee.put("F", new HashSet<String>());
    shouldNotSee.get("F").addAll(Arrays.asList(new String[] {}));

    Set<String> seen = new HashSet<>();
    // Test invocation order for group
    //
    group.prepareForEnumeration();
    for (TaskGroupEntry<TaskItem> entry = group.getNext(); entry != null; entry = group.getNext()) {
        Sets.SetView<String> common = Sets.intersection(shouldNotSee.get(entry.key()), seen);
        if (common.size() > 0) {
            Assert.assertTrue("The entries " + common + " must be emitted before " + entry.key(), false);
        }
        seen.add(entry.key());
        group.reportCompletion(entry);
    }

    Assert.assertEquals(6, seen.size()); // 1 groups with 6 nodes
    Set<String> expectedToSee = new HashSet<>();
    expectedToSee.addAll(Arrays.asList(new String[]  {"A", "B", "C", "D", "E", "F"}));
    Sets.SetView<String> diff = Sets.difference(seen, expectedToSee);
    Assert.assertEquals(0, diff.size());
}
 
开发者ID:Azure,项目名称:azure-libraries-for-java,代码行数:78,代码来源:ProxyTaskGroupTests.java


注:本文中的com.google.common.collect.Sets.SetView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。