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:de.fiz.ddb.aas.utils.LDAPEngineUtility.java

protected Set<PrivilegeEnum> convertLdapGroupsToOrganizationPrivileges(
        NamingEnumeration<SearchResult> pPrivilegesResult) {
    Set<PrivilegeEnum> vResult = EnumSet.noneOf(PrivilegeEnum.class);
    NamingEnumeration<SearchResult> vSearchResults = pPrivilegesResult;
    try {/*from  w ww .j av a 2s. com*/
        if (pPrivilegesResult != null) {
            PrivilegeEnum p;
            SearchResult sr;
            String vCnPrivileg;
            // construct privileges
            while (vSearchResults.hasMore()) {
                sr = vSearchResults.next();
                vCnPrivileg = (String) sr.getAttributes().get(Constants.ldap_ddbPrivilege_Cn).get();
                p = this.mapToPrivilege(sr.getAttributes(), Constants.ldap_ddbPrivilege_Cn);
                if (p != null) {
                    vResult.add(p);
                } else {
                    LOG.log(Level.WARNING,
                            "Es ist ein nicht existierende Privileg: ''{0}'' im LDAP gespeichert!",
                            new Object[] { vCnPrivileg });
                }
            }
            // -- releases this context's resources immediately, instead of
            // waiting for the garbage collector
            vSearchResults.close();
        }
    } catch (NamingException ne) {
        LOG.log(Level.SEVERE, null, ne);
    } finally {
        // -- releases this context's resources immediately, instead of
        // waiting for the garbage collector
        if (vSearchResults != null) {
            try {
                vSearchResults.close();
            } catch (NamingException ex) {
            }
        }
    }
    return vResult;
}

From source file:nl.strohalm.cyclos.services.elements.ReferenceServiceImpl.java

@Override
public Collection<Nature> getNaturesByGroup(MemberGroup group) {
    final Collection<Nature> natures = EnumSet.noneOf(Nature.class);

    // Check for transaction references
    group = fetchService.fetch(group, Group.Relationships.TRANSFER_TYPES);
    for (final TransferType transferType : group.getTransferTypes()) {
        if (transferType.isRequiresFeedback()) {
            natures.add(Nature.TRANSACTION);
            break;
        }//from   w ww  .  j a  v  a 2  s. co  m
    }

    if (permissionService.hasPermission(group, MemberPermission.REFERENCES_GIVE)) {
        natures.add(Reference.Nature.GENERAL);
    }

    return natures;
}

From source file:com.l2jfree.gameserver.gameobjects.templates.L2NpcTemplate.java

/**
 * Add the class id this npc can teach//from  w ww  .  ja v a2  s. co  m
 * @param classId
 */
public void addTeachInfo(ClassId classId) {
    if (_teachInfo == null)
        _teachInfo = EnumSet.noneOf(ClassId.class);
    _teachInfo.add(classId);
}

From source file:org.nuxeo.ecm.core.opencmis.impl.server.NuxeoObjectData.java

public static AllowableActions getAllowableActions(DocumentModel doc, boolean creation) {
    BaseTypeId baseType = NuxeoTypeHelper.getBaseTypeId(doc);
    boolean isDocument = baseType == BaseTypeId.CMIS_DOCUMENT;
    boolean isFolder = baseType == BaseTypeId.CMIS_FOLDER;
    boolean isRoot = "/".equals(doc.getPathAsString());
    boolean canWrite;
    try {/*from  w  w w  .j av a  2  s .c  o m*/
        canWrite = creation || doc.getCoreSession().hasPermission(doc.getRef(), SecurityConstants.WRITE);
    } catch (ClientException e) {
        canWrite = false;
    }

    Set<Action> set = EnumSet.noneOf(Action.class);
    set.add(Action.CAN_GET_OBJECT_PARENTS);
    set.add(Action.CAN_GET_PROPERTIES);
    if (isFolder) {
        set.add(Action.CAN_GET_DESCENDANTS);
        set.add(Action.CAN_GET_FOLDER_TREE);
        set.add(Action.CAN_GET_CHILDREN);
        if (!isRoot) {
            set.add(Action.CAN_GET_FOLDER_PARENT);
        }
    } else if (isDocument) {
        set.add(Action.CAN_GET_CONTENT_STREAM);
        set.add(Action.CAN_GET_ALL_VERSIONS);
        set.add(Action.CAN_ADD_OBJECT_TO_FOLDER);
        set.add(Action.CAN_REMOVE_OBJECT_FROM_FOLDER);
        try {
            if (doc.isCheckedOut()) {
                set.add(Action.CAN_CHECK_IN);
                set.add(Action.CAN_CANCEL_CHECK_OUT);
            } else {
                set.add(Action.CAN_CHECK_OUT);
            }
        } catch (ClientException e) {
            throw new CmisRuntimeException(e.toString(), e);
        }
    }
    if (isFolder || isDocument) {
        set.add(Action.CAN_GET_RENDITIONS);
    }
    if (canWrite) {
        if (isFolder) {
            set.add(Action.CAN_CREATE_DOCUMENT);
            set.add(Action.CAN_CREATE_FOLDER);
            set.add(Action.CAN_CREATE_RELATIONSHIP);
            set.add(Action.CAN_DELETE_TREE);
        } else if (isDocument) {
            set.add(Action.CAN_SET_CONTENT_STREAM);
            set.add(Action.CAN_DELETE_CONTENT_STREAM);
        }
        set.add(Action.CAN_UPDATE_PROPERTIES);
        if (isFolder && !isRoot || isDocument) {
            // Relationships are not fileable
            set.add(Action.CAN_MOVE_OBJECT);
        }
        if (!isRoot) {
            set.add(Action.CAN_DELETE_OBJECT);
        }
    }
    if (Boolean.FALSE.booleanValue()) {
        // TODO
        set.add(Action.CAN_GET_OBJECT_RELATIONSHIPS);
        set.add(Action.CAN_APPLY_POLICY);
        set.add(Action.CAN_REMOVE_POLICY);
        set.add(Action.CAN_GET_APPLIED_POLICIES);
        set.add(Action.CAN_GET_ACL);
        set.add(Action.CAN_APPLY_ACL);
        set.add(Action.CAN_CREATE_ITEM);
    }

    AllowableActionsImpl aa = new AllowableActionsImpl();
    aa.setAllowableActions(set);
    return aa;
}

From source file:com.dgtlrepublic.anitomyj.Token.java

/**
 * Given a list of tokens finds the first token the passes {@link #checkTokenFlags(Token, EnumSet)}.
 *
 * @param tokens         the list of the tokens to search
 * @param startIdx       the start index of the search. Inclusive.
 * @param shouldContinue a function that returns whether or not we should continue searching
 * @param next           a function that returns the next search index
 * @param flags          the flags the each token should be validated against
 * @return the found token/* w w  w.  j av a 2s.c om*/
 */
private static Result findTokenBase(List<Token> tokens, int startIdx, Function<Integer, Boolean> shouldContinue,
        Function<Integer, Integer> next, TokenFlag... flags) {
    EnumSet<TokenFlag> find = EnumSet.noneOf(TokenFlag.class);
    find.addAll(Arrays.asList(flags));

    for (int i = startIdx; shouldContinue.apply(i); i = next.apply(i)) {
        Token token = tokens.get(i);
        if (checkTokenFlags(token, find)) {
            return new Result(token, i);
        }
    }

    return new Result(null, null);
}

From source file:io.lavagna.service.LavagnaImporter.java

private Map<RoleAndPermission, Set<Permission>> from(Map<String, RoleAndPermissionsWithUsers> from) {
    Map<RoleAndPermission, Set<Permission>> res = new HashMap<>();
    for (Entry<String, RoleAndPermissionsWithUsers> kv : from.entrySet()) {

        RoleAndPermissionsWithUsers rpu = kv.getValue();
        RoleAndPermission rap = new RoleAndPermission(rpu.getName(), rpu.isRemovable(), rpu.isHidden(),
                rpu.isReadOnly(), null);
        if (!res.containsKey(rap)) {
            res.put(rap, EnumSet.noneOf(Permission.class));
        }//from  w  w  w.j  a v a 2 s.  c  om
        for (RoleAndPermission rp : kv.getValue().getRoleAndPermissions()) {
            //we can have null permission enum value if the enum is no more present
            if (rp.getPermission() != null) {
                res.get(rap).add(rp.getPermission());
            }
        }
    }
    return res;
}

From source file:replicatorg.app.gcode.GCodeParser.java

