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:org.jboss.as.test.integration.logging.handlers.SocketHandlerTestCase.java

@Test
public void testTlsSocket() throws Exception {
    final KeyStore clientTrustStore = loadKeyStore();
    final KeyStore serverKeyStore = loadKeyStore();

    createKeyStoreTrustStore(serverKeyStore, clientTrustStore);
    final Path clientTrustFile = createTemporaryKeyStoreFile(clientTrustStore, "client-trust-store.jks");
    final Path serverCertFile = createTemporaryKeyStoreFile(serverKeyStore, "server-cert-store.jks");
    // Create a TCP server and start it
    try (JsonLogServer server = JsonLogServer.createTlsServer(PORT, serverCertFile, TEST_PASSWORD)) {
        server.start(DFT_TIMEOUT);

        // Add the socket handler and test all levels
        final ModelNode socketHandlerAddress = addSocketHandler("test-log-server", null, "SSL_TCP",
                clientTrustFile);/*from   w ww.  ja va2 s . c o  m*/
        checkLevelsLogged(server, EnumSet.allOf(Logger.Level.class), "Test SSL_TCP all levels.");

        // Change to only allowing INFO and higher messages
        executeOperation(Operations.createWriteAttributeOperation(socketHandlerAddress, "level", "INFO"));
        checkLevelsLogged(server,
                EnumSet.of(Logger.Level.INFO, Logger.Level.WARN, Logger.Level.ERROR, Logger.Level.FATAL),
                "Test SSL_TCP INFO and higher.");
    }
}

From source file:com.vmware.upgrade.progress.DefaultExecutionStateAggregatorTest.java

private List<Mapping<List<ExecutionState>>> computeDepthTwoTripleTransitionStates() {
    Map<ExecutionState, Set<ExecutionState>> stateTransitions = computeAllStateTransitions();
    Set<ExecutionState> states = EnumSet.allOf(ExecutionState.class);

    List<Mapping<List<ExecutionState>>> depthTwoTransitions = new ArrayList<Mapping<List<ExecutionState>>>();

    for (Map.Entry<ExecutionState, Set<ExecutionState>> stateTransitionA : stateTransitions.entrySet()) {
        ExecutionState initialStateA = stateTransitionA.getKey();
        Set<ExecutionState> finalStatesA = stateTransitionA.getValue();
        for (ExecutionState finalStateA : finalStatesA) {
            for (Map.Entry<ExecutionState, Set<ExecutionState>> stateTransitionB : stateTransitions
                    .entrySet()) {//w  ww .  jav a2 s  . c om
                ExecutionState initialStateB = stateTransitionB.getKey();
                Set<ExecutionState> finalStatesB = stateTransitionB.getValue();
                for (ExecutionState finalStateB : finalStatesB) {
                    for (ExecutionState stableState : states) {
                        List<ExecutionState> depthTwoInitialStates = Arrays
                                .asList(new ExecutionState[] { initialStateA, initialStateB, stableState });
                        List<ExecutionState> depthTwoFinalStates = Arrays
                                .asList(new ExecutionState[] { finalStateA, finalStateB, stableState });
                        depthTwoTransitions.add(
                                new Mapping<List<ExecutionState>>(depthTwoInitialStates, depthTwoFinalStates));
                    }
                }
            }
        }
    }

    return depthTwoTransitions;
}

From source file:com.hortonworks.streamline.streams.service.NamespaceCatalogResource.java

@Timed
@POST//from   w ww. j av a  2  s. c  om
@Path("/namespaces")
public Response addNamespace(Namespace namespace, @Context SecurityContext securityContext) {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_ADMIN);
    try {
        String namespaceName = namespace.getName();
        Namespace result = environmentService.getNamespaceByName(namespaceName);
        if (result != null) {
            throw new AlreadyExistsException("Namespace entity already exists with name " + namespaceName);
        }
        Namespace created = environmentService.addNamespace(namespace);
        SecurityUtil.addAcl(authorizer, securityContext, Namespace.NAMESPACE, created.getId(),
                EnumSet.allOf(Permission.class));
        return WSUtils.respondEntity(created, CREATED);
    } catch (ProcessingException ex) {
        throw BadRequestException.of();
    }
}

From source file:org.apache.hadoop.yarn.server.timeline.KeyValueBasedTimelineStore.java

@Override
public synchronized TimelineEntity getEntity(String entityId, String entityType,
        EnumSet<Field> fieldsToRetrieve) {
    if (getServiceStopped()) {
        LOG.info("Service stopped, return null for the storage");
        return null;
    }//from   w  w w.jav a 2  s  . co m
    if (fieldsToRetrieve == null) {
        fieldsToRetrieve = EnumSet.allOf(Field.class);
    }
    TimelineEntity entity = entities.get(new EntityIdentifier(entityId, entityType));
    if (entity == null) {
        return null;
    } else {
        return KeyValueBasedTimelineStoreUtils.maskFields(entity, fieldsToRetrieve);
    }
}

From source file:de.javakaffee.kryoserializers.KryoTest.java

@Test(enabled = true)
public void testEnumSet() throws Exception {
    final EnumSet<?> set = EnumSet.allOf(Gender.class);
    final EnumSet<?> deserialized = deserialize(serialize(set), set.getClass());
    assertDeepEquals(deserialized, set);
}

From source file:com.hortonworks.streamline.streams.cluster.resource.ClusterCatalogResource.java

@Timed
@POST//from www.  j  av a 2 s .c om
@Path("/clusters")
public Response addCluster(Cluster cluster, @Context SecurityContext securityContext) {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_SERVICE_POOL_ADMIN);
    String clusterName = cluster.getName();
    String ambariImportUrl = cluster.getAmbariImportUrl();
    Cluster result = environmentService.getClusterByNameAndImportUrl(clusterName, ambariImportUrl);
    if (result != null) {
        throw EntityAlreadyExistsException.byName(cluster.getNameWithImportUrl());
    }

    Cluster createdCluster = environmentService.addCluster(cluster);
    SecurityUtil.addAcl(authorizer, securityContext, NAMESPACE, createdCluster.getId(),
            EnumSet.allOf(Permission.class));
    return WSUtils.respondEntity(createdCluster, CREATED);
}

From source file:ru.catssoftware.util.concurrent.RunnableStatsManager.java

public void dumpClassStats(final SortBy sortBy) {
    final List<MethodStat> methodStats = new ArrayList<MethodStat>();

    synchronized (this) {
        for (ClassStat classStat : _classStats.values())
            for (MethodStat methodStat : classStat._methodStats)
                if (methodStat._count > 0)
                    methodStats.add(methodStat);
    }//www  .  j  av  a2s  .c  o  m

    if (sortBy != null)
        Collections.sort(methodStats, sortBy._comparator);

    final List<String> lines = new ArrayList<String>();

    lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
    lines.add("<entries>");
    lines.add("\t<!-- This XML contains statistics about execution times. -->");
    lines.add("\t<!-- Submitted results will help the developers to optimize the server. -->");

    final String[][] values = new String[SortBy.VALUES.length][methodStats.size()];
    final int[] maxLength = new int[SortBy.VALUES.length];

    for (int i = 0; i < SortBy.VALUES.length; i++) {
        final SortBy sort = SortBy.VALUES[i];

        for (int k = 0; k < methodStats.size(); k++) {
            final Comparable c = sort.getComparableValueOf(methodStats.get(k));

            final String value;

            if (c instanceof Number)
                value = NumberFormat.getInstance(Locale.ENGLISH).format(((Number) c).longValue());
            else
                value = String.valueOf(c);

            values[i][k] = value;

            maxLength[i] = Math.max(maxLength[i], value.length());
        }
    }

    for (int k = 0; k < methodStats.size(); k++) {
        StringBuilder sb = new StringBuilder();
        sb.append("\t<entry ");

        EnumSet<SortBy> set = EnumSet.allOf(SortBy.class);

        if (sortBy != null) {
            switch (sortBy) {
            case NAME:
            case METHOD:
                appendAttribute(sb, SortBy.NAME, values[SortBy.NAME.ordinal()][k],
                        maxLength[SortBy.NAME.ordinal()]);
                set.remove(SortBy.NAME);

                appendAttribute(sb, SortBy.METHOD, values[SortBy.METHOD.ordinal()][k],
                        maxLength[SortBy.METHOD.ordinal()]);
                set.remove(SortBy.METHOD);
                break;
            default:
                appendAttribute(sb, sortBy, values[sortBy.ordinal()][k], maxLength[sortBy.ordinal()]);
                set.remove(sortBy);
                break;
            }
        }

        for (SortBy sort : SortBy.VALUES)
            if (set.contains(sort))
                appendAttribute(sb, sort, values[sort.ordinal()][k], maxLength[sort.ordinal()]);

        sb.append("/>");

        lines.add(sb.toString());
    }

    lines.add("</entries>");

    PrintStream ps = null;
    try {
        ps = new PrintStream("MethodStats-" + System.currentTimeMillis() + ".log");

        for (String line : lines)
            ps.println(line);
    } catch (Exception e) {
        _log.warn("", e);
    } finally {
        IOUtils.closeQuietly(ps);
    }
}

From source file:com.aionemu.commons.utils.concurrent.RunnableStatsManager.java

@SuppressWarnings("rawtypes")
public static void dumpClassStats(final SortBy sortBy) {
    final List<MethodStat> methodStats = new ArrayList<MethodStat>();

    synchronized (RunnableStatsManager.class) {
        for (ClassStat classStat : classStats.values())
            for (MethodStat methodStat : classStat.methodStats)
                if (methodStat.count > 0)
                    methodStats.add(methodStat);
    }/*from  w  ww  . j a  va 2  s  .c o m*/

    if (sortBy != null)
        Collections.sort(methodStats, sortBy.comparator);

    final List<String> lines = new ArrayList<String>();

    lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
    lines.add("<entries>");
    lines.add("\t<!-- This XML contains statistics about execution times. -->");
    lines.add("\t<!-- Submitted results will help the developers to optimize the server. -->");

    final String[][] values = new String[SortBy.VALUES.length][methodStats.size()];
    final int[] maxLength = new int[SortBy.VALUES.length];

    for (int i = 0; i < SortBy.VALUES.length; i++) {
        final SortBy sort = SortBy.VALUES[i];

        for (int k = 0; k < methodStats.size(); k++) {
            final Comparable c = sort.getComparableValueOf(methodStats.get(k));

            final String value;

            if (c instanceof Number)
                value = NumberFormat.getInstance(Locale.ENGLISH).format(((Number) c).longValue());
            else
                value = String.valueOf(c);

            values[i][k] = value;

            maxLength[i] = Math.max(maxLength[i], value.length());
        }
    }

    for (int k = 0; k < methodStats.size(); k++) {
        StringBuilder sb = new StringBuilder();
        sb.append("\t<entry ");

        EnumSet<SortBy> set = EnumSet.allOf(SortBy.class);

        if (sortBy != null) {
            switch (sortBy) {
            case NAME:
            case METHOD:
                appendAttribute(sb, SortBy.NAME, values[SortBy.NAME.ordinal()][k],
                        maxLength[SortBy.NAME.ordinal()]);
                set.remove(SortBy.NAME);

                appendAttribute(sb, SortBy.METHOD, values[SortBy.METHOD.ordinal()][k],
                        maxLength[SortBy.METHOD.ordinal()]);
                set.remove(SortBy.METHOD);
                break;
            default:
                appendAttribute(sb, sortBy, values[sortBy.ordinal()][k], maxLength[sortBy.ordinal()]);
                set.remove(sortBy);
                break;
            }
        }

        for (SortBy sort : SortBy.VALUES)
            if (set.contains(sort))
                appendAttribute(sb, sort, values[sort.ordinal()][k], maxLength[sort.ordinal()]);

        sb.append("/>");

        lines.add(sb.toString());
    }

    lines.add("</entries>");

    PrintStream ps = null;
    try {
        ps = new PrintStream("MethodStats-" + System.currentTimeMillis() + ".log");

        for (String line : lines)
            ps.println(line);
    } catch (Exception e) {
        log.warn("", e);
    } finally {
        IOUtils.closeQuietly(ps);
    }
}

From source file:org.conqat.engine.bugzilla.BugzillaWebScope.java

/** {@inheritDoc} */
@Override//  ww w.  j av a 2s  .  co  m
public StringSetNode process() throws ConQATException {
    StringSetNode root = new StringSetNode("Bugzilla CRs");
    root.setValue(NodeConstants.HIDE_ROOT, true);
    root.setValue(NodeConstants.COMPARATOR,
            new InvertingComparator<IConQATNode>(NumericIdSorter.NumericIdComparator.getInstance()));

    // if no fields were defined explicitly, use all fields
    // we don't have to do this for statuses as BugzillaWebClient.query()
    // returns Bugs with all statuses if an empty set is supplied
    if (fields.isEmpty()) {
        fields.addAll(EnumSet.allOf(EBugzillaField.class));
    }

    for (EBugzillaField field : fields) {
        NodeUtils.addToDisplayList(root, field.displayName);
    }
    NodeUtils.addToDisplayList(root, customFields.extractSecondList());

    Set<Bug> bugs = obtainBugs();
    getLogger().info("Found " + bugs.size() + " bugs.");

    String baseLinkUrl = StringUtils.stripSuffix("/", serverURL) + "/" + "show_bug.cgi?id=";

    for (Bug bug : bugs) {
        StringSetNode bugNode = new StringSetNode(String.valueOf(bug.getId()));
        root.addChild(bugNode);
        bugNode.setValue(LinkProviderBase.LINK_KEY, baseLinkUrl + bug.getId());
        copyFields(bug, bugNode);
    }

    return root;
}

From source file:com.l2jfree.util.concurrent.RunnableStatsManager.java

public static void dumpClassStats(final SortBy sortBy) {
    final List<MethodStat> methodStats = new ArrayList<MethodStat>();

    synchronized (RunnableStatsManager.class) {
        for (ClassStat classStat : _classStats.values())
            for (MethodStat methodStat : classStat._methodStats)
                if (methodStat._count > 0)
                    methodStats.add(methodStat);
    }//  w w w .  j av a  2 s  .  c  om

    if (sortBy != null)
        Collections.sort(methodStats, sortBy._comparator);

    final List<String> lines = new ArrayList<String>();

    lines.add("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
    lines.add("<entries>");
    lines.add("\t<!-- This XML contains statistics about execution times. -->");
    lines.add("\t<!-- Submitted results will help the developers to optimize the server. -->");

    final String[][] values = new String[SortBy.VALUES.length][methodStats.size()];
    final int[] maxLength = new int[SortBy.VALUES.length];

    for (int i = 0; i < SortBy.VALUES.length; i++) {
        final SortBy sort = SortBy.VALUES[i];

        for (int k = 0; k < methodStats.size(); k++) {
            final Comparable c = sort.getComparableValueOf(methodStats.get(k));

            final String value;

            if (c instanceof Number)
                value = NumberFormat.getInstance(Locale.ENGLISH).format(((Number) c).longValue());
            else
                value = String.valueOf(c);

            values[i][k] = value;

            maxLength[i] = Math.max(maxLength[i], value.length());
        }
    }

    for (int k = 0; k < methodStats.size(); k++) {
        StringBuilder sb = new StringBuilder();
        sb.append("\t<entry ");

        EnumSet<SortBy> set = EnumSet.allOf(SortBy.class);

        if (sortBy != null) {
            switch (sortBy) {
            case NAME:
            case METHOD:
                appendAttribute(sb, SortBy.NAME, values[SortBy.NAME.ordinal()][k],
                        maxLength[SortBy.NAME.ordinal()]);
                set.remove(SortBy.NAME);

                appendAttribute(sb, SortBy.METHOD, values[SortBy.METHOD.ordinal()][k],
                        maxLength[SortBy.METHOD.ordinal()]);
                set.remove(SortBy.METHOD);
                break;
            default:
                appendAttribute(sb, sortBy, values[sortBy.ordinal()][k], maxLength[sortBy.ordinal()]);
                set.remove(sortBy);
                break;
            }
        }

        for (SortBy sort : SortBy.VALUES)
            if (set.contains(sort))
                appendAttribute(sb, sort, values[sort.ordinal()][k], maxLength[sort.ordinal()]);

        sb.append("/>");

        lines.add(sb.toString());
    }

    lines.add("</entries>");

    PrintStream ps = null;
    try {
        ps = new PrintStream("MethodStats-" + System.currentTimeMillis() + ".log");

        for (String line : lines)
            ps.println(line);
    } catch (Exception e) {
        _log.warn("", e);
    } finally {
        IOUtils.closeQuietly(ps);
    }
}