Example usage for java.util EnumSet noneOf

List of usage examples for java.util EnumSet noneOf

Introduction

In this page you can find the example usage for java.util EnumSet noneOf.

Prototype

public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) 

Source Link

Document

Creates an empty enum set with the specified element type.

Usage

From source file:org.apache.hadoop.yarn.server.webapp.AppsBlock.java

protected void fetchData() throws YarnException, IOException, InterruptedException {
    reqAppStates = EnumSet.noneOf(YarnApplicationState.class);
    String reqStateString = $(APP_STATE);
    if (reqStateString != null && !reqStateString.isEmpty()) {
        String[] appStateStrings = reqStateString.split(",");
        for (String stateString : appStateStrings) {
            reqAppStates.add(YarnApplicationState.valueOf(stateString.trim()));
        }/*from   ww w .  j  a v  a 2 s .  co  m*/
    }
    callerUGI = getCallerUGI();
    final GetApplicationsRequest request = GetApplicationsRequest.newInstance(reqAppStates);
    String appsNumStr = $(APPS_NUM);
    if (appsNumStr != null && !appsNumStr.isEmpty()) {
        long appsNum = Long.parseLong(appsNumStr);
        request.setLimit(appsNum);
    }

    String appStartedTimeBegainStr = $(APP_START_TIME_BEGIN);
    long appStartedTimeBegain = 0;
    if (appStartedTimeBegainStr != null && !appStartedTimeBegainStr.isEmpty()) {
        appStartedTimeBegain = Long.parseLong(appStartedTimeBegainStr);
        if (appStartedTimeBegain < 0) {
            throw new BadRequestException("app.started-time.begin must be greater than 0");
        }
    }
    String appStartedTimeEndStr = $(APP_START_TIME_END);
    long appStartedTimeEnd = Long.MAX_VALUE;
    if (appStartedTimeEndStr != null && !appStartedTimeEndStr.isEmpty()) {
        appStartedTimeEnd = Long.parseLong(appStartedTimeEndStr);
        if (appStartedTimeEnd < 0) {
            throw new BadRequestException("app.started-time.end must be greater than 0");
        }
    }
    if (appStartedTimeBegain > appStartedTimeEnd) {
        throw new BadRequestException("app.started-time.end must be greater than app.started-time.begin");
    }
    request.setStartRange(new LongRange(appStartedTimeBegain, appStartedTimeEnd));

    if (callerUGI == null) {
        appReports = appBaseProt.getApplications(request).getApplicationList();
    } else {
        appReports = callerUGI.doAs(new PrivilegedExceptionAction<Collection<ApplicationReport>>() {
            @Override
            public Collection<ApplicationReport> run() throws Exception {
                return appBaseProt.getApplications(request).getApplicationList();
            }
        });
    }
}

From source file:play.modules.swagger.PlayReader.java

private Swagger read(Class<?> cls, boolean readHidden) {

    RouteWrapper routes = RouteFactory.getRoute();

    PlaySwaggerConfig config = PlayConfigFactory.getConfig();

    Api api = cls.getAnnotation(Api.class);

    Map<String, Tag> tags = new HashMap<>();
    List<SecurityRequirement> securities = new ArrayList<>();
    String[] consumes = new String[0];
    String[] produces = new String[0];
    final Set<Scheme> globalSchemes = EnumSet.noneOf(Scheme.class);

    final boolean readable = (api != null && readHidden) || (api != null && !api.hidden());

    // TODO possibly allow parsing also without @Api annotation
    if (readable) {
        // the value will be used as a tag for 2.0 UNLESS a Tags annotation is present
        Set<String> tagStrings = extractTags(api);
        for (String tagString : tagStrings) {
            Tag tag = new Tag().name(tagString);
            tags.put(tagString, tag);/*  ww  w .j  a  v  a 2  s  .c  o m*/
        }
        for (String tagName : tags.keySet()) {
            getSwagger().tag(tags.get(tagName));
        }

        if (!api.produces().isEmpty()) {
            produces = toArray(api.produces());
        }
        if (!api.consumes().isEmpty()) {
            consumes = toArray(api.consumes());
        }
        globalSchemes.addAll(parseSchemes(api.protocols()));
        Authorization[] authorizations = api.authorizations();

        for (Authorization auth : authorizations) {
            if (auth.value() != null && !"".equals(auth.value())) {
                SecurityRequirement security = new SecurityRequirement();
                security.setName(auth.value());
                AuthorizationScope[] scopes = auth.scopes();
                for (AuthorizationScope scope : scopes) {
                    if (scope.scope() != null && !"".equals(scope.scope())) {
                        security.addScope(scope.scope());
                    }
                }
                securities.add(security);
            }
        }

        // parse the method
        Method methods[] = cls.getMethods();
        for (Method method : methods) {
            if (ReflectionUtils.isOverriddenMethod(method, cls)) {
                continue;
            }
            // complete name as stored in route
            String fullMethodName = getFullMethodName(cls, method);

            if (!routes.exists(fullMethodName)) {
                continue;
            }
            Route route = routes.get(fullMethodName);

            String operationPath = getPathFromRoute(route.path(), config.basePath);

            if (operationPath != null) {
                final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class);

                String httpMethod = extractOperationMethod(apiOperation, method, route);
                Operation operation = null;
                if (apiOperation != null || httpMethod != null) {
                    operation = parseMethod(cls, method, route);
                }

                if (operation == null) {
                    continue;
                }

                if (apiOperation != null) {
                    for (Scheme scheme : parseSchemes(apiOperation.protocols())) {
                        operation.scheme(scheme);
                    }
                }

                if (operation.getSchemes() == null || operation.getSchemes().isEmpty()) {
                    for (Scheme scheme : globalSchemes) {
                        operation.scheme(scheme);
                    }
                }
                // can't continue without a valid http method
                if (httpMethod != null) {
                    if (apiOperation != null) {
                        for (String tag : apiOperation.tags()) {
                            if (!"".equals(tag)) {
                                operation.tag(tag);
                                getSwagger().tag(new Tag().name(tag));
                            }
                        }

                        operation.getVendorExtensions()
                                .putAll(BaseReaderUtils.parseExtensions(apiOperation.extensions()));
                    }
                    if (operation.getConsumes() == null) {
                        for (String mediaType : consumes) {
                            operation.consumes(mediaType);
                        }
                    }
                    if (operation.getProduces() == null) {
                        for (String mediaType : produces) {
                            operation.produces(mediaType);
                        }
                    }

                    if (operation.getTags() == null) {
                        for (String tagString : tags.keySet()) {
                            operation.tag(tagString);
                        }
                    }
                    // Only add global @Api securities if operation doesn't already have more specific securities
                    if (operation.getSecurity() == null) {
                        for (SecurityRequirement security : securities) {
                            operation.security(security);
                        }
                    }
                    Path path = getSwagger().getPath(operationPath);
                    if (path == null) {
                        path = new Path();
                        getSwagger().path(operationPath, path);
                    }
                    path.set(httpMethod, operation);
                    try {
                        readImplicitParameters(method, operation, cls);
                    } catch (Exception e) {
                        throw e;
                    }
                }
            }
        }
    }

    return getSwagger();
}

From source file:com.googlecode.ehcache.annotations.key.CachingReflectionHelper.java

/**
 * Scans a class to see if it implements the hashCode, toString and equals methods which are commonly
 * used by key generators//ww w. j a v  a 2s  .  co  m
 */
private boolean doesImplement(final Class<?> elementClass, ImplementsMethod method) {
    final Map<Class<?>, Set<ImplementsMethod>> cache = this.getCache();
    Set<ImplementsMethod> methodCache = cache.get(elementClass);

    if (methodCache == null) {
        methodCache = EnumSet.noneOf(ImplementsMethod.class);
        cache.put(elementClass, methodCache);

        //Create final reference for use by anonymous class
        final Set<ImplementsMethod> implementsSet = methodCache;
        ReflectionUtils.doWithMethods(elementClass, new MethodCallback() {
            public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
                if (implementsSet.size() == 3 || method.getDeclaringClass() == Object.class) {
                    return;
                }

                if (ReflectionUtils.isEqualsMethod(method)) {
                    implementsSet.add(ImplementsMethod.EQUALS);
                } else if (ReflectionUtils.isHashCodeMethod(method)) {
                    implementsSet.add(ImplementsMethod.HASH_CODE);
                } else if (ReflectionUtils.isToStringMethod(method)) {
                    implementsSet.add(ImplementsMethod.TO_STRING);
                }
            }
        });
    }

    return methodCache.contains(method);
}

