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 e) 

Source Link

Document

Creates an enum set initially containing the specified element.

Usage

From source file:com.haulmont.cuba.gui.components.autocomplete.impl.HintProvider.java

public HintResponse requestHint(HintRequest hintRequest) throws RecognitionException {
    AliasRemover aliasRemover = new AliasRemover();
    hintRequest = aliasRemover.replaceAliases(hintRequest);

    String input = hintRequest.getQuery();
    int cursorPos = hintRequest.getPosition();
    Set<InferredType> expectedTypes = hintRequest.getExpectedTypes() == null ? EnumSet.of(InferredType.Any)
            : hintRequest.getExpectedTypes();
    String lastWord = getLastWord(input, cursorPos);
    expectedTypes = narrowExpectedTypes(input, cursorPos, expectedTypes);

    return (!lastWord.contains(".")) ? hintEntityName(lastWord)
            : hintFieldName(lastWord, input, cursorPos, expectedTypes);
}

From source file:edu.uci.ics.hyracks.tests.integration.AbstractMultiNCIntegrationTest.java

protected void runTest(JobSpecification spec) throws Exception {
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info(spec.toJSON().toString(2));
    }/*from ww w.  jav  a 2s.c o m*/
    JobId jobId = hcc.startJob(spec, EnumSet.of(JobFlag.PROFILE_RUNTIME));
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info(jobId.toString());
    }

    int nReaders = 1;

    FrameManager resultDisplayFrameMgr = new FrameManager(spec.getFrameSize());
    VSizeFrame resultFrame = new VSizeFrame(resultDisplayFrameMgr);

    IFrameTupleAccessor frameTupleAccessor = new ResultFrameTupleAccessor();

    IHyracksDataset hyracksDataset = new HyracksDataset(hcc, spec.getFrameSize(), nReaders);
    IHyracksDatasetReader reader = hyracksDataset.createReader(jobId, spec.getResultSetIds().get(0));

    JSONArray resultRecords = new JSONArray();
    ByteBufferInputStream bbis = new ByteBufferInputStream();

    int readSize = reader.read(resultFrame);

    while (readSize > 0) {

        try {
            frameTupleAccessor.reset(resultFrame.getBuffer());
            for (int tIndex = 0; tIndex < frameTupleAccessor.getTupleCount(); tIndex++) {
                int start = frameTupleAccessor.getTupleStartOffset(tIndex);
                int length = frameTupleAccessor.getTupleEndOffset(tIndex) - start;
                bbis.setByteBuffer(resultFrame.getBuffer(), start);
                byte[] recordBytes = new byte[length];
                bbis.read(recordBytes, 0, length);
                resultRecords.put(new String(recordBytes, 0, length));
            }
        } finally {
            try {
                bbis.close();
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }

        readSize = reader.read(resultFrame);
    }

    hcc.waitForCompletion(jobId);
    dumpOutputFiles();
}

From source file:com.datatorrent.stram.InlineAM.java

public boolean run() throws Exception {
    LOG.info("Starting Client");

    // Connect to ResourceManager
    rmClient.start();/*ww  w.  j av a  2s .c o  m*/
    try {
        // Get a new application id
        YarnClientApplication newApp = rmClient.createApplication();
        ApplicationId appId = newApp.getNewApplicationResponse().getApplicationId();

        // Create launch context for app master
        LOG.info("Setting up application submission context for ASM");
        ApplicationSubmissionContext appContext = Records.newRecord(ApplicationSubmissionContext.class);

        // set the application id
        appContext.setApplicationId(appId);
        // set the application name
        appContext.setApplicationName(appName);

        // Set the priority for the application master
        Priority pri = Records.newRecord(Priority.class);
        pri.setPriority(amPriority);
        appContext.setPriority(pri);

        // Set the queue to which this application is to be submitted in the RM
        appContext.setQueue(amQueue);

        // Set up the container launch context for the application master
        ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);
        appContext.setAMContainerSpec(amContainer);

        // unmanaged AM
        appContext.setUnmanagedAM(true);
        LOG.info("Setting unmanaged AM");

        // Submit the application to the applications manager
        LOG.info("Submitting application to ASM");
        rmClient.submitApplication(appContext);

        // Monitor the application to wait for launch state
        ApplicationReport appReport = monitorApplication(appId, EnumSet.of(YarnApplicationState.ACCEPTED));
        ApplicationAttemptId attemptId = appReport.getCurrentApplicationAttemptId();
        LOG.info("Launching application with id: " + attemptId);

        // launch AM
        runAM(attemptId);

        // Monitor the application for end state
        appReport = monitorApplication(appId, EnumSet.of(YarnApplicationState.KILLED,
                YarnApplicationState.FAILED, YarnApplicationState.FINISHED));
        YarnApplicationState appState = appReport.getYarnApplicationState();
        FinalApplicationStatus appStatus = appReport.getFinalApplicationStatus();

        LOG.info("App ended with state: " + appReport.getYarnApplicationState() + " and status: " + appStatus);

        boolean success;
        if (YarnApplicationState.FINISHED == appState && FinalApplicationStatus.SUCCEEDED == appStatus) {
            LOG.info("Application has completed successfully.");
            success = true;
        } else {
            LOG.info("Application did finished unsuccessfully." + " YarnState=" + appState.toString()
                    + ", FinalStatus=" + appStatus.toString());
            success = false;
        }

        return success;
    } finally {
        rmClient.stop();
    }
}

From source file:com.google.i18n.addressinput.common.FormatInterpreter.java

/**
 * Returns the fields that are required to be filled in for this country. This is based upon the
 * "required" field in RegionDataConstants for {@code regionCode}, and handles falling back to
 * the default data if necessary./*ww w . j  a  v  a  2  s. c  om*/
 */
static Set<AddressField> getRequiredFields(String regionCode) {
    Util.checkNotNull(regionCode);
    String requireString = getRequiredString(regionCode);

    EnumSet<AddressField> required = EnumSet.of(AddressField.COUNTRY);
    for (char c : requireString.toCharArray()) {
        required.add(AddressField.of(c));
    }
    return required;
}

From source file:ch.cyberduck.core.googledrive.AbstractDriveListService.java

@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener)
        throws BackgroundException {
    try {//from ww  w .  j a v  a2  s  . co m
        final AttributedList<Path> children = new AttributedList<>();
        String page = null;
        do {
            final FileList list = session.getClient().files().list()
                    // Whether Team Drive items should be included in results
                    .setIncludeTeamDriveItems(true)
                    // Whether the requesting application supports Team Drives
                    .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable"))
                    .setQ(this.query(directory, listener)).setOrderBy("name").setPageToken(page)
                    .setFields(fields).setPageSize(pagesize).execute();
            if (log.isDebugEnabled()) {
                log.debug(String.format("Chunk of %d retrieved", list.getFiles().size()));
            }
            for (File f : list.getFiles()) {
                final PathAttributes properties = this.toAttributes(f);
                if (properties == null) {
                    continue;
                }
                final String filename;
                if (!DRIVE_FOLDER.equals(f.getMimeType())
                        && StringUtils.startsWith(f.getMimeType(), GOOGLE_APPS_PREFIX)) {
                    filename = String.format("%s.%s", PathNormalizer.name(f.getName()),
                            urlFileWriter.getExtension());
                } else {
                    filename = PathNormalizer.name(f.getName());
                }
                if (StringUtils.equals(filename, String.valueOf(Path.DELIMITER))) {
                    continue;
                }
                // Use placeholder type to mark Google Apps document to download as web link file
                final EnumSet<AbstractPath.Type> type = DRIVE_FOLDER.equals(f.getMimeType())
                        ? EnumSet.of(Path.Type.directory)
                        : StringUtils.startsWith(f.getMimeType(), GOOGLE_APPS_PREFIX)
                                ? EnumSet.of(Path.Type.file, Path.Type.placeholder)
                                : EnumSet.of(Path.Type.file);

                final Path child = new Path(directory, filename, type, properties);
                children.add(child);
            }
            listener.chunk(directory, children);
            page = list.getNextPageToken();
            if (log.isDebugEnabled()) {
                log.debug(String.format("Continue with next page token %s", page));
            }
        } while (page != null);
        return children;
    } catch (IOException e) {
        throw new DriveExceptionMappingService().map("Listing directory failed", e, directory);
    }
}

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

private void emitCreateTableMethod(JavaWriter writer) throws IOException {
    writer.emitAnnotation("Override");
    writer.beginMethod("Table", "createTable", EnumSet.of(Modifier.PUBLIC), "Class<? extends RealmObject>",
            "clazz", "ImplicitTransaction", "transaction");
    emitMediatorSwitch(new ProxySwitchStatement() {
        @Override/*from w w  w  . j  av  a 2  s .c o  m*/
        public void emitStatement(int i, JavaWriter writer) throws IOException {
            writer.emitStatement("return %s.initTable(transaction)", proxyClasses.get(i));
        }
    }, writer);
    writer.endMethod();
    writer.emitEmptyLine();
}