private EnumSet<AxisId> getAxes(GCodeCommand gcode) {
    EnumSet<AxisId> axes = EnumSet.noneOf(AxisId.class);

    if (gcode.hasCode('X'))
        axes.add(AxisId.X);//from  w  w  w .  ja  va  2 s  .c o m
    if (gcode.hasCode('Y'))
        axes.add(AxisId.Y);
    if (gcode.hasCode('Z'))
        axes.add(AxisId.Z);
    if (gcode.hasCode('A'))
        axes.add(AxisId.A);
    if (gcode.hasCode('B'))
        axes.add(AxisId.B);

    return axes;
}

From source file:net.sourceforge.pmd.lang.java.rule.codestyle.UnnecessaryModifierRule.java

@Override
public Object visit(ASTAnnotationMethodDeclaration node, Object data) {
    Set<Modifier> unnecessary = EnumSet.noneOf(Modifier.class);
    if (node.isPublic()) {
        unnecessary.add(Modifier.PUBLIC);
    }/*from   w w  w . ja v  a 2s  . c o m*/
    if (node.isAbstract()) {
        unnecessary.add(Modifier.ABSTRACT);
    }
    checkDeclarationInInterfaceType(data, node, unnecessary);
    return data;
}

From source file:io.sinistral.proteus.server.tools.swagger.Reader.java

