A
A
anton_nikitin2017-10-02 17:58:13
Android
anton_nikitin, 2017-10-02 17:58:13

Parent array filter?

Guys, hello everyone!
There is an array at the input and there is a parent array with a nested array. It is necessary to compare the input array and the nested array, if they match according to the given condition, then remove the object itself from the parent array. Here is the code, but somehow it works crookedly.

public void sort(List<ProductComponentsResponse> 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) {
                              Log.d("component", String.valueOf(productComponentsResponse.getId()));
                              Log.d("componentState", String.valueOf(componentState));
                              iterator.remove();
                              break;
                          }
                      } else if (componentState == ProductComponentsResponse.FilterState.UNSELECTED) {
                          if (containComponent) {
                              Log.d("_component", String.valueOf(productComponentsResponse.getId()));
                              Log.d("_componentState", String.valueOf(componentState));
                              iterator.remove();
                              break;
                          }
                      }
                  }
              }
          }
          notifyDataSetChanged();
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question