package sizebay.catalog.client.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@Accessors(chain = true)
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserProfile implements Serializable {

    String id;
    String email;
    String facebook;
    String password;

    List<UserProfileIdentification> profiles;

    public static UserProfile empty(String id, String password) {

        List<UserProfileIdentification> profile = new ArrayList<>();
        profile.add(UserProfileIdentification.empty());

        UserProfile user = new UserProfile().setId(id)
                                            .setPassword(password)
                                            .setProfiles(profile);

        return user;

    }

}

@@ -185,17 +185,16 @@
 essors;%0A
-%0A
 import j
@@ -259,20 +259,125 @@
 va.util.
-List
+Comparator;%0Aimport java.util.List;%0Aimport java.util.stream.Collectors;%0Aimport static java.util.Objects.isNull
 ;%0A%0A@Data
@@ -519,16 +519,68 @@
 le %7B%0A%0A  
+private static final int ACTIVE = 1, INACTIVE = 0;%0A%0A
   String
@@ -584,18 +584,16 @@
 ing id;%0A
-  
   String
@@ -600,18 +600,16 @@
  email;%0A
-  
   String
@@ -619,18 +619,16 @@
 cebook;%0A
-  
   String
@@ -645,49 +645,290 @@
 %0A%0A  
-  List%3CUserProfileIdentification%3E
+List%3CProfile%3E profiles = new ArrayList%3C%3E();%0A%0A  public void insertAndUpdateProfilesList(Profile newProfile) %7B%0A    final long profileId = newProfile.getId();%0A    final boolean removeProfile = profileId != 0;%0A%0A    if(removeProfile) this.getProfiles().removeIf(p -%3E p.getId() ==
  profile
 s;%0A%0A
@@ -927,419 +927,1833 @@
 file
-s
+Id)
 ;%0A%0A    
-public static UserProfile empty(String id, String password) %7B%0A%0A        List%3CUserProfileIdentification%3E p
+newProfile.generateIdentifier();%0A%0A    this.getProfiles().add(newProfile);%0A    this.activeProfile(newProfile.getId());%0A  %7D%0A%0A  public void activeProfile(long profileId) %7B%0A    final List%3CProfile%3E profiles = this.getProfiles();%0A%0A    profiles.stream().forEach(p -%3E %7B%0A      if(p.getId() == profileId) %7B%0A        p.setIsActive(ACTIVE);%0A        p.setLastActiveTime(System.currentTimeMillis());%0A      %7D else %7B%0A        p.setIsActive(INACTIVE);%0A      %7D%0A    %7D);%0A  %7D%0A%0A  public Profile retrieveActiveProfile() %7B%0A    final List%3CProfile%3E userP
 rofile
+s
  = 
-new ArrayList%3C%3E
+this.getProfiles
 ();%0A
+%0A
     
-    profile.add(UserProfileIdentification.empty());%0A%0A        UserProfile user = new UserProfile().setId(id)%0A                                            .setPassword(password)%0A                                            .setProfiles(profile);%0A%0A        return user;%0A%0A  
+if(isNull(userProfiles)) return null;%0A%0A    return userProfiles.stream().filter(p -%3E p.getIsActive() == ACTIVE).findAny().orElse(null);%0A  %7D%0A%0A  public Profile retrieveActiveProfileByGender(String gender) %7B%0A    final List%3CProfile%3E userProfiles = this.getProfiles();%0A%0A    if(isNull(userProfiles)) return null;%0A%0A    Profile profile = retrieveActiveProfile();%0A%0A    if(profile.getGender().equals(gender)) %7B%0A      return profile;%0A    %7D else %7B%0A      return userProfiles.stream().filter(p -%3E p.getGender().equals(gender))%0A                                  .sorted(new SortProfileByLastActiveTime())%0A                                  .collect(Collectors.toList()).get(0);%0A    %7D%0A%0A  %7D%0A%0A  public Long retrieveActiveProfileId() %7B%0A    final Profile userProfile = this.retrieveActiveProfile();%0A%0A    return isNull(userProfile) ? null : userProfile.getId();%0A  %7D%0A%0A  public static UserProfile empty(String id, String password) %7B%0A%0A    return new UserProfile().setId(id).setPassword(password);%0A  %7D%0A%0A  class SortProfileByLastActiveTime implements Comparator%3CProfile%3E %7B%0A    public int compare(Profile profileOne, Profile profileTwo) %7B%0A%0A      if(profileOne.getLastActiveTime() %3E profileTwo.getLastActiveTime()) %7B%0A        return -1;%0A      %7D else %7B%0A        return 0;%0A      %7D%0A%0A    %7D%0A
   %7D%0A

Refactor UserProfile class