All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.apkcloud.devicedetector.parser.VendorFragment Maven / Gradle / Ivy

Go to download

通用设备检测库将解析任何UserAgent并检测浏览器、操作系统、使用的设备(桌面、平板、移动、电视、车载、游戏机等等)、品牌和型号。

There is a newer version: 1.0.7
Show newest version
package io.github.apkcloud.devicedetector.parser;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用于检测供应商片段的设备解析器
 */
public class VendorFragment extends AbstractParser {

    protected String fixtureFile = "regexes/vendorfragments.yml";

    protected String parserName = "vendorfragments";

    protected String matchedRegex = null;

    public VendorFragment(String userAgent) {
        super(userAgent);
    }

    @Override
    public String getName() {
        return parserName;
    }

    /**
     * @return {@code Map | null}
     */
    public Map parse() throws Exception {
        Map> map = getRegexes(fixtureFile, String.class, List.class);
        for (Map.Entry> entry : map.entrySet()) {
            String brand = entry.getKey();
            List regexes = entry.getValue();

            for (String regex : regexes) {
                if (!isNullOrEmpty(matchUserAgent(regex + "[^a-z0-9]+"))) {
                    matchedRegex = regex;
                    Map result = new HashMap<>();
                    result.put("brand", brand);
                    return result;
                }
            }
        }

        return null;
    }

    /**
     * @return String | null
     */
    public String getMatchedRegex() {
        return matchedRegex;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy