Example usage for java.util EnumSet allOf

List of usage examples for java.util EnumSet allOf

Introduction

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

Prototype

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

Source Link

Document

Creates an enum set containing all of the elements in the specified element type.

Usage

From source file:com.rjuarez.webapp.tools.TheMovieDatabaseMethod.java

/**
 * Convert a string into an Enum type/*w  w w  . ja v  a  2 s.  com*/
 *
 * @param value
 * @return
 */
public static TheMovieDatabaseMethod fromString(final String value) {
    if (StringUtils.isNotBlank(value)) {
        for (final TheMovieDatabaseMethod method : EnumSet.allOf(TheMovieDatabaseMethod.class)) {
            if (value.equalsIgnoreCase(method.value)) {
                return method;
            }
        }
    }

    // We've not found the type!
    throw new IllegalArgumentException("Method '" + value + "' not recognised");
}

From source file:works.bill.web.beans.SpinUpBean.java

public DateThingGroupSet getDatedThings() {
    DateThingGroupSet dateThingGroupSet = new DateThingGroupSet();

    DatedThing thing6 = new DatedThing("Baz", LocalDate.now().minusDays(2), EnumSet.allOf(MyEnum.class));
    DatedThing thing1 = new DatedThing("Foo", LocalDate.now(), EnumSet.allOf(MyEnum.class));
    DatedThing thing5 = new DatedThing("Bar", LocalDate.now(), EnumSet.allOf(MyEnum.class));
    DatedThing thing2 = new DatedThing("Woo", LocalDate.now(), EnumSet.of(MyEnum.FIRST, MyEnum.SECOND));
    DatedThing thing3 = new DatedThing("Yay", LocalDate.now(), EnumSet.of(MyEnum.SECOND, MyEnum.FIRST));
    DatedThing thing4 = new DatedThing("Hoopla", LocalDate.now().plusDays(3), EnumSet.allOf(MyEnum.class));

    dateThingGroupSet.add(thing1);// w w  w. j  a v a 2s .  c o m
    dateThingGroupSet.add(thing2);
    dateThingGroupSet.add(thing3);
    dateThingGroupSet.add(thing4);
    dateThingGroupSet.add(thing5);
    dateThingGroupSet.add(thing6);

    return dateThingGroupSet;
}

From source file:com.omertron.omdbapi.tools.Param.java

/**
 * Convert a string into an Enum type/*from   ww w .j  a  v a2s.co  m*/
 *
 * @param value
 * @return
 */
public static Param fromString(String value) {
    if (StringUtils.isNotBlank(value)) {
        for (final Param param : EnumSet.allOf(Param.class)) {
            if (value.equalsIgnoreCase(param.value)) {
                return param;
            }
        }
    }

    // We've not found the type!
    throw new IllegalArgumentException("Value '" + value + "' not recognised");
}

From source file:org.apache.metron.dataservices.Main.java

public static void main(String[] args) throws Exception {

    Options options = new Options();

    options.addOption("homeDir", true, "Home directory for the service");

    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);

    Properties configProps = new Properties();

    String homeDir = cmd.getOptionValue("homeDir");

    if (homeDir.endsWith("/")) {
        homeDir = homeDir.substring(0, homeDir.length() - 1);
    }//from   w  w w  . j  a  v a 2  s . c o m

    DOMConfigurator.configure(homeDir + "/log4j.xml");

    logger.warn("DataServices Server starting...");

    File configFile = new File(homeDir + "/config.properties");
    FileReader configFileReader = new FileReader(configFile);
    try {
        configProps.load(configFileReader);

        Option[] cmdOptions = cmd.getOptions();
        for (Option opt : cmdOptions) {
            String argName = opt.getOpt();
            String argValue = opt.getValue();

            configProps.put(argName, argValue);
        }

    } finally {
        if (configFileReader != null) {
            configFileReader.close();
        }
    }

    WebAppContext context = new WebAppContext();

    Injector injector = Guice.createInjector(new DefaultServletModule(configProps),
            new AlertsServerModule(configProps),
            new DefaultShiroWebModule(configProps, context.getServletContext()), new AbstractModule() {

                @Override
                protected void configure() {
                    binder().requireExplicitBindings();
                    bind(GuiceFilter.class);
                    bind(GuiceResteasyBootstrapServletContextListener.class);
                    bind(EnvironmentLoaderListener.class);

                }
            });

    injector.getAllBindings();
    injector.createChildInjector().getAllBindings();

    Server server = new Server(port);

    /***************************************************
     *************** enable SSL ************************
     ***************************************************/

    // HTTP Configuration
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);
    http_config.setRequestHeaderSize(8192);
    http_config.setResponseHeaderSize(8192);
    http_config.setSendServerVersion(true);
    http_config.setSendDateHeader(false);
    // httpConfig.addCustomizer(new ForwardedRequestCustomizer())
    // SSL Context Factory
    SslContextFactory sslContextFactory = new SslContextFactory();

    String sslKeystorePath = configProps.getProperty("sslKeystorePath", "/keystore");
    logger.debug("sslKeystorePath: " + sslKeystorePath);
    sslContextFactory.setKeyStorePath(homeDir + sslKeystorePath);

    String sslKeystorePassword = configProps.getProperty("sslKeystorePassword");
    sslContextFactory.setKeyStorePassword(sslKeystorePassword);

    String sslKeyManagerPassword = configProps.getProperty("sslKeyManagerPassword");
    if (sslKeyManagerPassword != null && !sslKeyManagerPassword.isEmpty()) {
        sslContextFactory.setKeyManagerPassword(sslKeyManagerPassword);
    }

    String sslTruststorePath = configProps.getProperty("sslTruststorePath");
    if (sslTruststorePath != null && !sslTruststorePath.isEmpty()) {
        sslContextFactory.setTrustStorePath(homeDir + sslTruststorePath);
    }

    String sslTruststorePassword = configProps.getProperty("sslTruststorePassword");
    if (sslTruststorePassword != null && !sslTruststorePassword.isEmpty()) {
        sslContextFactory.setTrustStorePassword(sslTruststorePassword);
    }

    sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", "SSL_DHE_RSA_WITH_DES_CBC_SHA",
            "SSL_DHE_DSS_WITH_DES_CBC_SHA", "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
            "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
            "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");

    // SSL HTTP Configuration
    HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());

    // SSL Connector
    ServerConnector sslConnector = new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config));
    sslConnector.setPort(8443);
    server.addConnector(sslConnector);

    FilterHolder guiceFilter = new FilterHolder(injector.getInstance(GuiceFilter.class));

    /** For JSP support.  Used only for testing and debugging for now.  This came come out
     * once the real consumers for this service are in place
     */
    URL indexUri = Main.class.getResource(WEBROOT_INDEX);
    if (indexUri == null) {
        throw new FileNotFoundException("Unable to find resource " + WEBROOT_INDEX);
    }

    // Points to wherever /webroot/ (the resource) is
    URI baseUri = indexUri.toURI();

    // Establish Scratch directory for the servlet context (used by JSP compilation)
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    File scratchDir = new File(tempDir.toString(), "embedded-jetty-jsp");

    if (!scratchDir.exists()) {
        if (!scratchDir.mkdirs()) {
            throw new IOException("Unable to create scratch directory: " + scratchDir);
        }
    }

    // Set JSP to use Standard JavaC always
    System.setProperty("org.apache.jasper.compiler.disablejsr199", "false");

    context.setAttribute("javax.servlet.context.tempdir", scratchDir);
    context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());

    //Ensure the jsp engine is initialized correctly
    JettyJasperInitializer sci = new JettyJasperInitializer();
    ServletContainerInitializersStarter sciStarter = new ServletContainerInitializersStarter(context);
    ContainerInitializer initializer = new ContainerInitializer(sci, null);
    List<ContainerInitializer> initializers = new ArrayList<ContainerInitializer>();
    initializers.add(initializer);

    context.setAttribute("org.eclipse.jetty.containerInitializers", initializers);
    context.addBean(sciStarter, true);

    // Set Classloader of Context to be sane (needed for JSTL)
    // JSP requires a non-System classloader, this simply wraps the
    // embedded System classloader in a way that makes it suitable
    // for JSP to use
    // new URL( "file:///home/prhodes/.m2/repository/javax/servlet/jsp/javax.servlet.jsp-api/2.3.1/javax.servlet.jsp-api-2.3.1.jar" ) 
    ClassLoader jspClassLoader = new URLClassLoader(new URL[] {},
            Thread.currentThread().getContextClassLoader());
    context.setClassLoader(jspClassLoader);

    // Add JSP Servlet (must be named "jsp")
    ServletHolder holderJsp = new ServletHolder("jsp", JspServlet.class);
    holderJsp.setInitOrder(0);
    holderJsp.setInitParameter("logVerbosityLevel", "DEBUG");
    holderJsp.setInitParameter("fork", "false");
    holderJsp.setInitParameter("xpoweredBy", "false");
    holderJsp.setInitParameter("compilerTargetVM", "1.7");
    holderJsp.setInitParameter("compilerSourceVM", "1.7");
    holderJsp.setInitParameter("keepgenerated", "true");
    context.addServlet(holderJsp, "*.jsp");
    //context.addServlet(holderJsp,"*.jspf");
    //context.addServlet(holderJsp,"*.jspx");

    // Add Default Servlet (must be named "default")
    ServletHolder holderDefault = new ServletHolder("default", DefaultServlet.class);
    holderDefault.setInitParameter("resourceBase", baseUri.toASCIIString());
    holderDefault.setInitParameter("dirAllowed", "true");
    context.addServlet(holderDefault, "/");

    /** end "for JSP support */

    context.setResourceBase(baseUri.toASCIIString());

    context.setInitParameter("resteasy.guice.modules",
            "org.apache.metron.dataservices.modules.guice.RestEasyModule");
    context.setInitParameter("resteasy.servlet.mapping.prefix", "/rest");

    context.addEventListener(injector.getInstance(GuiceResteasyBootstrapServletContextListener.class));
    context.addFilter(guiceFilter, "/*", EnumSet.allOf(DispatcherType.class));

    server.setHandler(context);
    server.start();

    AlertsProcessingServer alertsServer = injector.getInstance(AlertsProcessingServer.class);

    alertsServer.startProcessing();

    server.join();
}

From source file:org.rhq.enterprise.server.plugins.alertOperations.PrintTokens.java

/**
 * Do the work and return an xml structure that lists available token classes and
 * tokens along with their descriptions.
 * @return String with an XML representation of the available tokens
 */// w w  w .j  a v  a  2 s.  c om
public static String createTokenDescription() {
    EnumSet<TokenClass> tokenClasses = EnumSet.allOf(TokenClass.class);

    StringBuilder builder = new StringBuilder("<tokenClasses>\n");

    for (TokenClass tc : tokenClasses) {
        builder.append("  <tokenClass name=\"").append(tc.getText()).append("\"").append(" description=\"")
                .append(tc.getDescription()).append(CLOSE);

        Set<Token> tokens = Token.getByTokenClass(tc);
        for (Token token : tokens) {
            builder.append("    <token name=\"").append(token.getName()).append(CLOSE);
            builder.append("      <fullName>").append(token.getText()).append("</fullName>\n");
            builder.append("      <descr>").append(token.getDescription()).append("</descr>\n");
            builder.append("    </token>\n");

        }

        builder.append("  </tokenClass>\n");

    }

    builder.append("</tokenClasses>\n");
    return builder.toString();
}

From source file:io.swagger.inflector.config.DirectionDeserializer.java

@Override
public Set<Configuration.Direction> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.VALUE_FALSE) {
        return EnumSet.noneOf(Configuration.Direction.class);
    } else if (token == JsonToken.VALUE_TRUE) {
        return EnumSet.allOf(Configuration.Direction.class);
    } else if (token == JsonToken.START_ARRAY) {
        final Set<Configuration.Direction> items = EnumSet.noneOf(Configuration.Direction.class);
        while (true) {
            final JsonToken next = jp.nextToken();
            if (next == JsonToken.VALUE_STRING) {
                final String name = jp.getText();
                items.add(Configuration.Direction.valueOf(name));
            } else if (next == JsonToken.END_ARRAY) {
                return items;
            } else {
                break;
            }/*from w  w  w  .j  av  a 2 s.c o  m*/
        }
    }
    throw ctxt.mappingException(Configuration.Direction.class);
}

From source file:org.ala.util.RankingType.java

public static Set<RankingType> getAll() {
    return EnumSet.allOf(RankingType.class);
}

From source file:com.zhihu.matisse.MimeType.java

public static Set<MimeType> ofAll() {
    return EnumSet.allOf(MimeType.class);
}

From source file:org.n52.geolabel.server.StaticLabelIT.java

@Test
public void testStaticAllFactesAvailable()
        throws MalformedURLException, IOException, XpathException, SAXException {
    String allAvailableSVG = getServerResourceAsString("11111111.svg?size=100");

    performCommonLabelChecks(allAvailableSVG, 100);
    performFacetChecks(allAvailableSVG, EnumSet.allOf(Facet.class));
}

From source file:org.midonet.util.process.ProcessHelper.java

public static RunnerConfiguration newProcess(final String commandLine) {

    return new RunnerConfiguration() {
        DrainTarget drainTarget;/*from  w  w  w .  j a  v  a 2 s .co  m*/
        String procCommandLine = commandLine;
        Map<String, String> envVars = new HashMap<>();

        EnumSet<OutputStreams> streamsToLog = EnumSet.allOf(OutputStreams.class);
        final List<Runnable> exitHandlers = new ArrayList<>(1);

        @Override
        public RunnerConfiguration logOutput(Logger log, String marker, OutputStreams... streams) {
            streamsToLog.clear();

            if (streams.length == 0) {
                streamsToLog = EnumSet.of(OutputStreams.StdOutput);
            } else {
                streamsToLog = EnumSet.noneOf(OutputStreams.class);
                Collections.addAll(streamsToLog, streams);
            }

            drainTarget = DrainTargets.slf4jTarget(log, marker);
            return this;
        }

        public RunnerConfiguration setDrainTarget(DrainTarget drainTarget) {
            this.drainTarget = drainTarget;
            return this;
        }

        @Override
        public RunnerConfiguration setEnvVariables(Map<String, String> vars) {

            this.envVars.putAll(vars);
            return this;
        }

        @Override
        public RunnerConfiguration setEnvVariable(String var, String value) {
            this.envVars.put(var, value);
            return this;
        }

        @Override
        public RunnerConfiguration addExitHandler(Runnable handler) {
            synchronized (exitHandlers) {
                exitHandlers.add(handler);
            }
            return this;
        }

        @Override
        public int runAndWait() {
            Process p = createProcess(true);

            String processName = procCommandLine;

            try {
                if (p != null) {
                    p.waitFor();

                    IOUtils.closeQuietly(p.getInputStream());
                    IOUtils.closeQuietly(p.getErrorStream());
                    IOUtils.closeQuietly(p.getOutputStream());

                    if (p.exitValue() == 0) {
                        log.trace("Process \"{}\" exited with code: {}", processName, p.exitValue());

                    } else {
                        log.debug("Process \"{}\" exited with non zero code: {}", processName, p.exitValue());
                    }
                    return p.exitValue();
                }
            } catch (InterruptedException e) {
                log.error(String.format("Error while launching command: \"%s\"", processName), e);
            }

            return -1;
        }

        public Process run() {
            return createProcess(false);
        }

        @Override
        public RunnerConfiguration withSudo() {
            procCommandLine = "sudo " + procCommandLine;
            return this;
        }

        private Process createProcess(boolean wait) {
            try {
                final Process process = launchProcess();
                if (drainTarget == null) {
                    drainTarget = DrainTargets.noneTarget();
                }

                Runnable exitHandler = new Runnable() {
                    @Override
                    public void run() {
                        try {
                            process.waitFor();
                        } catch (InterruptedException e) {
                        }
                        synchronized (exitHandlers) {
                            for (Runnable handler : exitHandlers) {
                                handler.run();
                            }
                        }
                    }
                };

                ProcessOutputDrainer outputDrainer;

                if (streamsToLog.contains(OutputStreams.StdError)) {
                    outputDrainer = new ProcessOutputDrainer(process, true);
                } else {
                    outputDrainer = new ProcessOutputDrainer(process);
                }

                outputDrainer.drainOutput(drainTarget, wait, exitHandler);

                return process;
            } catch (IOException e) {
                log.error("Error while executing command: \"{}\"", commandLine, e);
            }

            return null;
        }

        private Process launchProcess() throws IOException {

            if (envVars.isEmpty()) {
                return Runtime.getRuntime().exec(procCommandLine);
            } else {
                List<String> param = new ArrayList<>();
                for (Map.Entry<String, String> var : envVars.entrySet()) {
                    param.add(var.getKey() + "=" + var.getValue());
                }
                return Runtime.getRuntime().exec(procCommandLine, param.toArray(new String[param.size()]));

            }
        }
    };
}