Example usage for java.util.concurrent ConcurrentHashMap newKeySet

List of usage examples for java.util.concurrent ConcurrentHashMap newKeySet

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentHashMap newKeySet.

Prototype

public static <K> KeySetView<K, Boolean> newKeySet(int initialCapacity) 

Source Link

Document

Creates a new Set backed by a ConcurrentHashMap from the given type to Boolean.TRUE .

Usage

From source file:com.blackducksoftware.integration.hub.detect.detector.clang.ClangExtractor.java

public Extraction extract(final ClangLinuxPackageManager pkgMgr, final File givenDir, final int depth,
        final ExtractionId extractionId, final File jsonCompilationDatabaseFile) {
    try {/*from   www .  ja  va  2  s .c  o m*/
        logger.info(String.format("Analyzing %s", jsonCompilationDatabaseFile.getAbsolutePath()));
        final File rootDir = fileFinder.findContainingDir(givenDir, depth);
        final File outputDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
        logger.debug(String.format("extract() called; compileCommandsJsonFilePath: %s",
                jsonCompilationDatabaseFile.getAbsolutePath()));
        final Set<File> unManagedDependencyFiles = ConcurrentHashMap.newKeySet(64);
        final List<CompileCommand> compileCommands = CompileCommandsJsonFile
                .parseJsonCompilationDatabaseFile(gson, jsonCompilationDatabaseFile);
        final List<Dependency> bdioComponents = compileCommands.parallelStream()
                .flatMap(compileCommandToDependencyFilePathsConverter(outputDirectory))
                .collect(Collectors.toSet()).parallelStream().filter(StringUtils::isNotBlank).map(File::new)
                .filter(fileIsNewPredicate())
                .flatMap(dependencyFileToLinuxPackagesConverter(rootDir, unManagedDependencyFiles, pkgMgr))
                .collect(Collectors.toSet()).parallelStream()
                .flatMap(linuxPackageToBdioComponentsConverter(pkgMgr)).collect(Collectors.toList());

        final DetectCodeLocation detectCodeLocation = codeLocationAssembler
                .generateCodeLocation(pkgMgr.getDefaultForge(), rootDir, bdioComponents);
        logSummary(bdioComponents, unManagedDependencyFiles);
        return new Extraction.Builder().success(detectCodeLocation).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}

From source file:sx.blah.discord.api.internal.DispatchHandler.java

private void ready(ReadyResponse ready) {
    Discord4J.LOGGER.info(LogMarkers.WEBSOCKET, "Connected to Discord Gateway v{}. Receiving {} guilds.",
            ready.v, ready.guilds.length);

    ws.state = DiscordWS.State.READY;
    ws.hasReceivedReady = true; // Websocket received actual ready event
    if (client.ourUser == null)
        client.ourUser = DiscordUtils.getUserFromJSON(shard, ready.user);
    client.getDispatcher().dispatch(new LoginEvent(shard));

    new RequestBuilder(client).setAsync(true).doAction(() -> {
        ws.sessionId = ready.session_id;

        Set<UnavailableGuildObject> waitingGuilds = ConcurrentHashMap.newKeySet(ready.guilds.length);
        waitingGuilds.addAll(Arrays.asList(ready.guilds));

        final AtomicInteger loadedGuilds = new AtomicInteger(0);
        client.getDispatcher().waitFor((GuildCreateEvent e) -> {
            waitingGuilds.removeIf(g -> g.id.equals(e.getGuild().getStringID()));
            return loadedGuilds.incrementAndGet() >= ready.guilds.length;
        }, (long) Math.ceil(Math.sqrt(2 * ready.guilds.length)), TimeUnit.SECONDS);

        waitingGuilds.forEach(guild -> client.getDispatcher()
                .dispatch(new GuildUnavailableEvent(Long.parseUnsignedLong(guild.id))));
        return true;
    }).andThen(() -> {//from  w  w w.java2 s  .  c o  m
        if (this.shard.getInfo()[0] == 0) { // pms are only sent to shard 0
            for (ChannelObject pmObj : ready.private_channels) {
                IPrivateChannel pm = (IPrivateChannel) DiscordUtils.getChannelFromJSON(shard, null, pmObj);
                shard.privateChannels.put(pm);
            }
        }

        ws.isReady = true;
        client.getDispatcher().dispatch(new ShardReadyEvent(shard)); // All information for this shard has been received
        return true;
    }).execute();
}