下面列出了java.util.EnumSet#removeAll ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private String overrideSync( String url,
Map<HttpRequests, String> httpPaths,
Map<HttpRequests, Boolean> useIds ) throws IOException
{
StringBuilder builder = new StringBuilder();
for( Entry<HttpRequests,String> entry : httpPaths.entrySet() ){
overrideMethod(url, entry.getValue(),
useIds.get(entry.getKey()), entry.getKey(), builder);
}
EnumSet<HttpRequests> set = EnumSet.allOf(HttpRequests.class);
set.removeAll( httpPaths.keySet());
for( HttpRequests request : set ){
overrideMethod(url, null, null, request, builder);
}
return getModifierdSync(builder.toString());
}
private boolean check(ElementKind kind, Set<Modifier> modifiers) {
if (this.kind != kind)
return false;
if (modifiers == null || modifiers.isEmpty())
return mods.isEmpty();
if (!modifiers.containsAll(this.mods))
return false;
EnumSet<Modifier> copy = EnumSet.copyOf(modifiers);
copy.removeAll(this.mods);
copy.retainAll(ignoreVisibility? EnumSet.of(Modifier.STATIC)
: EnumSet.of(Modifier.STATIC, Modifier.PUBLIC, Modifier.PRIVATE, Modifier.PROTECTED));
return copy.isEmpty();
}
private boolean hasAllTypes(List<Use> uses, EnumSet<UseTypes> types) {
for (Use u : uses) {
if (types.isEmpty()) {
return true;
}
types.removeAll(u.type);
}
return types.isEmpty();
}
private EnumSet<DatadogReporter.Expansion> getExpansions() {
final EnumSet<DatadogReporter.Expansion> expansions;
if (_includeExpansions == null) {
expansions = EnumSet.allOf(DatadogReporter.Expansion.class);
} else {
expansions = EnumSet.copyOf(asExpansions(_includeExpansions));
}
if (_excludeExpansions != null) {
expansions.removeAll(asExpansions(_excludeExpansions));
}
return expansions;
}
/** {@inheritDoc} */
@Override public GridClientData flagsOff(GridClientCacheFlag... flags) throws GridClientException {
if (flags == null || flags.length == 0 || this.flags == null || this.flags.isEmpty())
return this;
EnumSet<GridClientCacheFlag> flagSet = EnumSet.copyOf(this.flags);
flagSet.removeAll(Arrays.asList(flags));
return createProjection(nodes, filter, balancer, new GridClientDataFactory(flagSet));
}
private boolean shouldAllowAclAddOrUpdate(AclEntry aclEntry, SecurityContext securityContext) {
if (SecurityUtil.hasRole(authorizer, securityContext, ROLE_SECURITY_ADMIN)) {
return true;
}
User currentUser = getCurrentUser(securityContext);
// check if the current user is the owner or can grant permission on the specific object
EnumSet<Permission> remaining = aclEntry.getPermissions();
Collection<AclEntry> userAcls = catalogService.listUserAcls(currentUser.getId(), aclEntry.getObjectNamespace(), aclEntry.getObjectId());
for (AclEntry userAcl : userAcls) {
if (userAcl.isOwner()) {
return true;
} else if (userAcl.isGrant()) {
remaining.removeAll(userAcl.getPermissions());
if (remaining.isEmpty()) {
return true;
}
}
}
// check if any roles that the current user belongs to is the owner or can grant
Set<Role> currentUserRoles = catalogService.getAllUserRoles(currentUser);
for (Role role : currentUserRoles) {
Collection<AclEntry> roleAcls = catalogService.listRoleAcls(role.getId(), aclEntry.getObjectNamespace(), aclEntry.getObjectId());
for (AclEntry roleAcl : roleAcls) {
if (roleAcl.isOwner()) {
return true;
} else if (roleAcl.isGrant()) {
remaining.removeAll(roleAcl.getPermissions());
if (remaining.isEmpty()) {
return true;
}
}
}
}
return false;
}
public boolean checkUserPermissions(String objectNamespace, Long objectId, Long userId, EnumSet<Permission> required) {
User user = getUser(userId);
if (user == null) {
return false;
}
EnumSet<Permission> remaining = EnumSet.copyOf(required);
// try direct user acl entry first
List<QueryParam> qps = QueryParam.params(
AclEntry.OBJECT_NAMESPACE, objectNamespace,
AclEntry.OBJECT_ID, String.valueOf(objectId),
AclEntry.SID_TYPE, USER.toString(),
AclEntry.SID_ID, String.valueOf(userId));
Collection<AclEntry> acls = listAcls(qps);
if (acls.size() > 1) {
throw new IllegalStateException("More than one ACL entry for " + qps);
} else if (acls.size() == 1) {
AclEntry aclEntry = acls.iterator().next();
remaining.removeAll(aclEntry.getPermissions());
}
// try role based permissions next
if (!remaining.isEmpty() && user.getRoles() != null) {
qps = QueryParam.params(
AclEntry.OBJECT_NAMESPACE, objectNamespace,
AclEntry.OBJECT_ID, String.valueOf(objectId),
AclEntry.SID_TYPE, AclEntry.SidType.ROLE.toString());
acls = listAcls(qps);
Set<Role> userRoles = getAllUserRoles(user);
Iterator<AclEntry> it = acls.iterator();
while (!remaining.isEmpty() && it.hasNext()) {
AclEntry roleEntry = it.next();
if (userRoles.contains(getRole(roleEntry.getSidId()))) {
remaining.removeAll(roleEntry.getPermissions());
}
}
}
return remaining.isEmpty();
}
public void testIterator(int numThreads, boolean epoll) throws Exception {
int maxRuns = 3;
List<AssertionError> failures = new ArrayList<>();
EnumSet<DatagramMode> remainingFormats = EnumSet.of(
DatagramMode.NETFLOW,
DatagramMode.SYSLOG,
DatagramMode.RAW_DATA
);
for (int i = 0; i < maxRuns; i++) {
try {
EnumSet<DatagramMode> succeededFormats = EnumSet.noneOf(DatagramMode.class);
for (DatagramMode mode : remainingFormats) {
doBasicTest(mode, epoll, numThreads);
succeededFormats.add(mode);
}
remainingFormats.removeAll(succeededFormats);
} catch (Exception ex) {
// we don't expect exceptions to be thrown,
// even when udp messages are lost
throw ex;
} catch (AssertionError failure) {
String msg = "Test failed on iteration: " + i;
LOG.error(msg, failure);
failures.add(failure);
Assert.assertTrue("Interrupted while sleeping", ThreadUtil.sleep(10 * 1000));
}
}
if (failures.size() >= maxRuns) {
throw failures.get(0);
}
}
@Override
public void disable(Set<MenuOption> toDisable) {
Pair<EnumMap<MenuOption, BlipMenuItemDomImpl>, EnumSet<MenuOption>> state = getMenuState();
EnumSet<MenuOption> options = EnumSet.copyOf(state.first.keySet());
EnumSet<MenuOption> selected = state.second;
options.removeAll(toDisable);
selected.removeAll(toDisable);
setMenuState(options, selected);
}
/**
* Returns the set of allowed values for the option.
*
* Implements {@link #convert(String)}.
*/
@Override
public Set<E> convert(String input) throws OptionsParsingException {
if (input.isEmpty()) {
return Collections.emptySet();
}
EnumSet<E> includedSet = EnumSet.noneOf(typeClass);
EnumSet<E> excludedSet = EnumSet.noneOf(typeClass);
for (String value : input.split(",", -1)) {
boolean excludeFlag = value.startsWith("-");
String s = (excludeFlag ? value.substring(1) : value).toUpperCase();
if (!allowedValues.contains(s)) {
throw new OptionsParsingException("Invalid " + prettyEnumName + " filter '" + value +
"' in the input '" + input + "'");
}
(excludeFlag ? excludedSet : includedSet).add(Enum.valueOf(typeClass, s));
}
if (includedSet.isEmpty()) {
includedSet = EnumSet.complementOf(excludedSet);
} else {
includedSet.removeAll(excludedSet);
}
if (includedSet.isEmpty()) {
throw new OptionsParsingException(
Character.toUpperCase(prettyEnumName.charAt(0)) + prettyEnumName.substring(1) +
" filter '" + input + "' definition cannot match any tests");
}
return includedSet;
}
@Override
public void disable(Set<MenuOption> toDisable) {
Pair<EnumMap<MenuOption, BlipMenuItemDomImpl>, EnumSet<MenuOption>> state = getMenuState();
EnumSet<MenuOption> options = EnumSet.copyOf(state.first.keySet());
EnumSet<MenuOption> selected = state.second;
options.removeAll(toDisable);
selected.removeAll(toDisable);
setMenuState(options, selected);
}
/**
* Creates a new {@link ConnectionProfile} based on the added connections.
* @throws IllegalStateException if any of the {@link org.elasticsearch.transport.TransportRequestOptions.Type} enum is missing
*/
public ConnectionProfile build() {
EnumSet<TransportRequestOptions.Type> types = EnumSet.allOf(TransportRequestOptions.Type.class);
types.removeAll(addedTypes);
if (types.isEmpty() == false) {
throw new IllegalStateException("not all types are added for this connection profile - missing types: " + types);
}
return new ConnectionProfile(Collections.unmodifiableList(handles), numConnections, connectTimeout, handshakeTimeout,
pingInterval, compressionEnabled);
}
/**
* Return the set of unsupported JVM features that improve the estimation.
*/
public static EnumSet<JvmFeature> getUnsupportedFeatures() {
EnumSet<JvmFeature> unsupported = EnumSet.allOf(JvmFeature.class);
unsupported.removeAll(supportedFeatures);
return unsupported;
}
private static <E extends Enum<E>> EnumSet<E> makeComplementByHand(Collection<E> collection, Class<E> type) {
EnumSet<E> result = EnumSet.allOf(type);
result.removeAll(collection);
return result;
}
private static <E extends Enum<E>> EnumSet<E> makeComplementByHand(Collection<E> collection, Class<E> type) {
EnumSet<E> result = EnumSet.allOf(type);
result.removeAll(collection);
return result;
}
private static <E extends Enum<E>> EnumSet<E> makeComplementByHand(Collection<E> collection, Class<E> type) {
EnumSet<E> result = EnumSet.allOf(type);
result.removeAll(collection);
return result;
}
private static <E extends Enum<E>> EnumSet<E> makeComplementByHand(Collection<E> collection, Class<E> type) {
EnumSet<E> result = EnumSet.allOf(type);
result.removeAll(collection);
return result;
}
private static <E extends Enum<E>> EnumSet<E> makeComplementByHand(
Collection<E> collection, Class<E> type) {
EnumSet<E> result = EnumSet.allOf(type);
result.removeAll(collection);
return result;
}
/** Return the set of unsupported JVM features that improve the estimation. */
public static EnumSet<JvmFeature> getUnsupportedFeatures() {
EnumSet<JvmFeature> unsupported = EnumSet.allOf(JvmFeature.class);
unsupported.removeAll(supportedFeatures);
return unsupported;
}