Example usage for java.util Map putIfAbsent

List of usage examples for java.util Map putIfAbsent

Introduction

In this page you can find the example usage for java.util Map putIfAbsent.

Prototype

default V putIfAbsent(K key, V value) 

Source Link

Document

If the specified key is not already associated with a value (or is mapped to null ) associates it with the given value and returns null , else returns the current value.

Usage

From source file:org.opendaylight.genius.interfacemanager.renderer.ovs.utilities.SouthboundUtils.java

private static void addTunnelPortToBridge(IfTunnel ifTunnel, InstanceIdentifier<?> bridgeIid, Interface iface,
        String portName, DataBroker dataBroker) {
    LOG.debug("adding tunnel port {} to bridge {}", portName, bridgeIid);

    Class<? extends InterfaceTypeBase> type = TUNNEL_TYPE_MAP.get(ifTunnel.getTunnelInterfaceType());

    if (type == null) {
        LOG.warn("Unknown Tunnel Type obtained while creating interface: {}", iface);
        return;//  ww w.  j  av  a 2  s .co  m
    }

    int vlanId = 0;
    IfL2vlan ifL2vlan = iface.getAugmentation(IfL2vlan.class);
    if (ifL2vlan != null && ifL2vlan.getVlanId() != null) {
        vlanId = ifL2vlan.getVlanId().getValue();
    }

    Map<String, String> options = Maps.newHashMap();

    // Options common to any kind of tunnel
    if (BooleanUtils.isTrue(ifTunnel.isTunnelSourceIpFlow())) {
        options.put(TUNNEL_OPTIONS_LOCAL_IP, TUNNEL_OPTIONS_VALUE_FLOW);
    } else {
        IpAddress localIp = ifTunnel.getTunnelSource();
        options.put(TUNNEL_OPTIONS_LOCAL_IP, String.valueOf(localIp.getValue()));
    }
    if (BooleanUtils.isTrue(ifTunnel.isTunnelRemoteIpFlow())) {
        options.put(TUNNEL_OPTIONS_REMOTE_IP, TUNNEL_OPTIONS_VALUE_FLOW);
    } else {
        IpAddress remoteIp = ifTunnel.getTunnelDestination();
        options.put(TUNNEL_OPTIONS_REMOTE_IP, String.valueOf(remoteIp.getValue()));
    }

    // Specific options for each type of tunnel
    if (!ifTunnel.getTunnelInterfaceType().equals(TunnelTypeMplsOverGre.class)) {
        options.put(TUNNEL_OPTIONS_KEY, TUNNEL_OPTIONS_VALUE_FLOW);
    }
    if (ifTunnel.getTunnelInterfaceType().equals(TunnelTypeVxlanGpe.class)) {
        options.put(TUNNEL_OPTIONS_EXTS, TUNNEL_OPTIONS_VALUE_GPE);
        options.put(TUNNEL_OPTIONS_NSI, TUNNEL_OPTIONS_VALUE_FLOW);
        options.put(TUNNEL_OPTIONS_NSP, TUNNEL_OPTIONS_VALUE_FLOW);
        options.put(TUNNEL_OPTIONS_NSHC1, TUNNEL_OPTIONS_VALUE_FLOW);
        options.put(TUNNEL_OPTIONS_NSHC2, TUNNEL_OPTIONS_VALUE_FLOW);
        options.put(TUNNEL_OPTIONS_NSHC3, TUNNEL_OPTIONS_VALUE_FLOW);
        options.put(TUNNEL_OPTIONS_NSHC4, TUNNEL_OPTIONS_VALUE_FLOW);
        // VxLAN-GPE interfaces will not use the default UDP port to avoid
        // problems with other meshes
        options.put(TUNNEL_OPTIONS_DESTINATION_PORT, TUNNEL_OPTIONS_VALUE_GPE_DESTINATION_PORT);
    }

    if (ifTunnel.getTunnelOptions() != null) {
        for (TunnelOptions tunOpt : ifTunnel.getTunnelOptions()) {
            options.putIfAbsent(tunOpt.getTunnelOption(), tunOpt.getValue());
        }
    }

    addTerminationPoint(bridgeIid, portName, vlanId, type, options, ifTunnel);
}

