比较子arraylist并删除父对象的对象

时间:2017-10-02 07:13:24

标签: java android

我很困惑,我有父数组(产品),它有内部数组(组件),我有第三个数组(filterdata),类似于父数组中的数组。我需要比较组件和过滤器,如果有些重复,则需要删除产品中的对象。

productsList = new ArrayList<>(mSortModels);
for (ProductComponentsResponse component : filterData) {
    String componentId = component.getId();
    int componentState = component.getState();
    Iterator<ProductResponse> iterator = productsList.iterator();
    while (iterator.hasNext()) {
        ProductResponse next = iterator.next();
        for (ProductComponentsResponse productComponentsResponse: next.getProductComponents()) {
            boolean containComponent = productComponentsResponse.getId().contains(componentId);
            if (componentState == ProductComponentsResponse.FilterState.NONE) {
                continue;
            }
            if (componentState == ProductComponentsResponse.FilterState.SELECTED) {
                if (!containComponent) {

                    iterator.remove();
                    break;
                }
            } else if (componentState == ProductComponentsResponse.FilterState.UNSELECTED) {
                if (containComponent) {
                    iterator.remove();
                    break;
                }
            }
        }
    }
}
notifyDataSetChanged();

0 个答案:

没有答案
相关问题