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

com.makitoo.User Maven / Gradle / Ivy

The newest version!
package com.makitoo;

import org.json.JSONObject;

/**
 * Created by nicolas on 23/01/17.
 */
public class User {

    private static final String USER_AGENT = "userAgent";
    private static final String IP = "ip";
    public static final String LANGUAGE = "language";

    final String id;
    private JSONObject context = new JSONObject();

    public User(String id) {
        this.id = id;
    }

    public User withProperty(String name, String value) {
        getProperties().put(name, value);
        return this;
    }

    public User withContext(String name, String value) {
        context.put(name, value);
        return this;
    }

    public User withUserAgent(String userAgent) {
        return withContext(USER_AGENT, userAgent);
    }

    public User withIP(String ip) {
        return withContext(IP, ip);
    }

    public User withLanguage(String language) {
        return withContext(LANGUAGE, language);
    }

    public String getId() {
        return id;
    }

    public JSONObject getContext() {
        return context;
    }

    public JSONObject getProperties() {
        if (!context.has("user")) {
            context.put("user", new JSONObject());
        }
        return context.getJSONObject("user");
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        return id != null ? id.equals(user.id) : user.id == null;

    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy