Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate IdentityMap/IdentityItem APIs for kotlin #97

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ class CustomIdentityFragment : Fragment() {
val authenticatedState: AuthenticatedState? = sharedViewModel.authenticatedState.value
val isPrimary: Boolean = sharedViewModel.isPrimary.value ?: false

val item = IdentityItem(identifier, authenticatedState, isPrimary)
val map = IdentityMap()
map.addItem(item, namespace)
Identity.updateIdentities(map)
if (identifier != null && namespace != null) {
val item = IdentityItem(identifier, authenticatedState, isPrimary)
val map = IdentityMap()
map.addItem(item, namespace)
Identity.updateIdentities(map)
}
}

root.findViewById<Button>(R.id.btn_remove_identities).setOnClickListener {
Expand All @@ -106,8 +108,8 @@ class CustomIdentityFragment : Fragment() {
val authenticatedState: AuthenticatedState? = sharedViewModel.authenticatedState.value
val isPrimary: Boolean = sharedViewModel.isPrimary.value ?: false

val item = IdentityItem(identifier, authenticatedState, isPrimary)
if (namespace != null) {
if (identifier != null && namespace != null) {
val item = IdentityItem(identifier, authenticatedState, isPrimary)
Identity.removeIdentity(item, namespace)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import static com.adobe.marketing.mobile.edge.identity.IdentityConstants.LOG_TAG;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.adobe.marketing.mobile.services.Log;
import com.adobe.marketing.mobile.util.DataReader;
import com.adobe.marketing.mobile.util.DataReaderException;
Expand All @@ -37,12 +39,16 @@ public final class IdentityItem {
/**
* Creates a new {@link IdentityItem}
*
* @param id id for the item
* @param authenticatedState {@link AuthenticatedState} for the item
* @param id id for the item; should not be null
* @param authenticatedState {@link AuthenticatedState} for the item; if none is provided {@link AuthenticatedState#AMBIGUOUS} is used as default
* @param primary primary flag for the item
* @throws IllegalArgumentException if id is null
*/
public IdentityItem(final String id, final AuthenticatedState authenticatedState, final boolean primary) {
public IdentityItem(
@NonNull final String id,
@Nullable final AuthenticatedState authenticatedState,
final boolean primary
) {
if (id == null) {
throw new IllegalArgumentException("id must be non-null");
}
Expand All @@ -57,18 +63,18 @@ public IdentityItem(final String id, final AuthenticatedState authenticatedState
* {@code authenticatedState) is set to AMBIGUOUS
* (@code primary} is set to false
*
* @param id the id for this {@link IdentityItem}
* @param id the id for this {@link IdentityItem}; should not be null
*/
public IdentityItem(final String id) {
public IdentityItem(@NonNull final String id) {
this(id, AuthenticatedState.AMBIGUOUS, false);
}

/**
* Creates a copy of item.
*
* @param item A {@link IdentityItem} to be copied
* @param item A {@link IdentityItem} to be copied; should not be null
*/
public IdentityItem(final IdentityItem item) {
public IdentityItem(@NonNull final IdentityItem item) {
this(item.id, item.authenticatedState, item.primary);
}

Expand All @@ -77,6 +83,7 @@ public IdentityItem(final IdentityItem item) {
*
* @return The id for this identity item
*/
@NonNull
public String getId() {
return id;
}
Expand All @@ -86,6 +93,7 @@ public String getId() {
*
* @return Current {@link AuthenticatedState} for this item
*/
@NonNull
public AuthenticatedState getAuthenticatedState() {
return authenticatedState;
}
Expand All @@ -100,6 +108,7 @@ public boolean isPrimary() {
return primary;
}

@NonNull
@Override
public String toString() {
// format:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import static com.adobe.marketing.mobile.edge.identity.IdentityConstants.LOG_TAG;

import androidx.annotation.NonNull;
import com.adobe.marketing.mobile.services.Log;
import com.adobe.marketing.mobile.util.DataReader;
import com.adobe.marketing.mobile.util.MapUtils;
Expand Down Expand Up @@ -44,7 +45,8 @@ public class IdentityMap {
* @param namespace namespace for the list of identities to retrieve
* @return IdentityItem for the namespace
*/
public List<IdentityItem> getIdentityItemsForNamespace(final String namespace) {
@NonNull
public List<IdentityItem> getIdentityItemsForNamespace(@NonNull final String namespace) {
final List<IdentityItem> copyItems = new ArrayList<>();

if (StringUtils.isNullOrEmpty(namespace)) {
Expand All @@ -69,6 +71,7 @@ public List<IdentityItem> getIdentityItemsForNamespace(final String namespace) {
*
* @return a list of all the namespaces for this {@link IdentityMap}, or an empty string if this {@code IdentityMap} is empty
*/
@NonNull
public List<String> getNamespaces() {
return new ArrayList<>(identityItems.keySet());
}
Expand All @@ -77,20 +80,20 @@ public List<String> getNamespaces() {
* Add an identity item which is used to clearly distinguish entities that are interacting
* with digital experiences.
*
* @param item {@link IdentityItem} to be added to the given {@code namespace}
* @param namespace the namespace integration code or namespace ID of the identity
* @param item {@link IdentityItem} to be added to the given {@code namespace}; should not be null
* @param namespace the namespace integration code or namespace ID of the identity; should not be null
*/
public void addItem(final IdentityItem item, final String namespace) {
public void addItem(@NonNull final IdentityItem item, @NonNull final String namespace) {
addItem(item, namespace, false);
}

/**
* Remove a single {@link IdentityItem} from this map.
*
* @param item {@link IdentityItem} to be removed from the given {@code namespace}
* @param namespace the namespace integration code or namespace ID of the identity
* @param item {@link IdentityItem} to be removed from the given {@code namespace}; should not be null
* @param namespace the namespace integration code or namespace ID of the identity; should not be null
*/
public void removeItem(final IdentityItem item, final String namespace) {
public void removeItem(@NonNull final IdentityItem item, @NonNull final String namespace) {
if (item == null) {
Log.debug(LOG_TAG, LOG_SOURCE, "Remove item ignored as must contain a non-null IdentityItem.");
return;
Expand All @@ -113,6 +116,7 @@ public boolean isEmpty() {
return identityItems.isEmpty();
}

@NonNull
@Override
public String toString() {
final StringBuilder b = new StringBuilder();
Expand Down