From source file:org.libreplan.web.limitingresources.LimitingResourceQueueModel.java

private Map<LimitingResourceQueueElement, List<Edge>> bySource(Collection<? extends Edge> incomingEdgesOf) {
    Map<LimitingResourceQueueElement, List<Edge>> result = new HashMap<>();
    for (Edge each : incomingEdgesOf) {
        result.putIfAbsent(each.source, new ArrayList<>());
        result.get(each.source).add(each);
    }/* w  w w .  j ava 2  s. c om*/

    return result;
}

From source file:org.wildfly.security.tool.CredentialStoreCommand.java

@Override
public void execute(String[] args) throws Exception {
    setStatus(GENERAL_CONFIGURATION_ERROR);
    cmdLine = parser.parse(options, args, false);
    setEnableDebug(cmdLine.hasOption(DEBUG_PARAM));
    if (cmdLine.hasOption(HELP_PARAM)) {
        help();//from   www  . j  a v a2 s  .co m
        setStatus(ElytronTool.ElytronToolExitStatus_OK);
        return;
    }

    printDuplicatesWarning(cmdLine);

    String location = cmdLine.getOptionValue(STORE_LOCATION_PARAM);
    if ((cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM)) && location != null
            && !Files.exists(Paths.get(location))) {
        setStatus(GENERAL_CONFIGURATION_ERROR);
        throw ElytronToolMessages.msg.storageFileDoesNotExist(location);
    }
    String csPassword = cmdLine.getOptionValue(CREDENTIAL_STORE_PASSWORD_PARAM);
    String password = csPassword == null ? "" : csPassword;
    String salt = cmdLine.getOptionValue(SALT_PARAM);
    String csType = cmdLine.getOptionValue(CREDENTIAL_STORE_TYPE_PARAM,
            KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE);
    int iterationCount = getArgumentAsInt(cmdLine.getOptionValue(ITERATION_PARAM));
    String entryType = cmdLine.getOptionValue(ENTRY_TYPE_PARAM);
    String otherProviders = cmdLine.getOptionValue(OTHER_PROVIDERS_PARAM);
    String csProvider = cmdLine.getOptionValue(CUSTOM_CREDENTIAL_STORE_PROVIDER_PARAM);
    boolean createStorage = cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM);
    if (createStorage && cmdLine.getArgs().length > 0) {
        setStatus(GENERAL_CONFIGURATION_ERROR);
        throw ElytronToolMessages.msg.noArgumentOption(CREATE_CREDENTIAL_STORE_PARAM);
    }
    boolean printSummary = cmdLine.hasOption(PRINT_SUMMARY_PARAM);
    String secret = cmdLine.getOptionValue(PASSWORD_CREDENTIAL_VALUE_PARAM);

    Map<String, String> implProps = parseCredentialStoreProperties(
            cmdLine.getOptionValue(IMPLEMENTATION_PROPERTIES_PARAM));

    CredentialStore credentialStore;
    if (csProvider != null) {
        credentialStore = CredentialStore.getInstance(csType, csProvider, getProvidersSupplier(csProvider));
    } else {
        try {
            credentialStore = CredentialStore.getInstance(csType);
        } catch (NoSuchAlgorithmException e) {
            // fallback to load all possible providers
            credentialStore = CredentialStore.getInstance(csType, getProvidersSupplier(null));
        }
    }
    implProps.put("location", location);
    implProps.putIfAbsent("modifiable", Boolean.TRUE.toString());
    implProps.putIfAbsent("create", Boolean.valueOf(createStorage).toString());
    if (csType.equals(KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE)) {
        implProps.putIfAbsent("keyStoreType", "JCEKS");
    }
    String implPropsKeyStoreType = implProps.get("keyStoreType");
    if (location == null && implPropsKeyStoreType != null
            && filebasedKeystoreTypes.contains(implPropsKeyStoreType.toUpperCase(Locale.ENGLISH))) {
        throw ElytronToolMessages.msg.filebasedKeystoreLocationMissing(implPropsKeyStoreType);
    }

    CredentialStore.CredentialSourceProtectionParameter credentialSourceProtectionParameter = null;
    if (csPassword == null) {
        // prompt for password
        csPassword = prompt(false, ElytronToolMessages.msg.credentialStorePasswordPrompt(), true,
                ElytronToolMessages.msg.credentialStorePasswordPromptConfirm());
        if (csPassword == null) {
            setStatus(GENERAL_CONFIGURATION_ERROR);
            throw ElytronToolMessages.msg.optionNotSpecified(CREDENTIAL_STORE_PASSWORD_PARAM);
        }
    }
    if (csPassword != null) {
        char[] passwordCredential;
        if (csPassword.startsWith("MASK-")) {
            passwordCredential = MaskCommand.decryptMasked(csPassword);
        } else {
            passwordCredential = csPassword.toCharArray();
        }
        credentialSourceProtectionParameter = new CredentialStore.CredentialSourceProtectionParameter(
                IdentityCredentials.NONE.withCredential(new PasswordCredential(
                        ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, passwordCredential))));
    }
    credentialStore.initialize(implProps, credentialSourceProtectionParameter,
            getProvidersSupplier(otherProviders).get());

    // ELY-1294 compute password to validate salt parameter without --summary.
    if (csPassword != null && !csPassword.startsWith("MASK-") && salt != null && iterationCount > -1) {
        password = MaskCommand.computeMasked(csPassword, salt, iterationCount);
    }

    if (cmdLine.hasOption(ADD_ALIAS_PARAM)) {
        String alias = cmdLine.getOptionValue(ADD_ALIAS_PARAM);
        if (alias.length() == 0) {
            setStatus(GENERAL_CONFIGURATION_ERROR);
            throw ElytronToolMessages.msg.optionNotSpecified(ADD_ALIAS_PARAM);
        }
        if (secret == null) {
            // prompt for secret
            secret = prompt(false, ElytronToolMessages.msg.secretToStorePrompt(), true,
                    ElytronToolMessages.msg.secretToStorePromptConfirm());
            if (secret == null) {
                setStatus(GENERAL_CONFIGURATION_ERROR);
                throw ElytronToolMessages.msg.optionNotSpecified(PASSWORD_CREDENTIAL_VALUE_PARAM);
            }
        }

        credentialStore.store(alias, createCredential(secret, entryType));
        credentialStore.flush();
        if (entryType != null) {
            System.out.println(ElytronToolMessages.msg.aliasStored(alias, entryType));
        } else {
            System.out.println(ElytronToolMessages.msg.aliasStored(alias));
        }
        setStatus(ElytronTool.ElytronToolExitStatus_OK);
    } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) {
        String alias = cmdLine.getOptionValue(REMOVE_ALIAS_PARAM);
        if (credentialStore.exists(alias, entryTypeToCredential(entryType))) {
            credentialStore.remove(alias, entryTypeToCredential(entryType));
            credentialStore.flush();
            if (entryType != null) {
                System.out.println(ElytronToolMessages.msg.aliasRemoved(alias, entryType));
            } else {
                System.out.println(ElytronToolMessages.msg.aliasRemoved(alias));
            }
            setStatus(ElytronTool.ElytronToolExitStatus_OK);
        } else {
            if (entryType != null) {
                System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType));
            } else {
                System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias));
            }
            setStatus(ALIAS_NOT_FOUND);
        }

    } else if (cmdLine.hasOption(CHECK_ALIAS_PARAM)) {
        String alias = cmdLine.getOptionValue(CHECK_ALIAS_PARAM);
        if (credentialStore.exists(alias, entryTypeToCredential(entryType))) {
            setStatus(ElytronTool.ElytronToolExitStatus_OK);
            System.out.println(ElytronToolMessages.msg.aliasExists(alias));
        } else {
            setStatus(ALIAS_NOT_FOUND);
            if (entryType != null) {
                System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias, entryType));
            } else {
                System.out.println(ElytronToolMessages.msg.aliasDoesNotExist(alias));
            }
        }
    } else if (cmdLine.hasOption(ALIASES_PARAM)) {
        Set<String> aliases = credentialStore.getAliases();
        if (aliases.size() != 0) {
            StringBuilder list = new StringBuilder();
            for (String alias : aliases) {
                list.append(alias).append(" ");
            }
            System.out.println(ElytronToolMessages.msg.aliases(list.toString()));
        } else {
            System.out.println(ElytronToolMessages.msg.noAliases());
        }
        setStatus(ElytronTool.ElytronToolExitStatus_OK);
    } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)) {
        //this must be always the last available option.
        credentialStore.flush();
        System.out.println(ElytronToolMessages.msg.credentialStoreCreated());
        setStatus(ElytronTool.ElytronToolExitStatus_OK);
    } else {
        setStatus(ACTION_NOT_DEFINED);
        throw ElytronToolMessages.msg.actionToPerformNotDefined();
    }

    if (printSummary) {
        StringBuilder com = new StringBuilder();

        if (cmdLine.hasOption(ADD_ALIAS_PARAM)) {
            if (implProps.get("create") != null && implProps.get("create").equals("true")) {
                getCreateSummary(implProps, com, password);
                com.append("\n");
            }
            com.append("/subsystem=elytron/credential-store=test:add-alias(alias=");
            com.append(cmdLine.getOptionValue(ADD_ALIAS_PARAM));
            if (entryType != null) {
                com.append(",entry-type=\"").append(entryType).append("\"");
            }
            com.append(",secret-value=\"");
            com.append(secret);
            com.append("\")");

        } else if (cmdLine.hasOption(REMOVE_ALIAS_PARAM)) {

            com.append("/subsystem=elytron/credential-store=test:remove-alias(alias=");
            com.append(cmdLine.getOptionValue(REMOVE_ALIAS_PARAM));
            com.append(")");

        } else if (cmdLine.hasOption(ALIASES_PARAM) || cmdLine.hasOption(CHECK_ALIAS_PARAM)) {
            com.append("/subsystem=elytron/credential-store=test:read-aliases()");
        } else if (cmdLine.hasOption(CREATE_CREDENTIAL_STORE_PARAM)) {
            getCreateSummary(implProps, com, password);
        }

        System.out.println(ElytronToolMessages.msg.commandSummary(com.toString()));
    }
}

From source file:org.codice.ddf.registry.schemabindings.RegistryPackageWebConverter.java

private static void putTelephoneNumber(List<TelephoneNumberType> phoneNumbers,
        Map<String, Object> organizationMap) {
    List<Map<String, Object>> webPhoneNumbers = new ArrayList<>();

    for (TelephoneNumberType phoneNumber : phoneNumbers) {
        Map<String, Object> phoneNumberMap = new HashMap<>();

        if (phoneNumber.isSetAreaCode()) {
            phoneNumberMap.put(PHONE_AREA_CODE, phoneNumber.getAreaCode());
        }//  w ww .j  a v  a2 s  . c  o  m

        if (phoneNumber.isSetCountryCode()) {
            phoneNumberMap.put(PHONE_COUNTRY_CODE, phoneNumber.getCountryCode());
        }

        if (phoneNumber.isSetExtension()) {
            phoneNumberMap.put(PHONE_EXTENSION, phoneNumber.getExtension());
        }

        if (phoneNumber.isSetNumber()) {
            phoneNumberMap.put(PHONE_NUMBER, phoneNumber.getNumber());
        }

        if (phoneNumber.isSetPhoneType()) {
            phoneNumberMap.putIfAbsent(PHONE_TYPE, phoneNumber.getPhoneType());
        }

        if (!phoneNumberMap.isEmpty()) {
            webPhoneNumbers.add(phoneNumberMap);
        }
    }

    if (CollectionUtils.isNotEmpty(webPhoneNumbers)) {
        organizationMap.put(TELEPHONE_KEY, webPhoneNumbers);
    }
}

