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

com.statsig.StatsigUser Maven / Gradle / Ivy

The newest version!
package com.statsig;

import com.google.gson.Gson;

import java.util.Map;

public class StatsigUser {
    public String userID;
    public Map customIDs;
    public String email;
    public String ip;
    public String locale;
    public String appVersion;
    public String userAgent;
    public String country;
    public Map privateAttributes;
    public Map custom;

    private volatile String ref;

    public StatsigUser(
            String userId,
            Map customIDs,
            String email,
            String ip,
            String userAgent,
            String country,
            String locale,
            String appVersion,
            Map custom,
            Map privateAttributes
    ) {
        this.userID = userId;
        this.custom = custom;
        this.email = email;
        this.ip = ip;
        this.locale = locale;
        this.appVersion = appVersion;
        this.customIDs = customIDs;
        this.privateAttributes = privateAttributes;
        this.country = country;
        this.userAgent = userAgent;

        initializeRef();
        ResourceCleaner.register(this, () -> {
            if (ref != null) {
                StatsigJNI.statsigUserRelease(ref);
                ref = null;
            }
        });
    }

    public StatsigUser(String userId) {
        this(userId, null, null, null, null, null, null, null, null, null);
    }

    public StatsigUser(Map customIDs) {
        this(null, customIDs, null, null, null, null, null, null, null, null);
    }

    public StatsigUser(String userId, String email) {
        this(userId, null, email, null, null, null, null, null, null, null);
    }

    public String getUserID() {
        return userID;
    }

    public void setUserID(String userID) {
        this.userID = userID;
    }

    public Map getCustomIDs() {
        return customIDs;
    }

    public void setCustomIDs(Map customIDs) {
        this.customIDs = customIDs;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getLocale() {
        return locale;
    }

    public void setLocale(String locale) {
        this.locale = locale;
    }

    public String getAppVersion() {
        return appVersion;
    }

    public void setAppVersion(String appVersion) {
        this.appVersion = appVersion;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public Map getPrivateAttributes() {
        return privateAttributes;
    }

    public void setPrivateAttributes(Map privateAttributes) {
        this.privateAttributes = privateAttributes;
    }

    public Map getCustom() {
        return custom;
    }

    public void setCustom(Map custom) {
        this.custom = custom;
    }

    private void initializeRef() {
        Gson gson = new Gson();

        String customIdsJson = customIDs != null ? gson.toJson(customIDs) : null;
        String customJson = custom != null ? gson.toJson(custom) : null;
        String privateAttributesJson = privateAttributes != null ? gson.toJson(privateAttributes) : null;

        // Pass all arguments to the JNI binding
        this.ref = StatsigJNI.statsigUserCreate(
                userID,
                customIdsJson,
                email,
                ip,
                userAgent,
                country,
                locale,
                appVersion,
                customJson,
                privateAttributesJson
        );
    }

    String getRef() {
        return ref;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy