Java List Remove removeEmptyLists(Map map)

Here you can find the source of removeEmptyLists(Map map)

Description

remove Empty Lists

License

Open Source License

Declaration

public static void removeEmptyLists(Map<String, Object> map) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class Main {
    public static void removeEmptyLists(Map<String, Object> map) {
        for (Iterator<Map.Entry<String, Object>> it = map.entrySet()
                .iterator(); it.hasNext();) {
            Map.Entry<String, Object> entry = it.next();

            if (entry.getValue() == null) {
                it.remove();//w w  w  .ja  v a 2s  . c o  m
            } else if (entry.getKey().equals("coordinates")) { // hack because schema for coordinates is inconsistent
                it.remove();
            } else if (entry.getValue() instanceof List) {
                if (((ArrayList<?>) entry.getValue()).size() == 0) {
                    it.remove();
                }
            } else if (entry.getValue() instanceof Map) {
                if (((Map) entry.getValue()).size() == 0) {
                    it.remove();
                } else {
                    removeEmptyLists((Map) entry.getValue());
                    if (((Map) entry.getValue()).size() == 0) {
                        it.remove();
                    }
                }
            }
        }
    }
}

Related

  1. removeEmpty(List strings)
  2. removeEmptyColumns(List data)
  3. removeEmptyLines(List lines)
  4. removeEmptyLinesFromEnd(List list)
  5. removeEmptyLinesOnSides(List lines)
  6. removeEmptyStringsFromList(List list)
  7. removeEmptyStringsInList(List list)
  8. removeEmptyTags(List tags)
  9. removeEmptyValues(final List values)