From source file:org.tightblog.rendering.requests.WeblogSearchRequest.java

/**
 * Create weblog entries for each result found.
 *//*from www.jav a2  s.c  om*/
Map<LocalDate, TreeSet<WeblogEntry>> convertHitsToEntries(ScoreDoc[] hits, SearchTask searchTask) {
    Map<LocalDate, TreeSet<WeblogEntry>> results = new HashMap<>();

    // determine offset and limit
    this.offset = getPageNum() * RESULTS_PER_PAGE;
    if (this.offset >= hits.length) {
        this.offset = 0;
    }

    this.limit = RESULTS_PER_PAGE;
    if (this.offset + this.limit > hits.length) {
        this.limit = hits.length - this.offset;
    }

    WeblogEntry entry;
    Document doc;
    for (int i = offset; i < offset + limit; i++) {
        try {
            doc = searchTask.getSearcher().doc(hits[i].doc);
        } catch (IOException e) {
            log.warn("IOException processing {}", hits[i].doc, e);
            continue;
        }
        entry = searchModel.getWeblogEntryRepository()
                .findByIdOrNull(doc.getField(FieldConstants.ID).stringValue());

        if (entry != null && WeblogEntry.PubStatus.PUBLISHED.equals(entry.getStatus())) {
            LocalDate pubDate = entry.getPubTime().atZone(ZoneId.systemDefault()).toLocalDate();

            // ensure we do not get duplicates from Lucene by using a set collection.
            results.putIfAbsent(pubDate, new TreeSet<>(Comparator.comparing(WeblogEntry::getPubTime).reversed()
                    .thenComparing(WeblogEntry::getTitle)));
            results.get(pubDate).add(entry);
        }
    }

    return results;
}

From source file:io.anserini.doc.DataModel.java

public String generateEvalCommand(String collection) {
    Map<String, Object> config = this.collections.get(collection);
    String allCommandsStr = "";
    Set<String> allEvalCommands = new HashSet<>();
    ObjectMapper oMapper = new ObjectMapper();
    List models = oMapper.convertValue((List) safeGet(config, "models"), List.class);
    List topics = oMapper.convertValue((List) safeGet(config, "topics"), List.class);
    List evals = oMapper.convertValue((List) safeGet(config, "evals"), List.class);
    for (Object modelObj : models) {
        Model model = oMapper.convertValue(modelObj, Model.class);
        for (Object topicObj : topics) {
            Topic topic = oMapper.convertValue(topicObj, Topic.class);
            Map<String, Map<String, List<String>>> combinedEvalCmd = new HashMap<>();
            for (Object evalObj : evals) {
                Eval eval = oMapper.convertValue(evalObj, Eval.class);
                String evalCmd = eval.getCommand();
                List evalParams = oMapper.convertValue(eval.getParams(), List.class);
                String evalCmdOption = "";
                if (evalParams != null) {
                    for (Object option : evalParams) {
                        evalCmdOption += " " + option;
                    }//  w  ww  . java 2 s  .co  m
                }
                String evalCmdResidual = "";
                evalCmdResidual += " " + Paths.get((String) safeGet(config, "qrels_root"), topic.getQrel());
                evalCmdResidual += " -output run." + safeGet(config, "name") + "." + model.getName() + "."
                        + topic.getPath();
                evalCmdResidual += "\n";
                if (eval.isCan_combine() || evalCmdOption.isEmpty()) {
                    combinedEvalCmd.putIfAbsent(evalCmd, new HashMap<>());
                    combinedEvalCmd.get(evalCmd).putIfAbsent(evalCmdResidual, new ArrayList<>());
                    combinedEvalCmd.get(evalCmd).get(evalCmdResidual).add(evalCmdOption);
                } else {
                    allCommandsStr += evalCmd + evalCmdOption + evalCmdResidual;
                }
            }
            for (Map.Entry<String, Map<String, List<String>>> entry : combinedEvalCmd.entrySet()) {
                for (Map.Entry<String, List<String>> innerEntry : entry.getValue().entrySet()) {
                    allCommandsStr += entry.getKey() + String.join("", innerEntry.getValue())
                            + innerEntry.getKey();
                }
            }
        }
        allCommandsStr += "\n";
    }

    return allCommandsStr.substring(0, allCommandsStr.lastIndexOf("\n"));
}

From source file:org.codice.ddf.registry.schemabindings.RegistryPackageWebConverter.java

private static void putRegistryAssociation(AssociationType1 association,
        Map<String, Object> registryObjectListMap) {
    if (association == null) {
        return;//  w  ww  .j av a 2s.co  m
    }
    Map<String, Object> associationMap = new HashMap<>();

    putGeneralInfo(association, associationMap);

    if (association.isSetAssociationType()) {
        associationMap.put(ASSOCIATION_TYPE, association.getAssociationType());
    }

    if (association.isSetSourceObject()) {
        associationMap.put(ASSOCIATION_SOURCE_OBJECT, association.getSourceObject());
    }

    if (association.isSetTargetObject()) {
        associationMap.put(ASSOCIATION_TARGET_OBJECT, association.getTargetObject());
    }

    if (!associationMap.isEmpty()) {
        registryObjectListMap.putIfAbsent(ASSOCIATION_KEY, new ArrayList<Map<String, Object>>());
        ((List) registryObjectListMap.get(ASSOCIATION_KEY)).add(associationMap);
    }
}

From source file:org.codice.ddf.registry.schemabindings.RegistryPackageWebConverter.java

private static void putRegistryPerson(PersonType person, Map<String, Object> registryObjectListMap) {
    if (person == null) {
        return;//from  ww  w.j  av a2  s .com
    }

    Map<String, Object> personMap = new HashMap<>();

    putGeneralInfo(person, personMap);

    if (person.isSetAddress()) {
        putAddress(person.getAddress(), personMap);
    }

    if (person.isSetEmailAddress()) {
        putEmailAddress(person.getEmailAddress(), personMap);
    }

    if (person.isSetPersonName()) {
        putPersonName(person.getPersonName(), personMap);
    }

    if (person.isSetTelephoneNumber()) {
        putTelephoneNumber(person.getTelephoneNumber(), personMap);
    }

    if (!personMap.isEmpty()) {
        registryObjectListMap.putIfAbsent(PERSON_KEY, new ArrayList<Map<String, Object>>());
        ((List) registryObjectListMap.get(PERSON_KEY)).add(personMap);
    }
}

From source file:org.onosproject.influxdbmetrics.DefaultInfluxDbMetricsRetriever.java

@Override
public Map<NodeId, InfluxMetric> metricsByName(String metricName) {
    Map<NodeId, InfluxMetric> map = Maps.newHashMap();
    String queryPrefix = new StringBuilder().append("SELECT m1_rate FROM").append(database)
            .append(METRIC_DELIMITER).append(quote(DEFAULT_POLICY)).append(METRIC_DELIMITER).toString();
    String querySuffix = new StringBuilder().append(" LIMIT 1").toString();

    allMetricNames().keySet().forEach(nodeId -> {
        String queryString = new StringBuilder().append(queryPrefix)
                .append(quote(nodeId + METRIC_DELIMITER + metricName)).append(querySuffix).toString();
        Query query = new Query(queryString, database);
        List<QueryResult.Result> results = influxDB.query(query).getResults();

        if (results != null && results.get(0) != null && results.get(0).getSeries() != null) {
            InfluxMetric metric = new DefaultInfluxMetric.Builder()
                    .time((String) results.get(0).getSeries().get(0).getValues().get(0).get(0))
                    .oneMinRate((Double) results.get(0).getSeries().get(0).getValues().get(0).get(1)).build();
            map.putIfAbsent(nodeId, metric);
        }//  w  w w.  j a v  a2s  .com
    });

    return map;
}

From source file:org.dataconservancy.packaging.tool.integration.PackageGenerationTest.java

/**
 * Reads in any BagIt file that uses a ':' to delimit a keyword and value pair.
 *
 * @param bagItFile the file to read/*from ww w .  j a  v a 2  s.  c o  m*/
 * @return a Map keyed by the keywords, with the List of values as they appear in the file
 * @throws IOException
 */
private Map<String, List<String>> parseBagItKeyValuesFile(File bagItFile) throws IOException {
    Map<String, List<String>> result = new HashMap<>();

    // Used to track state; a streams no-no.  Probably should do this the old-fashioned way.
    BitSet bitSet = new BitSet(1);
    bitSet.set(0);
    StringBuilder key = new StringBuilder();

    Files.lines(bagItFile.toPath(), Charset.forName("UTF-8")).flatMap(line -> Stream
            .of(line.substring(0, line.indexOf(":")), line.substring(line.indexOf(":") + 1).trim()))
            .forEach(token -> {
                if (bitSet.get(0)) {
                    // key
                    key.delete(0, key.length());
                    result.putIfAbsent(token, new ArrayList<>());
                    key.append(token);
                    bitSet.clear(0);
                } else {
                    // value
                    result.get(key.toString()).add(token);
                    bitSet.set(0);
                }
            });

    return result;
}