Data Filtering and Aggregation in User Management with Kotlin
Introduction
Welcome to today's lesson on applying Kotlin to perform data filtering and aggregation in a real-world scenario using a user management system. We'll start by building a foundational structure that can handle basic user operations. Then, we'll expand it by introducing more advanced functionalities that allow filtering and aggregating user data.
Starter Task Methods
In our starter task, we will implement a class that manages basic operations on a collection of user data, specifically handling the addition of new users, retrieving user profiles, and updating user profiles.
Here are the starter task methods:
-
addUser(userId: String, age: Int, country: String, subscribed: Boolean): Boolean- adds a new user with the specified attributes. Returnstrueif the user was added successfully andfalseif a user with the sameuserIdalready exists. -
getUser(userId: String): Map<String, Any?>?- returns the user's profile as a map if the user exists; otherwise, returnsnull. -
updateUser(userId: String, age: Int?, country: String?, subscribed: Boolean?): Boolean- updates the user's profile based on non-null parameters. Returnstrueif the user exists and was updated,falseotherwise.
Solution for the Starter Task
Here is the implementation of our starter task using Kotlin:
This implementation covers all our starter methods. Let's move forward and introduce more complex functionalities.