From source file:com.github.fge.jsonschema.syntax.SyntaxProcessorTest.java

@BeforeMethod
public void initialize() {
    report = spy(new TestProcessingReport());
    final DictionaryBuilder<SyntaxChecker> builder = Dictionary.newBuilder();

    checker = mock(SyntaxChecker.class);
    builder.addEntry(K1, checker);/*from   w w w . j ava 2 s  . co m*/
    builder.addEntry(K2, new SyntaxChecker() {
        @Override
        public EnumSet<NodeType> getValidTypes() {
            return EnumSet.noneOf(NodeType.class);
        }

        @Override
        public void checkSyntax(final Collection<JsonPointer> pointers, final ProcessingReport report,
                final SchemaTree tree) throws ProcessingException {
            report.error(new ProcessingMessage().message(ERRMSG));
        }
    });

    processor = new SyntaxProcessor(builder.freeze());
}

From source file:org.apache.nifi.user.NiFiUser.java

public Set<Authority> getAuthorities() {
    if (authorities == null) {
        authorities = EnumSet.noneOf(Authority.class);
    }//from   w  w w .  j a  v  a 2  s  .c o m
    return authorities;
}

From source file:org.xwiki.security.internal.AbstractRightsObject.java

/**
 * Construct a more manageable java object from the corresponding
 * xwiki object./* w w w . j a  v  a  2s .  com*/
 * @param obj An xwiki rights object.
 * @param resolver A document reference resolver for user and group pages.
 * @param wikiName The name of the current wiki.
 */
protected AbstractRightsObject(BaseObject obj, DocumentReferenceResolver resolver, String wikiName) {
    state = (obj.getIntValue(ALLOW_FIELD_NAME) == 1) ? RightState.ALLOW : RightState.DENY;
    users = new HashSet();
    groups = new HashSet();
    rights = EnumSet.noneOf(Right.class);

    String levels = obj.getStringValue("levels");
    String[] levelsarray = StringUtils.split(levels, " ,|");
    for (String s : levelsarray) {
        Right right = Right.toRight(s);
        if (right != Right.ILLEGAL) {
            rights.add(right);
        }
    }

    for (String u : UsersClass.getListFromString(obj.getStringValue(USERS_FIELD_NAME))) {
        String user = u;
        DocumentReference ref = resolver.resolve(user, wikiName);
        this.users.add(ref);
    }

    for (String g : GroupsClass.getListFromString(obj.getStringValue(GROUPS_FIELD_NAME))) {
        String group = g;
        DocumentReference ref = resolver.resolve(group, wikiName);
        this.groups.add(ref);
    }
}

From source file:net.sourceforge.jencrypt.lib.Utils.java

/**
 * Encode Set of PosixFilePermission objects as two bytes.
 * /*from   w ww .  ja v a 2  s . c  o  m*/
 * @param b
 * @return
 */
public static Set<PosixFilePermission> byteToPerms(byte[] b) {

    Set<PosixFilePermission> result = EnumSet.noneOf(PosixFilePermission.class);
    // @formatter:off      
    if ((b[0] & 1) != 0)
        result.add(OWNER_READ);
    if ((b[0] & 2) != 0)
        result.add(OWNER_WRITE);
    if ((b[0] & 4) != 0)
        result.add(OWNER_EXECUTE);

    if ((b[0] & 8) != 0)
        result.add(GROUP_READ);
    if ((b[0] & 16) != 0)
        result.add(GROUP_WRITE);
    if ((b[0] & 32) != 0)
        result.add(GROUP_EXECUTE);

    if ((b[0] & 64) != 0)
        result.add(OTHERS_READ);
    if ((b[0] & 128) != 0)
        result.add(OTHERS_WRITE);
    if ((b[1] & 1) != 0)
        result.add(OTHERS_EXECUTE);
    // @formatter:on

    return result;
}

From source file:netbeanstypescript.TSSemanticAnalyzer.java

@Override
public void run(Parser.Result t, SchedulerEvent se) {
    Object highlights = TSService.call("getSemanticHighlights", t.getSnapshot().getSource().getFileObject());
    if (highlights == null) {
        result = Collections.emptyMap();
        return;//from   www  .ja v a2  s  .  c o  m
    }
    Map<OffsetRange, Set<ColoringAttributes>> map = new HashMap<>();
    for (JSONObject hi : (List<JSONObject>) highlights) {
        int start = ((Number) hi.get("s")).intValue();
        int length = ((Number) hi.get("l")).intValue();
        EnumSet<ColoringAttributes> atts = EnumSet.noneOf(ColoringAttributes.class);
        for (String attr : (List<String>) hi.get("a")) {
            atts.add(ColoringAttributes.valueOf(attr));
        }
        map.put(new OffsetRange(start, start + length), atts);
    }
    result = map;
}

From source file:org.apache.cassandra.auth.CassandraAuthorizer.java

public Set<Permission> authorize(AuthenticatedUser user, IResource resource) {
    if (user.isSuper())
        return resource.applicablePermissions();

    Set<Permission> permissions = EnumSet.noneOf(Permission.class);
    try {// w  w  w . ja  va 2 s  .  c o  m
        for (RoleResource role : user.getRoles())
            addPermissionsForRole(permissions, resource, role);
    } catch (RequestValidationException e) {
        throw new AssertionError(e); // not supposed to happen
    } catch (RequestExecutionException e) {
        logger.warn("CassandraAuthorizer failed to authorize {} for {}", user, resource);
        throw new RuntimeException(e);
    }

    return permissions;
}

From source file:ch.cyberduck.core.azure.AzureObjectListService.java

@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener)
        throws BackgroundException {
    try {// w w  w .j  a  va2  s  .  c  om
        final CloudBlobContainer container = session.getClient()
                .getContainerReference(containerService.getContainer(directory).getName());
        final AttributedList<Path> children = new AttributedList<Path>();
        ResultContinuation token = null;
        ResultSegment<ListBlobItem> result;
        String prefix = StringUtils.EMPTY;
        if (!containerService.isContainer(directory)) {
            prefix = containerService.getKey(directory);
            if (!prefix.endsWith(String.valueOf(Path.DELIMITER))) {
                prefix += Path.DELIMITER;
            }
        }
        do {
            final BlobRequestOptions options = new BlobRequestOptions();
            result = container.listBlobsSegmented(prefix, false, EnumSet.noneOf(BlobListingDetails.class),
                    PreferencesFactory.get().getInteger("azure.listing.chunksize"), token, options, context);
            for (ListBlobItem object : result.getResults()) {
                if (new Path(object.getUri().getPath(), EnumSet.of(Path.Type.directory)).equals(directory)) {
                    continue;
                }
                final PathAttributes attributes = new PathAttributes();
                if (object instanceof CloudBlob) {
                    final CloudBlob blob = (CloudBlob) object;
                    attributes.setSize(blob.getProperties().getLength());
                    attributes.setModificationDate(blob.getProperties().getLastModified().getTime());
                    attributes.setETag(blob.getProperties().getEtag());
                    if (StringUtils.isNotBlank(blob.getProperties().getContentMD5())) {
                        attributes.setChecksum(Checksum.parse(Hex
                                .encodeHexString(Base64.decodeBase64(blob.getProperties().getContentMD5()))));
                    }
                }
                // A directory is designated by a delimiter character.
                final EnumSet<AbstractPath.Type> types = object instanceof CloudBlobDirectory
                        ? EnumSet.of(Path.Type.directory, Path.Type.placeholder)
                        : EnumSet.of(Path.Type.file);
                final Path child = new Path(directory, PathNormalizer.name(object.getUri().getPath()), types,
                        attributes);
                children.add(child);
            }
            listener.chunk(directory, children);
            token = result.getContinuationToken();
        } while (result.getHasMoreResults());
        return children;
    } catch (StorageException e) {
        throw new AzureExceptionMappingService().map("Listing directory {0} failed", e, directory);
    } catch (URISyntaxException e) {
        throw new NotfoundException(e.getMessage(), e);
    }
}