@SuppressWarnings("deprecation")
private Swagger read(Class<?> cls, String parentPath, String parentMethod, boolean isSubresource,
        String[] parentConsumes, String[] parentProduces, Map<String, Tag> parentTags,
        List<Parameter> parentParameters, Set<Class<?>> scannedResources) {

    Map<String, Tag> tags = new TreeMap<>();

    List<SecurityRequirement> securities = new ArrayList<>();

    String[] consumes = new String[0];
    String[] produces = new String[0];
    final Set<Scheme> globalSchemes = EnumSet.noneOf(Scheme.class);

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

    boolean hasPathAnnotation = (ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class) != null);
    boolean hasApiAnnotation = (api != null);
    boolean isApiHidden = hasApiAnnotation && api.hidden();

    // class readable only if annotated with ((@Path and @Api) or isSubresource ) - and @Api not hidden
    boolean classReadable = ((hasPathAnnotation && hasApiAnnotation) || isSubresource) && !isApiHidden;

    // with scanAllResources true in config and @Api not hidden scan only if it has also @Path annotation or is subresource
    boolean scanAll = !isApiHidden && config.isScanAllResources() && (hasPathAnnotation || isSubresource);

    // readable if classReadable or scanAll
    boolean readable = classReadable || scanAll;

    if (!readable) {
        return swagger;
    }/*from w  w w. java  2s  . c o  m*/

    // api readable only if @Api present; cannot be hidden because checked in classReadable.

    if (hasApiAnnotation) {
        // 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);
        }
        for (String tagName : tags.keySet()) {
            swagger.tag(tags.get(tagName));
        }

        if (!api.produces().isEmpty()) {
            produces = ReaderUtils.splitContentValues(new String[] { api.produces() });
        }
        if (!api.consumes().isEmpty()) {
            consumes = ReaderUtils.splitContentValues(new String[] { api.consumes() });
        }
        globalSchemes.addAll(parseSchemes(api.protocols()));

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

    if (readable) {
        if (isSubresource) {
            if (parentTags != null) {
                tags.putAll(parentTags);
            }
        }
        // merge consumes, produces
        if (consumes.length == 0 && cls.getAnnotation(Consumes.class) != null) {
            consumes = ReaderUtils.splitContentValues(cls.getAnnotation(Consumes.class).value());
        }
        if (produces.length == 0 && cls.getAnnotation(Produces.class) != null) {
            produces = ReaderUtils.splitContentValues(cls.getAnnotation(Produces.class).value());
        }
        // look for method-level annotated properties

        // handle sub-resources by looking at return type

        final List<Parameter> globalParameters = new ArrayList<Parameter>();

        // look for constructor-level annotated properties
        globalParameters.addAll(ReaderUtils.collectConstructorParameters(cls, swagger));

        // look for field-level annotated properties
        globalParameters.addAll(ReaderUtils.collectFieldParameters(cls, swagger));

        // build class/interface level @ApiResponse list
        ApiResponses classResponseAnnotation = ReflectionUtils.getAnnotation(cls, ApiResponses.class);
        List<ApiResponse> classApiResponses = new ArrayList<ApiResponse>();
        if (classResponseAnnotation != null) {
            classApiResponses.addAll(Arrays.asList(classResponseAnnotation.value()));
        }

        // parse the method
        final javax.ws.rs.Path apiPath = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class);
        JavaType classType = TypeFactory.defaultInstance().constructType(cls);
        BeanDescription bd = new ObjectMapper().getSerializationConfig().introspect(classType);
        Method methods[] = cls.getMethods();
        for (Method method : methods) {
            AnnotatedMethod annotatedMethod = bd.findMethod(method.getName(), method.getParameterTypes());
            if (ReflectionUtils.isOverriddenMethod(method, cls)) {
                continue;
            }
            javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class);

            String operationPath = getPath(apiPath, methodPath, parentPath);
            Map<String, String> regexMap = new LinkedHashMap<>();
            operationPath = PathUtils.parsePath(operationPath, regexMap);

            if (operationPath != null) {
                if (isIgnored(operationPath)) {
                    continue;
                }

                List<String> pathParamNames = new ArrayList<>();

                Matcher m = PATH_PATTERN.matcher(operationPath);
                while (m.find()) {
                    String pathParamName = m.group(1);
                    int bracketIndex = pathParamName.indexOf('[');

                    if (bracketIndex > -1) {
                        pathParamName = pathParamName.substring(0, bracketIndex);
                    }

                    pathParamNames.add(pathParamName);
                }

                final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class);
                String httpMethod = extractOperationMethod(apiOperation, method, SwaggerExtensions.chain());

                Operation operation = null;
                if (apiOperation != null || config.isScanAllResources() || httpMethod != null
                        || methodPath != null) {
                    operation = parseMethod(cls, method, annotatedMethod, globalParameters, classApiResponses,
                            pathParamNames);
                }
                if (operation == null) {
                    continue;
                }
                if (parentParameters != null) {
                    for (Parameter param : parentParameters) {
                        operation.parameter(param);
                    }
                }

                for (Parameter param : operation.getParameters()) {
                    if (regexMap.get(param.getName()) != null) {
                        String pattern = regexMap.get(param.getName());
                        param.setPattern(pattern);
                    }
                }

                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);
                    }
                }

                String[] apiConsumes = consumes;
                if (parentConsumes != null) {
                    Set<String> both = new LinkedHashSet<>(Arrays.asList(apiConsumes));
                    both.addAll(new LinkedHashSet<>(Arrays.asList(parentConsumes)));
                    if (operation.getConsumes() != null) {
                        both.addAll(new LinkedHashSet<String>(operation.getConsumes()));
                    }
                    apiConsumes = both.toArray(new String[both.size()]);
                }

                String[] apiProduces = produces;
                if (parentProduces != null) {
                    Set<String> both = new LinkedHashSet<>(Arrays.asList(apiProduces));
                    both.addAll(new LinkedHashSet<>(Arrays.asList(parentProduces)));
                    if (operation.getProduces() != null) {
                        both.addAll(new LinkedHashSet<String>(operation.getProduces()));
                    }
                    apiProduces = both.toArray(new String[both.size()]);
                }
                final Class<?> subResource = getSubResourceWithJaxRsSubresourceLocatorSpecs(method);
                if (subResource != null && !scannedResources.contains(subResource)) {
                    scannedResources.add(subResource);
                    read(subResource, operationPath, httpMethod, true, apiConsumes, apiProduces, tags,
                            operation.getParameters(), scannedResources);
                    // remove the sub resource so that it can visit it later in another path
                    // but we have a room for optimization in the future to reuse the scanned result
                    // by caching the scanned resources in the reader instance to avoid actual scanning
                    // the the resources again
                    scannedResources.remove(subResource);
                }

                // can't continue without a valid http method
                httpMethod = (httpMethod == null) ? parentMethod : httpMethod;

                if (httpMethod != null) {
                    if (apiOperation != null) {
                        for (String tag : apiOperation.tags()) {
                            if (!"".equals(tag)) {
                                operation.tag(tag);
                                swagger.tag(new Tag().name(tag));
                            }
                        }

                        operation.getVendorExtensions()
                                .putAll(BaseReaderUtils.parseExtensions(apiOperation.extensions()));
                    }

                    if (operation.getConsumes() == null) {
                        for (String mediaType : apiConsumes) {
                            operation.consumes(mediaType);
                        }
                    }
                    if (operation.getProduces() == null) {
                        for (String mediaType : apiProduces) {
                            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 = swagger.getPath(operationPath);
                    if (path == null) {
                        path = new Path();
                        swagger.path(operationPath, path);
                    }
                    path.set(httpMethod, operation);

                    readImplicitParameters(method, operation);

                    readExternalDocs(method, operation);
                }
            }
        }
    }

    List<Tag> swaggerTags = new ArrayList<Tag>(swagger.getTags());

    swaggerTags.sort((a, b) -> {
        return a.getName().compareTo(b.getName());
    });

    swagger.setTags(swaggerTags);

    return swagger;
}

From source file:net.sf.nmedit.nomad.core.NomadLoader.java

private void initLookAndFeel(String lafClassName, String themeClassName, String defaultLafOnPlatform) {
    EnumSet<Platform.OS> defaultLafPlatforms = EnumSet.noneOf(Platform.OS.class);
    {//from   ww  w.  jav  a 2s. c  om
        // remove whitespace + lowercase
        defaultLafOnPlatform = defaultLafOnPlatform.replaceAll("\\s", "").toLowerCase();
        // split comma separated list
        String[] dlop = defaultLafOnPlatform.split(",");
        // check items
        for (String s : dlop) {
            if (s.equals("all")) {
                // on all platforms
                defaultLafPlatforms.addAll(EnumSet.allOf(Platform.OS.class));
                break;
            } else if (s.equals("mac")) {
                defaultLafPlatforms.add(Platform.OS.MacOSFlavor);
            } else if (s.equals("unix")) {
                defaultLafPlatforms.add(Platform.OS.UnixFlavor);
            } else if (s.equals("windows")) {
                defaultLafPlatforms.add(Platform.OS.WindowsFlavor);
            }
        }
    }

    // jgoodies specific properties

    PlasticLookAndFeel.setTabStyle(PlasticLookAndFeel.TAB_STYLE_METAL_VALUE);
    //UIManager.put(Options.POPUP_DROP_SHADOW_ENABLED_KEY, Boolean.FALSE);
    Options.setPopupDropShadowEnabled(false);
    Options.setUseNarrowButtons(true);

    //UIManager.put(Options.PLASTIC_MENU_FONT_KEY, new FontUIResource("Verdana", Font.PLAIN, 9));
    //PlasticLookAndFeel.setFontPolicy(FontPolicies.getDefaultWindowsPolicy());
    /*
            UIManager.put("MenuItem.margin", new InsetsUIResource(2,2,1,2));
            UIManager.put("Menu.margin", new InsetsUIResource(1,2,1,2));
            */
    // set the metal theme

    if (defaultLafPlatforms.contains(Platform.flavor())) {
        // use default LAF on current platform

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Throwable e) {
            Log log = LogFactory.getLog(getClass());
            log.warn("could not set look and feel theme", e);

        }

        if (Platform.isFlavor(Platform.OS.MacOSFlavor)) {
            System.setProperty("apple.laf.useScreenMenuBar", "true");
        }

    } else {
        // use LAF setting

        MetalTheme theme = null;
        if (themeClassName != null) {
            try {
                theme = (MetalTheme) Class.forName(themeClassName).newInstance();
                UIManager.put("Plastic.theme", themeClassName);

                if (theme instanceof PlasticTheme) {
                    PlasticLookAndFeel.setPlasticTheme((PlasticTheme) theme);
                    // PlasticLookAndFeel.setTabStyle(settings.getPlasticTabStyle());
                } else if (theme instanceof MetalTheme) {
                    MetalLookAndFeel.setCurrentTheme(theme);
                }

            } catch (Throwable e) {
                Log log = LogFactory.getLog(getClass());
                log.warn("could not set look and feel theme", e);
            }
        }
        // set the look and feel
        if (lafClassName != null) {
            try {
                LookAndFeel LAF = (LookAndFeel) Class.forName(lafClassName).newInstance();
                // it is very important to set the classloader  
                UIManager.getDefaults().put("ClassLoader", getClass().getClassLoader());
                UIManager.setLookAndFeel(LAF);
            } catch (Throwable e) {
                Log log = LogFactory.getLog(getClass());
                log.warn("could not set custom look and feel", e);
            }
        }
    }

}