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

no.finn.unleash.UnleashContext Maven / Gradle / Ivy

There is a newer version: 4.4.1
Show newest version
package no.finn.unleash;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class UnleashContext {
    private final Optional userId;
    private final Optional sessionId;
    private final Optional remoteAddress;

    private final Map properties;

    public UnleashContext(String userId, String sessionId, String remoteAddress, Map properties) {
        this.userId = Optional.ofNullable(userId);
        this.sessionId = Optional.ofNullable(sessionId);
        this.remoteAddress = Optional.ofNullable(remoteAddress);
        this.properties = properties;
    }

    public Optional getUserId() {
        return userId;
    }

    public Optional getSessionId() {
        return sessionId;
    }

    public Optional getRemoteAddress() {
        return remoteAddress;
    }

    public Map getProperties() {
        return properties;
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        private String userId;
        private String sessionId;
        private String remoteAddress;

        private final Map properties = new HashMap<>();

        public Builder userId(String userId) {
            this.userId = userId;
            return this;
        }

        public Builder sessionId(String sessionId) {
            this.sessionId = sessionId;
            return this;
        }

        public Builder remoteAddress(String remoteAddress) {
            this.remoteAddress = remoteAddress;
            return this;
        }

        public Builder addProperty(String name, String value) {
            properties.put(name, value);
            return this;
        }

        public UnleashContext build() {
            return new UnleashContext(userId, sessionId, remoteAddress, properties);
        }
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy