Class LDUser
- java.lang.Object
-
- com.launchdarkly.sdk.LDUser
-
- All Implemented Interfaces:
JsonSerializable
public class LDUser extends java.lang.Object implements JsonSerializable
A collection of attributes that can affect flag evaluation, usually corresponding to a user of your application.The only mandatory property is the
key
, which must uniquely identify each user; this could be a username or email address for authenticated users, or a session ID for anonymous users. All other built-in properties are optional. You may also define custom properties with arbitrary names and values.For a fuller description of user attributes and how they can be referenced in feature flag rules, see the reference guides on Setting user attributes and Targeting users.
LaunchDarkly defines a standard JSON encoding for user objects, used by the JavaScript SDK and also in analytics events.
LDUser
can be converted to and from JSON in any of these ways:- With
JsonSerialization
. - With Gson, if and only if you configure your
Gson
instance withLDGson
. - With Jackson, if and only if you configure your
ObjectMapper
instance withLDJackson
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LDUser.Builder
-
Constructor Summary
Constructors Modifier Constructor Description protected
LDUser(LDUser.Builder builder)
LDUser(java.lang.String key)
Create a user with the given key
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
LDValue
getAttribute(UserAttribute attribute)
Gets the value of a user attribute, if present.java.lang.String
getAvatar()
Returns the value of the avatar property for the user, if set.java.lang.String
getCountry()
Returns the value of the country property for the user, if set.java.lang.Iterable<UserAttribute>
getCustomAttributes()
Returns an enumeration of all custom attribute names that were set for this user.java.lang.String
getEmail()
Returns the value of the email property for the user, if set.java.lang.String
getFirstName()
Returns the value of the first name property for the user, if set.java.lang.String
getIp()
Returns the value of the IP property for the user, if set.java.lang.String
getKey()
Returns the user's unique key.java.lang.String
getLastName()
Returns the value of the last name property for the user, if set.java.lang.String
getName()
Returns the value of the full name property for the user, if set.java.lang.Iterable<UserAttribute>
getPrivateAttributes()
Returns an enumeration of all attributes that were marked private for this user.java.lang.String
getSecondary()
Returns the value of the secondary key property for the user, if set.int
hashCode()
boolean
isAnonymous()
Returns true if this user was marked anonymous.boolean
isAttributePrivate(UserAttribute attribute)
Tests whether an attribute has been marked private for this user.java.lang.String
toString()
-
-
-
Constructor Detail
-
LDUser
protected LDUser(LDUser.Builder builder)
-
LDUser
public LDUser(java.lang.String key)
Create a user with the given key- Parameters:
key
- aString
that uniquely identifies a user
-
-
Method Detail
-
getKey
public java.lang.String getKey()
Returns the user's unique key.- Returns:
- the user key as a string
-
getSecondary
public java.lang.String getSecondary()
Returns the value of the secondary key property for the user, if set.- Returns:
- a string or null
-
getIp
public java.lang.String getIp()
Returns the value of the IP property for the user, if set.- Returns:
- a string or null
-
getCountry
public java.lang.String getCountry()
Returns the value of the country property for the user, if set.- Returns:
- a string or null
-
getName
public java.lang.String getName()
Returns the value of the full name property for the user, if set.- Returns:
- a string or null
-
getFirstName
public java.lang.String getFirstName()
Returns the value of the first name property for the user, if set.- Returns:
- a string or null
-
getLastName
public java.lang.String getLastName()
Returns the value of the last name property for the user, if set.- Returns:
- a string or null
-
getEmail
public java.lang.String getEmail()
Returns the value of the email property for the user, if set.- Returns:
- a string or null
-
getAvatar
public java.lang.String getAvatar()
Returns the value of the avatar property for the user, if set.- Returns:
- a string or null
-
isAnonymous
public boolean isAnonymous()
Returns true if this user was marked anonymous.- Returns:
- true for an anonymous user
-
getAttribute
public LDValue getAttribute(UserAttribute attribute)
Gets the value of a user attribute, if present.This can be either a built-in attribute or a custom one. It returns the value using the
LDValue
type, which can have any type that is supported in JSON. If the attribute does not exist, it returnsLDValue.ofNull()
.- Parameters:
attribute
- the attribute to get- Returns:
- the attribute value or
LDValue.ofNull()
; will never be an actual null reference
-
getCustomAttributes
public java.lang.Iterable<UserAttribute> getCustomAttributes()
Returns an enumeration of all custom attribute names that were set for this user.- Returns:
- the custom attribute names
-
getPrivateAttributes
public java.lang.Iterable<UserAttribute> getPrivateAttributes()
Returns an enumeration of all attributes that were marked private for this user.This does not include any attributes that were globally marked private in your SDK configuration.
- Returns:
- the names of private attributes for this user
-
isAttributePrivate
public boolean isAttributePrivate(UserAttribute attribute)
Tests whether an attribute has been marked private for this user.- Parameters:
attribute
- a built-in or custom attribute- Returns:
- true if the attribute was marked private on a per-user level
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-