From source file:com.linecorp.armeria.server.docs.DocServiceTest.java

@Test
public void testOk() throws Exception {
    final Map<Class<?>, Iterable<EndpointInfo>> serviceMap = new HashMap<>();
    serviceMap.put(HelloService.class, Collections
            .singletonList(EndpointInfo.of("*", "/", "hello", THRIFT_BINARY, SerializationFormat.ofThrift())));
    serviceMap.put(SleepService.class, Collections
            .singletonList(EndpointInfo.of("*", "/", "sleep", THRIFT_BINARY, SerializationFormat.ofThrift())));
    serviceMap.put(FooService.class, Collections
            .singletonList(EndpointInfo.of("*", "/foo", "", THRIFT_COMPACT, EnumSet.of(THRIFT_COMPACT))));
    serviceMap.put(Cassandra.class,
            Arrays.asList(EndpointInfo.of("*", "/cassandra", "", THRIFT_BINARY, EnumSet.of(THRIFT_BINARY)),
                    EndpointInfo.of("*", "/cassandra/debug", "", THRIFT_TEXT, EnumSet.of(THRIFT_TEXT))));
    serviceMap.put(Hbase.class, Collections
            .singletonList(EndpointInfo.of("*", "/hbase", "", THRIFT_BINARY, SerializationFormat.ofThrift())));
    serviceMap.put(OnewayHelloService.class, Collections
            .singletonList(EndpointInfo.of("*", "/oneway", "", THRIFT_BINARY, SerializationFormat.ofThrift())));

    final ObjectMapper mapper = new ObjectMapper();
    final String expectedJson = mapper.writeValueAsString(Specification.forServiceClasses(serviceMap,
            ImmutableMap.of(hello_args.class, SAMPLE_HELLO), SAMPLE_HTTP_HEADERS));

    try (CloseableHttpClient hc = HttpClients.createMinimal()) {
        final HttpGet req = new HttpGet(specificationUri());

        try (CloseableHttpResponse res = hc.execute(req)) {
            assertThat(res.getStatusLine().toString()).isEqualTo("HTTP/1.1 200 OK");
            String responseJson = EntityUtils.toString(res.getEntity());

            // Convert to Map for order-insensitive comparison.
            Map<?, ?> actual = mapper.readValue(responseJson, Map.class);
            Map<?, ?> expected = mapper.readValue(expectedJson, Map.class);
            assertThat(actual).isEqualTo(expected);
        }/* w ww. j  av  a 2 s  .  com*/
    }
}

From source file:ch.cyberduck.core.openstack.SwiftSegmentService.java

public Path getSegmentsDirectory(final Path file, final Long size) {
    return new Path(file.getParent(), String.format("%s%s/%d", prefix, file.getName(), size),
            EnumSet.of(Path.Type.directory));
}

From source file:org.simbasecurity.core.service.config.ConfigurationServiceImpl.java

@Override
public EnumSet<SimbaEventType> getTypesOfInterest() {
    return EnumSet.of(SimbaEventType.CONFIG_PARAM_CHANGED);
}

From source file:ch.cyberduck.core.dav.DAVReadFeatureTest.java

@Test
public void testReadInterrupt() throws Exception {
    final Host host = new Host(new DAVSSLProtocol(), "svn.cyberduck.ch",
            new Credentials(PreferencesFactory.get().getProperty("connection.login.anon.name"), null));
    final DAVSession session = new DAVSession(host);
    final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(),
            new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    service.connect(session, PathCache.empty(), new DisabledCancelCallback());
    final Path test = new Path("/trunk/LICENSE.txt", EnumSet.of(Path.Type.file));
    // Unknown length in status
    final TransferStatus status = new TransferStatus();
    // Read a single byte
    {/* w w  w .j av a  2 s.  c  om*/
        final InputStream in = new DAVReadFeature(session).read(test, status, new DisabledConnectionCallback());
        assertNotNull(in.read());
        in.close();
    }
    {
        final InputStream in = new DAVReadFeature(session).read(test, status, new DisabledConnectionCallback());
        assertNotNull(in);
        in.close();
    }
    session.close();
}