public void improveLayoutEngineAndAgentInfo(AnalyzerConfigHolder config, MutableUserAgent userAgent, ClientHints clientHints) {
        // Improve the Agent info.
        List<Brand> versionList = clientHints.getFullVersionList();
        if (versionList == null) {
            versionList = clientHints.getBrands();
        }

        if (versionList == null) {
            return; // Nothing to do
        }

        final Map<String, Brand> versionMap = new TreeMap<>();
        versionList.forEach(v -> versionMap.put(v.getName(), v));

        // ========================
        Brand chromium = versionMap.get("Chromium");
        if (chromium != null) {
            String version = chromium.getVersion();
            String[] versionSplits = DOT_SPLITTER.split(version);
            String majorVersion = versionSplits[0];

            // Work around the major in minor hack/feature of Chrome ~v99
            if (versionSplits.length==4 && !"0".equals(versionSplits[1])) {
                version = versionSplits[1] + ".0." + versionSplits[2] + '.' + versionSplits[3];
                majorVersion = versionSplits[1];
            }

            // ==== Blink ?
            MutableAgentField engineName = userAgent.get(LAYOUT_ENGINE_NAME);
            if (engineName.isDefaultValue() || !"Blink".equals(engineName.getValue())) {
                overrideValue(engineName, "Blink");
            }
            MutableAgentField engineVersion = userAgent.get(LAYOUT_ENGINE_VERSION);
            MutableAgentField engineMajorVersion = userAgent.get(LAYOUT_ENGINE_VERSION_MAJOR);
            String blinkVersion = majorVersion;
            if (versionSplits.length>1) {
                blinkVersion = majorVersion + ".0";
            }
            if (newVersionIsBetter(engineVersion, blinkVersion)) {
                overrideValue(engineVersion, blinkVersion);
                overrideValue(engineMajorVersion, majorVersion);
            }

            overrideValue(userAgent.get(LAYOUT_ENGINE_NAME_VERSION), engineName.getValue() + " " + engineVersion.getValue());
            overrideValue(userAgent.get(LAYOUT_ENGINE_NAME_VERSION_MAJOR), engineName.getValue() + " " + engineMajorVersion.getValue());

            // ===== Chromium browser?
            if (versionList.size() == 1 && CHROMIUMNAMES.contains(userAgent.getValue(AGENT_NAME))) { // NOTE: The grease was filtered out !
                // So we have only have a "Chromium" hint and not "Chrome" or "Edge" or something else
                // If the previous agentname is Chrome and there is only 1 hing then the real name is Chromium ...
                MutableAgentField currentVersion = userAgent.get(AGENT_VERSION);
                if (newVersionIsBetter(currentVersion, version)) {
                    overrideValue(userAgent.get(AGENT_NAME), "Chromium");
                    overrideValue(userAgent.get(AGENT_VERSION), version);
                    overrideValue(userAgent.get(AGENT_NAME_VERSION), "Chromium " + version);
                    overrideValue(userAgent.get(AGENT_VERSION_MAJOR), majorVersion);
                    overrideValue(userAgent.get(AGENT_NAME_VERSION_MAJOR), "Chromium " + majorVersion);
                } else {
                    // We ONLY update the name of the agent to Chromium in some cases
                    if ("Chrome".equals(userAgent.getValue(AGENT_NAME))) {
                        overrideValue(userAgent.get(AGENT_NAME), "Chromium");
                        overrideValue(userAgent.get(AGENT_NAME_VERSION), "Chromium " + currentVersion.getValue());

                        String currentMajorVersion = userAgent.getValue(AGENT_VERSION_MAJOR);
                        overrideValue(userAgent.get(AGENT_NAME_VERSION_MAJOR), "Chromium " + currentMajorVersion);
                    }
                }

                return;
            }
            versionMap.remove("Chromium");
        }

        // Some browsers include tags for their historical version --> Drop those
        BROWSER_ANCESTORS.forEach((wanted, unwanted) -> {
            if (versionMap.containsKey(wanted)) {
                versionMap.remove(unwanted);
            }
        });

        // Some browsers include tags that are simply nonsense
        versionMap.remove("Android WebView"); // Opera GX 2.1, Phoenix

        // ========================
        Brand chrome = versionMap.get("Chrome");
        if (chrome == null) {
            chrome = versionMap.get("Google Chrome");
        }
        if (chrome != null) {
            if (versionMap.size() == 1) {
                // So we have "Chrome" and nothing else
                MutableAgentField currentVersion = userAgent.get(AGENT_VERSION);
                String version = chrome.getVersion();
                String[] versionSplits = DOT_SPLITTER.split(version);
                String majorVersion = versionSplits[0];

                // Work around the major in minor hack/feature of Chrome ~v99
                // 99.100.x.y is really 100.0.x.y
                if (versionSplits.length==4 && !"0".equals(versionSplits[1])) {
                    version = versionSplits[1] + ".0." + versionSplits[2] + '.' + versionSplits[3];
                    majorVersion = versionSplits[1];
                }

                if (newVersionIsBetter(currentVersion, version)) {
                    overrideValue(userAgent.get(AGENT_NAME), "Chrome");
                    overrideValue(currentVersion, version);
                    overrideValue(userAgent.get(AGENT_NAME_VERSION), "Chrome " + version);
                    overrideValue(userAgent.get(AGENT_VERSION_MAJOR), majorVersion);
                    overrideValue(userAgent.get(AGENT_NAME_VERSION_MAJOR), "Chrome " + majorVersion);
                    return;
                }
            }
            versionMap.remove("Chrome");
            versionMap.remove("Google Chrome");
        }
        // ========================

        // There was a bug in Opera which puts the wrong version in the client hints.
        // This has been fixed in the first release of Opera 98
        // https://blogs.opera.com/desktop/changelog-for-98/
        // So up until Opera 97 / Opera Mobile the version information was buggy.
        MutableAgentField currentAgent = userAgent.get(AGENT_NAME);
        if ("Opera".equals(currentAgent.getValue())) {
            String currentVersion = userAgent.get(AGENT_VERSION).getValue();
            // We only consider the Client Hints if the version new enough.
            String currentMajorVersion = DOT_SPLITTER.split(currentVersion, 2)[0];
            try {
                int currentMajorVersionInt = Integer.parseInt(currentMajorVersion);
                if (currentMajorVersionInt < 98) {
                    versionMap.remove("Opera");
                }
            } catch (NumberFormatException nfe) {
                // Safety net; Ignore this problem if it happens.
            }
        }

        // If anything remains then (we think) THAT is the truth...
        Map<String, Brand> sortedBrands = new TreeMap<>();

        // If we have more than 1 left we sort them by how detailed the version info is.
        int originalPosition = 0;
        for (Brand brand : versionMap.values()) {
            originalPosition++;
            String version = brand.getVersion();
            boolean versionFieldValueHasDot = version.indexOf('.') >= 0;
            boolean versionIsMajorVersionOnly = !versionFieldValueHasDot;
            if (versionFieldValueHasDot) {
                versionIsMajorVersionOnly = version.endsWith(".0.0.0");
            }
            // The 0 (with detailed version) is sorted before the 1 (only major version) in the TreeMap (which sorts by key)
            sortedBrands.put((versionIsMajorVersionOnly ?"1":"0") + "_"+ originalPosition + "_" + brand.getName(), brand);
        }

        MutableAgentField agentNameField = userAgent.get(AGENT_NAME);
        MutableAgentField agentVersionField = userAgent.get(AGENT_VERSION);
        String versionFieldValue = agentVersionField.getValue();

        boolean versionFieldValueHasDot = versionFieldValue.indexOf('.') >= 0;
        boolean versionIsMajorVersionOnly = !versionFieldValueHasDot;
        if (versionFieldValueHasDot) {
            versionIsMajorVersionOnly = versionFieldValue.endsWith(".0.0.0");
        }

        // We just pick the first one that remains.
        Optional<Map.Entry<String, Brand>> firstBrand = sortedBrands.entrySet().stream().findFirst();
        if (!firstBrand.isPresent()) {
            return;
        }

        Map.Entry<String, Brand> brandEntry = firstBrand.get();
        Brand brand = brandEntry.getValue();
        String agentName = brand.getName();

        // Sanitize the common yet unwanted names
        Map<String, String> clientHintTagMapping = config.getLookups().get("ClientHintTagToNameMapping");
        if (clientHintTagMapping != null) {
            String betterValue = clientHintTagMapping.get(agentName.toLowerCase(Locale.ROOT));
            if (betterValue != null) {
                agentName = betterValue;
            }
        }

        // We only update the version if we have a better version number.
        // We always update the AgentName because I think the Client hints are always "better"...
        String newVersion = brand.getVersion();
        String newMajorVersion = DOT_SPLITTER.split(newVersion, 2)[0];

        // The values we are going to set at the end.
        String setVersion = versionFieldValue;
        String setMajorVersion = DOT_SPLITTER.split(versionFieldValue, 2)[0];

        // If the original is a major version only then the new one is better
        if (versionIsMajorVersionOnly) {
            setVersion = newVersion;
            setMajorVersion = newMajorVersion;
        } else {
            // If current version is a full version but there is a mismatch in the major we pick the
            // ClientHints version anyway.
            if (!setMajorVersion.equals(newMajorVersion)) {
                setVersion = newVersion;
                setMajorVersion = newMajorVersion;
            }
        }

        overrideValue(agentNameField, agentName);
        overrideValue(userAgent.get(AGENT_VERSION), setVersion);
        overrideValue(userAgent.get(AGENT_NAME_VERSION), agentName + " " + setVersion);
        overrideValue(userAgent.get(AGENT_VERSION_MAJOR), setMajorVersion);
        overrideValue(userAgent.get(AGENT_NAME_VERSION_MAJOR), agentName + " " + setMajorVersion);
    }
Some device names are "Generic" and thus must be overwritten if a Client hint is available.
analyzer/src/main/java/nl/basjes/parse/useragent/clienthints/ClientHintsAnalyzer.java