# Filter
The Filter class is used to filter out the data according to certain rules.
The objective of the Filter class is to perform filtering operations on the recommendedList generated by the Recommender class. The recommendedList is composed of a set of recommendedItem, which can be represented as a triple (userId itemId value).
The GenericRecommendedFilter instance returns the recommendedList that contains the recommendedItem with only the specific userId or itemId. The specific userId or itemId is set as a list in the GenericRecommendedFilter in advance.
The Filter is only used in the Java code.

The results of applying GenericRecommendedFilter are shown as follows.

```
userIdList = {"1", "2"}
recommendedList = {
    {userId:1 itemId:1 value:1.0},
    {userId:1 itemId:2 value:2.0},
    {userId:1 itemId:3 value:3.0},
    {userId:2 itemId:1 value:4.0},
    {userId:2 itemId:2 value:5.0},
    {userId:2 itemId:3 value:6.0},
    {userId:3 itemId:1 value:7.0},
    {userId:3 itemId:2 value:8.0},
    {userId:3 itemId:3 value:9.0}
}
filtered recommendedList = {
    {userId:1 itemId:2 value:2.0},
    {userId:2 itemId:3 value:6.0},
    {userId:1 itemId:1 value:1.0},
    {userId:2 itemId:1 value:4.0},
    {userId:2 itemId:2 value:5.0},
    {userId:1 itemId:3 value:3.0}
}
```

The example of the GenericRecommendedFilter class is shown as follows.

```java

// specify the userIds and itemIds for filter
userIdList = new ArrayList<>();
itemIdList = new ArrayList<>();
for (int i=1; i<=2; i++) {
    userIdList.add(Integer.toString(i));
    itemIdList.add(Integer.toString(4-i));
}

// generate recommendedList by recommender
Configuration conf = new Configuration();
Resource resource = new Resource("rec/cf/userknn-test.properties");
conf.addResource(resource);
DataModel dataModel = new TextDataModel(conf);
dataModel.buildDataModel();
RecommenderContext context = new RecommenderContext(conf, dataModel);
RecommenderSimilarity similarity = new PCCSimilarity();
similarity.buildSimilarityMatrix(dataModel);
context.setSimilarity(similarity);
Recommender recommender = new UserKNNRecommender();
recommender.setContext(context);
recommender.recommend(context);
List<RecommendedItem> recommendedItemList = recommender.getRecommendedList();

// filter the recommendedList with GenericRecommendedFilter
GenericRecommendedFilter filter = new GenericRecommendedFilter();
filter.setUserIdList(userIdList);
filter.setItemIdList(itemIdList);
recommendedItemList = filter.filter(recommendedItemList);
```
