I have a List of Object. The Object is of type of Class - UserType.
public class UserType {
private int userId = 0;
private int userTypeId = 0;
private String userType;
//Getters and Setters;
}
For the above mention List, I want to filter out the List based on the userType. The userType is not unique(can have same names and not duplicate), but a combination of userId, userTypeId and userType is unique.
So the requirement is, if I have userType as let us say - "ASSEMBLE", then I need to form a List with unique userType alone and also appending the userId and userTypeId as a List in the Bean.
EX: INPUT FORMAT:
[{userId: 1, userTypeId: 101, userType: "ASSEMBLE" },
{userId: 1, userTypeId: 102, userType: "ASSEMBLE" },
{userId: 2, userTypeId: 103, userType: "ARCHS" },
{userId: 3, userTypeId: 103, userType: "ARCHS" },
{userId: 4, userTypeId: 104, userType: "BAYLEAF" },
{userId: 4, userTypeId: 105, userType: "BAYLEAF" },
{userId: 5, userTypeId: 106, userType: "CHARSET" }]
EXPECTED: Results Filter out based on userType:
[{userIds: [1] userTypeIds: [101,102], userType: "ASSEMBLE" },
{userId: [2,3], userTypeId: [103], userType: "ARCHS" },
{userId: [4], userTypeId: [104,105] userType: "BAYLEAF" },
{userId: [5], userTypeId: [106], userType: "CHARSET" }]
So typically this must form a bean like -
public class UserType {
private String userType;
private List userIds = 0;
private List userTypeIds = 0;
//Getters and Setters;
}
How to filter this object based on the requirement? Can also provide solutions in Javascript so that will look into one which is much optimized solutions. Thanks in advance.
[{userId: 1, userTypeId: 101, userType: "ASSEMBLE" }, {userId: 2, userTypeId: 102, userType: "ASSEMBLE" }]. This gives[{userIds: [1,2] userTypeIds: [101,102], userType: "ASSEMBLE" }]. How do you distinguish that from an alternative input of[{userId: 1, userTypeId: 102, userType: "ASSEMBLE" }, {userId: 2, userTypeId: 101, userType: "ASSEMBLE" }]?