I have a list of conversion histories, where information about user channels is stored. For example user may have app for iOS and Android installed. Each time user logs in, I store a conversion history, so that there might be multiple rows with shared data (e.g. client is always iOS).
I need to get the latest usage of iOS and Android in this case, as you can see code is pretty much in 'serial' way, so I wonder how this part can be optimized. Any help is appreciated.
private List<UserChannel.AppUser> findLatestAppClients(
List<Conversion> conversions
) {
Optional<Conversion> iosClient =
conversions.stream().filter(c -> IOS.clientName().equals(c.getClient())).findFirst();
Optional<Conversion> androidClient =
conversions.stream().filter(c -> ANDROID.clientName().equals(c.getClient())).findFirst();
List<UserChannel.AppUser> appUsers = new ArrayList<>();
if (iosClient.isPresent()) {
appUsers.add(new UserChannel.AppUser(iosClient.get().getClient(), iosClient.get().getClientId()));
}
if (androidClient.isPresent()) {
appUsers.add(new UserChannel.AppUser(androidClient.get().getClient(), androidClient.get().getClientId()));
}
return appUsers;
}