List of usage examples for java.util EnumSet of
@SafeVarargs public static <E extends Enum<E>> EnumSet<E> of(E first, E... rest)
From source file:org.eclipse.hono.authorization.impl.InMemoryAuthorizationService.java
@Override public void addPermission(final String subject, final ResourceIdentifier resource, final Permission first, final Permission... rest) { requireNonNull(first, "permission is required"); final EnumSet<Permission> permissions = EnumSet.of(first, rest); addPermission(subject, resource, permissions); }
From source file:io.lavagna.service.ConfigurationRepositoryTest.java
@Test public void findFor() { Map<Key, String> v = configurationRepository .findConfigurationFor(EnumSet.of(Key.TEST_PLACEHOLDER, Key.PERSONA_AUDIENCE)); Assert.assertNull(v.get(Key.TEST_PLACEHOLDER)); Assert.assertNull(v.get(Key.PERSONA_AUDIENCE)); configurationRepository.insert(Key.TEST_PLACEHOLDER, "TEST"); Map<Key, String> v1 = configurationRepository .findConfigurationFor(EnumSet.of(Key.TEST_PLACEHOLDER, Key.PERSONA_AUDIENCE)); Assert.assertEquals("TEST", v1.get(Key.TEST_PLACEHOLDER)); Assert.assertNull(v1.get(Key.PERSONA_AUDIENCE)); }
From source file:ch.cyberduck.cli.CommandLinePathParserTest.java
@Test public void testParseProfile() throws Exception { final ProtocolFactory factory = new ProtocolFactory( new HashSet<>(Collections.singleton(new SwiftProtocol() { @Override//from w ww . j av a 2s. co m public boolean isEnabled() { return true; } }))); final ProfilePlistReader reader = new ProfilePlistReader(factory, new DeserializerFactory(PlistDeserializer.class.getName())); final Profile profile = reader.read(new Local("../profiles/default/Rackspace US.cyberduckprofile")); assertNotNull(profile); final CommandLineParser parser = new PosixParser(); final CommandLine input = parser.parse(new Options(), new String[] {}); assertEquals(new Path("/cdn.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)), new CommandLinePathParser(input, new ProtocolFactory(new HashSet<>(Arrays.asList(new SwiftProtocol(), profile)))) .parse("rackspace://u@cdn.cyberduck.ch/")); assertEquals(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)), new CommandLinePathParser(input, new ProtocolFactory(new HashSet<>(Arrays.asList(new SwiftProtocol(), profile)))) .parse("rackspace:///")); }
From source file:ch.cyberduck.core.spectra.SpectraReadFeatureTest.java
@Test public void testRead() throws Exception { final Host host = new Host(new SpectraProtocol() { @Override//from www. j ava2 s. co m public Scheme getScheme() { return Scheme.http; } }, System.getProperties().getProperty("spectra.hostname"), Integer.valueOf(System.getProperties().getProperty("spectra.port")), new Credentials(System.getProperties().getProperty("spectra.user"), System.getProperties().getProperty("spectra.key"))); final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final byte[] content = new RandomStringGenerator.Builder().build().generate(1000).getBytes(); final TransferStatus status = new TransferStatus().length(content.length); status.setChecksum(new CRC32ChecksumCompute().compute(new ByteArrayInputStream(content), status)); final OutputStream out = new S3WriteFeature(session).write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); out.close(); new SpectraBulkService(session).pre(Transfer.Type.download, Collections.singletonMap(test, status), new DisabledConnectionCallback()); final InputStream in = new SpectraReadFeature(session).read(test, status, new DisabledConnectionCallback()); assertNotNull(in); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length); new StreamCopier(status, status).transfer(in, buffer); assertArrayEquals(content, buffer.toByteArray()); in.close(); new SpectraDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:jgnash.ui.report.compiled.IncomeExpensePieChart.java
private JPanel createPanel() { EnumSet<AccountType> set = EnumSet.of(AccountType.INCOME, AccountType.EXPENSE); JButton refreshButton = new JButton(rb.getString("Button.Refresh")); startField = new DatePanel(); endField = new DatePanel(); showEmptyCheck = new JCheckBox(rb.getString("Label.ShowEmptyAccounts")); showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues")); final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT); Objects.requireNonNull(engine); combo = AccountListComboBox.getParentTypeInstance(engine.getRootAccount(), set); final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now()).minusYears(1); long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart)); startField.setDate(DateUtils.asLocalDate(start)); currentAccount = combo.getSelectedAccount(); JFreeChart chart = createPieChart(currentAccount); chartPanel = new ChartPanel(chart, true, true, true, false, true); // (chart, properties, save, print, zoom, tooltips) FormLayout layout = new FormLayout("p, 4dlu, 70dlu, 8dlu, p, 4dlu, 70dlu, 8dlu, p, 4dlu:g, left:p", "f:d, 3dlu, f:d, 6dlu, f:p:g"); DefaultFormBuilder builder = new DefaultFormBuilder(layout); layout.setRowGroups(new int[][] { { 1, 3 } }); builder.append(combo, 9);/*from w w w .j ava 2 s . co m*/ builder.append(showEmptyCheck); builder.nextLine(); builder.nextLine(); builder.append(rb.getString("Label.StartDate"), startField); builder.append(rb.getString("Label.EndDate"), endField); builder.append(refreshButton); builder.append(showPercentCheck); builder.nextLine(); builder.nextLine(); builder.append(chartPanel, 11); JPanel panel = builder.getPanel(); combo.addActionListener(e -> { setCurrentAccount(combo.getSelectedAccount()); pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate())); }); refreshButton.addActionListener(e -> { setCurrentAccount(currentAccount); pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate())); }); showEmptyCheck.addActionListener(e -> setCurrentAccount(currentAccount)); showPercentCheck.addActionListener(e -> ((PiePlot) chartPanel.getChart().getPlot()) .setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels)); ChartMouseListener mouseListener = new ChartMouseListener() { @Override public void chartMouseClicked(final ChartMouseEvent event) { MouseEvent me = event.getTrigger(); if (me.getID() == MouseEvent.MOUSE_CLICKED && me.getClickCount() == 1) { try { ChartEntity entity = event.getEntity(); // expand sections if interesting, back out if in nothing if (entity instanceof PieSectionEntity) { Account a = (Account) ((PieSectionEntity) entity).getSectionKey(); if (a.getChildCount() > 0) { setCurrentAccount(a); } } else if (entity == null) { Account parent = currentAccount; if (parent == null) { return; } parent = parent.getParent(); if (parent == null || parent instanceof RootAccount) { return; } setCurrentAccount(parent); } } catch (final Exception e) { Logger.getLogger(IncomeExpensePieChart.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e); } } } @Override public void chartMouseMoved(ChartMouseEvent event) { setChartCursor(chartPanel, event.getEntity(), event.getTrigger().getPoint()); } }; chartPanel.addChartMouseListener(mouseListener); return panel; }
From source file:org.vader.ecm.dao.impl.DocumentDaoImplITCase.java
private ExternalParty createExternalParty(ExternalPartyType apmAccountType, String externalId) { final ExternalParty account = new ExternalParty(); account.setExternalId(externalId);/*from w ww . ja v a2 s. c o m*/ account.setExternalPartyType(apmAccountType); account.setGrants(EnumSet.of(Grant.DOCUMENT_READ, Grant.DOCUMENT_WRITE)); entityManager.persist(account); return account; }
From source file:ch.cyberduck.core.s3.S3SearchFeatureTest.java
@Test public void testSearchInDirectory() throws Exception { final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")))); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path workdir = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); workdir.attributes().setRegion("us-east-1"); final String name = new AlphanumericRandomStringService().random(); final Path file = new Path(workdir, name, EnumSet.of(Path.Type.file)); session.getFeature(Touch.class).touch(file, new TransferStatus()); final S3SearchFeature feature = new S3SearchFeature(session); assertTrue(//from w w w . j a va2 s . c o m feature.search(workdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file)); assertTrue(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener()).contains(file)); { final AttributedList<Path> result = feature.search(workdir, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)), new DisabledListProgressListener()); assertTrue(result.contains(file)); } assertFalse(feature.search( new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new SearchFilter(name), new DisabledListProgressListener()).contains(file)); final Path subdir = new S3DirectoryFeature(session, new S3WriteFeature(session)).mkdir( new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null, new TransferStatus()); assertFalse( feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file)); final Path filesubdir = new S3TouchFeature(session).touch( new Path(subdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus()); { final AttributedList<Path> result = feature.search(workdir, new SearchFilter(filesubdir.getName()), new DisabledListProgressListener()); assertNotNull(result.find(new SimplePathPredicate(filesubdir))); assertEquals(subdir, result.find(new SimplePathPredicate(filesubdir)).getParent()); } new S3DefaultDeleteFeature(session).delete(Arrays.asList(file, filesubdir, subdir), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:com.microsoft.azure.storage.queue.CloudQueueEncryptionTests.java
private void doQueueAddUpdateEncryptedMessage(IKey key, DictionaryKeyResolver keyResolver) throws StorageException { String messageStr = UUID.randomUUID().toString(); CloudQueueMessage message = new CloudQueueMessage(messageStr); QueueRequestOptions createOptions = new QueueRequestOptions(); createOptions.setEncryptionPolicy(new QueueEncryptionPolicy(key, null)); // add message this.queue.addMessage(message, 0, 0, createOptions, null); // Retrieve message QueueRequestOptions retrieveOptions = new QueueRequestOptions(); retrieveOptions.setEncryptionPolicy(new QueueEncryptionPolicy(null, keyResolver)); CloudQueueMessage retrMessage = this.queue.retrieveMessage(30, retrieveOptions, null); assertEquals(messageStr, retrMessage.getMessageContentAsString()); // Update message String updatedMessage = UUID.randomUUID().toString(); retrMessage.setMessageContent(updatedMessage); this.queue.updateMessage(retrMessage, 0, EnumSet.of(MessageUpdateFields.CONTENT, MessageUpdateFields.VISIBILITY), createOptions, null); // Retrieve updated message retrMessage = this.queue.retrieveMessage(30, retrieveOptions, null); assertEquals(updatedMessage, retrMessage.getMessageContentAsString()); }
From source file:ch.cyberduck.core.b2.B2LargeUploadWriteFeatureTest.java
@Test public void testWriteLowerMinimumSize() throws Exception { final B2Session session = new B2Session(new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(), new Credentials(System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")))); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final B2LargeUploadWriteFeature feature = new B2LargeUploadWriteFeature(session); final Path container = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final TransferStatus status = new TransferStatus(); status.setLength(-1L);/*from www . j a v a2s .c om*/ final Path file = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final OutputStream out = feature.write(file, status, new DisabledConnectionCallback()); final byte[] content = new RandomStringGenerator.Builder().build().generate(2 * 1024 * 1024) .getBytes("UTF-8"); final ByteArrayInputStream in = new ByteArrayInputStream(content); assertEquals(content.length, IOUtils.copy(in, out)); in.close(); out.close(); assertTrue(new B2FindFeature(session).find(file)); final byte[] compare = new byte[content.length]; final InputStream stream = new B2ReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback()); IOUtils.readFully(stream, compare); stream.close(); assertArrayEquals(content, compare); new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:ch.cyberduck.core.cryptomator.S3TouchFeatureTest.java
@Test public void testTouchLongFilenameEncrypted() throws Exception { final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials( System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret"))); final S3Session session = new S3Session(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path home = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); final Path test = new Path(vault, new RandomStringGenerator.Builder().build().generate(130), EnumSet.of(Path.Type.file)); final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore()); cryptomator.create(session, null, new VaultCredentials("test")); session.withRegistry(/*from w w w . jav a2s .c o m*/ new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator)); new CryptoTouchFeature<StorageObject>(session, new S3TouchFeature(session), new S3WriteFeature(session), cryptomator).touch(test, new TransferStatus()); assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test)); new CryptoDeleteFeature(session, new S3DefaultDeleteFeature(session), cryptomator) .delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }