Example usage for java.util EnumSet of

List of usage examples for java.util EnumSet of

Introduction

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

Prototype

public static <E extends Enum<E>> EnumSet<E> of(E e1, E e2, E e3) 

Source Link

Document

Creates an enum set initially containing the specified elements.

Usage

From source file:ch.cyberduck.core.sds.SDSMissingFileKeysSchedulerFeatureTest.java

@Test
public void testMissingKeys() throws Exception {
    final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
            System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")));
    final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path room = new Path("CD-TEST-ENCRYPTED",
            EnumSet.of(Path.Type.directory, Path.Type.volume, Path.Type.vault));
    final byte[] content = RandomUtils.nextBytes(32769);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);/*w  w w . j a  v a  2  s.c o m*/
    final Path test = new Path(room, UUID.randomUUID().toString(),
            EnumSet.of(Path.Type.file, Path.Type.decrypted));
    final SDSEncryptionBulkFeature bulk = new SDSEncryptionBulkFeature(session);
    bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, status), new DisabledConnectionCallback());
    final CryptoWriteFeature writer = new CryptoWriteFeature(session, new SDSWriteFeature(session));
    final StatusOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    final VersionId version = out.getStatus();
    assertNotNull(version);
    assertTrue(new DefaultFindFeature(session).find(test));
    assertEquals(content.length, new SDSAttributesFinderFeature(session).find(test).getSize());
    final SDSMissingFileKeysSchedulerFeature background = new SDSMissingFileKeysSchedulerFeature(session);
    final List<UserFileKeySetRequest> processed = background.operate(new PasswordCallback() {
        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason,
                final LoginOptions options) throws LoginCanceledException {
            return new VaultCredentials("ahbic3Ae");
        }
    }, test);
    assertFalse(processed.isEmpty());
    boolean found = false;
    for (UserFileKeySetRequest p : processed) {
        if (p.getFileId().equals(Long.parseLong(version.id))) {
            found = true;
            break;
        }
    }
    assertTrue(found);
    new SDSDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:ch.cyberduck.core.sds.triplecrypt.CryptoWriteFeatureTest.java

@Test
public void testWrite() throws Exception {
    final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
            System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")));
    final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path room = new Path("CD-TEST-ENCRYPTED",
            EnumSet.of(Path.Type.directory, Path.Type.volume, Path.Type.vault));
    final byte[] content = RandomUtils.nextBytes(32769);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);//from  w  w w.  ja  v  a  2 s  .c  o m
    final Path test = new Path(room, UUID.randomUUID().toString(),
            EnumSet.of(Path.Type.file, Path.Type.decrypted));
    final SDSEncryptionBulkFeature bulk = new SDSEncryptionBulkFeature(session);
    bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, status), new DisabledConnectionCallback());
    final CryptoWriteFeature writer = new CryptoWriteFeature(session, new SDSWriteFeature(session));
    final StatusOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    final VersionId version = out.getStatus();
    assertNotNull(version);
    assertTrue(new DefaultFindFeature(session).find(test));
    assertEquals(content.length, new SDSAttributesFinderFeature(session).find(test).getSize());
    final byte[] compare = new byte[content.length];
    final InputStream stream = new CryptoReadFeature(session, new SDSReadFeature(session)).read(test,
            new TransferStatus(), new ConnectionCallback() {
                @Override
                public void warn(final Host bookmark, final String title, final String message,
                        final String defaultButton, final String cancelButton, final String preference)
                        throws ConnectionCanceledException {
                    //
                }

                @Override
                public Credentials prompt(final Host bookmark, final String title, final String reason,
                        final LoginOptions options) throws LoginCanceledException {
                    return new VaultCredentials("ahbic3Ae");
                }
            });
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new SDSDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();
}

From source file:com.streamsets.pipeline.stage.origin.udp.BaseUDPSourceTest.java

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);/*from  w ww  .  java2s  .  co m*/

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

From source file:de.appsolve.padelcampus.controller.ranking.RankingController.java

@RequestMapping("{participantUUID}/history")
public ModelAndView getRankingHistory(@PathVariable() String participantUUID) throws JsonProcessingException {
    Participant participant = participantDAO.findByUUID(participantUUID);
    if (participant == null) {
        throw new ResourceNotFoundException();
    }//w w  w .java 2 s  .c o  m

    LocalDate endDate = LocalDate.now();
    LocalDate startDate = endDate.minusDays(365);
    Map<Gender, Map<Long, BigDecimal>> genderDateRankingMap = new TreeMap<>();
    for (Gender gender : EnumSet.of(Gender.male, Gender.female, Gender.unisex)) {
        List<Ranking> rankings = rankingUtil.getPlayerRanking(gender, participant, startDate, endDate);
        if (rankings != null && !rankings.isEmpty()) {
            Map<Long, BigDecimal> dateRankingMap = new TreeMap<>();
            for (Ranking ranking : rankings) {
                LocalDate date = ranking.getDate();
                Long millis = date.toDateTimeAtStartOfDay().getMillis();
                dateRankingMap.put(millis, ranking.getValue().setScale(0, RoundingMode.HALF_UP));
            }
            genderDateRankingMap.put(gender, dateRankingMap);
        }
    }
    ModelAndView mav = new ModelAndView(getPath() + "ranking/history");
    mav.addObject("Participant", participant);
    mav.addObject("GenderDateRankingMap", genderDateRankingMap);
    mav.addObject("ChartMap", objectMapper.writeValueAsString(genderDateRankingMap));
    return mav;
}

From source file:com.cloudera.impala.authorization.AuthorizationChecker.java

/**
 * Authorizes the PrivilegeRequest, throwing an Authorization exception if
 * the user does not have sufficient privileges.
 *///from   w  ww.j a  va2  s.c om
public void checkAccess(User user, PrivilegeRequest privilegeRequest) throws AuthorizationException {
    Preconditions.checkNotNull(privilegeRequest);

    if (!hasAccess(user, privilegeRequest)) {
        if (privilegeRequest.getAuthorizeable() instanceof AuthorizeableFn) {
            throw new AuthorizationException(String
                    .format("User '%s' does not have privileges to CREATE/DROP functions.", user.getName()));
        }

        Privilege privilege = privilegeRequest.getPrivilege();
        if (EnumSet.of(Privilege.ANY, Privilege.ALL, Privilege.VIEW_METADATA).contains(privilege)) {
            throw new AuthorizationException(String.format("User '%s' does not have privileges to access: %s",
                    user.getName(), privilegeRequest.getName()));
        } else {
            throw new AuthorizationException(
                    String.format("User '%s' does not have privileges to execute '%s' on: %s", user.getName(),
                            privilege, privilegeRequest.getName()));
        }
    }
}

From source file:com.github.fge.jsonschema.syntax.checkers.AbstractSyntaxCheckerTest.java

@Test(dataProvider = "invalidTypes")
public void syntaxCheckingFailsOnInvalidTypes(final JsonNode node) throws ProcessingException {
    final ObjectNode schema = FACTORY.objectNode();
    schema.put(KEYWORD, node);//from w  w  w . j  a  v a 2s.c o  m
    final SchemaTree tree = new CanonicalSchemaTree(schema);

    final AbstractSyntaxChecker checker = spy(new DummyChecker());
    final ProcessingReport report = mock(ProcessingReport.class);

    final ArgumentCaptor<ProcessingMessage> captor = ArgumentCaptor.forClass(ProcessingMessage.class);

    checker.checkSyntax(null, report, tree);
    verify(report).error(captor.capture());
    verify(checker, never()).checkValue(null, report, tree);

    final ProcessingMessage msg = captor.getValue();
    assertMessage(msg).hasField("keyword", KEYWORD).hasField("schema", tree)
            .hasMessage(BUNDLE.getString("incorrectType")).hasField("domain", "syntax")
            .hasField("expected", EnumSet.of(ARRAY, INTEGER, STRING))
            .hasField("found", NodeType.getNodeType(node));
}

From source file:io.realm.processor.RealmProxyMediatorGenerator.java

private void emitFields(JavaWriter writer) throws IOException {
    writer.emitField("List<Class<? extends RealmObject>>", "MODEL_CLASSES",
            EnumSet.of(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL));
    writer.beginInitializer(true);//from   w  ww.j a va 2 s. c o  m
    writer.emitStatement(
            "List<Class<? extends RealmObject>> modelClasses = new ArrayList<Class<? extends RealmObject>>()");
    for (String clazz : simpleModelClasses) {
        writer.emitStatement("modelClasses.add(%s.class)", clazz);
    }
    writer.emitStatement("MODEL_CLASSES = Collections.unmodifiableList(modelClasses)");
    writer.endInitializer();
    writer.emitEmptyLine();
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.BasicSyntaxCheckerTest.java

@Test(dataProvider = "invalidTypes")
public void syntaxCheckingFailsOnInvalidTypes(final JsonNode node) throws ProcessingException {
    final NodeType type = NodeType.getNodeType(node);
    final ObjectNode schema = FACTORY.objectNode();
    schema.put(KEYWORD, node);/*w w w  .  j  a  v a  2 s.  c  o  m*/
    final SchemaTree tree = new CanonicalSchemaTree(SchemaKey.anonymousKey(), schema);

    final AbstractSyntaxChecker checker = spy(new DummyChecker());
    final ProcessingReport report = mock(ProcessingReport.class);

    final ArgumentCaptor<ProcessingMessage> captor = ArgumentCaptor.forClass(ProcessingMessage.class);

    checker.checkSyntax(null, BUNDLE, report, tree);
    verify(report).error(captor.capture());
    verify(checker, never()).checkValue(null, BUNDLE, report, tree);

    final ProcessingMessage msg = captor.getValue();
    assertMessage(msg).hasField("keyword", KEYWORD).hasField("schema", tree)
            .hasMessage(BUNDLE.printf("common.incorrectType", type, VALID_TYPES)).hasField("domain", "syntax")
            .hasField("expected", EnumSet.of(ARRAY, INTEGER, STRING))
            .hasField("found", NodeType.getNodeType(node));
}

From source file:fi.helsinki.opintoni.config.WebConfigurer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    log.info("Web application configuration, using profiles: {}", Arrays.toString(env.getActiveProfiles()));
    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD,
            DispatcherType.ASYNC);/*from  w ww. jav  a  2s .  c  om*/
    if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT, Constants.SPRING_PROFILE_QA,
            Constants.SPRING_PROFILE_DEMO, Constants.SPRING_PROFILE_PRODUCTION)) {
        initMetrics(servletContext, dispatcherTypes);

        // Forces browser to send cookies with HTTPS connection only
        servletContext.getSessionCookieConfig().setSecure(true);
    }

    servletContext.getSessionCookieConfig().setName(Constants.SESSION_COOKIE_NAME);
    servletContext.getSessionCookieConfig().setDomain(appConfiguration.get("cookieDomain"));

    log.info("Web application fully configured");
}

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

public void exportData(OutputStream os) throws IOException {
    try (ZipOutputStream zf = new ZipOutputStream(os);
            OutputStreamWriter osw = new OutputStreamWriter(zf, StandardCharsets.UTF_8)) {
        writeEntry("config.json", configurationRepository.findAll(), zf, osw);
        writeEntry("users.json", userRepository.findAll(), zf, osw);
        writeEntry("permissions.json", permissionService.findAllRolesAndRelatedPermissionWithUsers(), zf, osw);

        exportFiles(zf, osw);/*from   w  w w. jav a 2  s .  c  o m*/

        for (Project p : projectService.findAll()) {
            exportProject(zf, osw, p);
        }

        //
        final int amountPerPage = 100;
        int pages = (eventRepository.count() + amountPerPage - 1) / amountPerPage;

        writeEntry("events-page-count.json", pages, zf, osw);
        for (int i = 0; i < pages; i++) {
            writeEntry("events-" + i + ".json", toEventFull(eventRepository.find(i * 100, 100)), zf, osw);
        }
        //
        writeEntry("card-data-types-order.json",
                cardDataRepository.findAllByTypes(
                        EnumSet.of(CardType.ACTION_LIST, CardType.ACTION_CHECKED, CardType.ACTION_UNCHECKED)),
                zf, osw);
    }
}