Java List Remove removeEmptyColumns(List data)

Here you can find the source of removeEmptyColumns(List data)

Description

remove Empty Columns

License

Open Source License

Declaration

public static List<String> removeEmptyColumns(List<String> data) 

Method Source Code

//package com.java2s;
/* ========================================================================
 * PlantUML : a free UML diagram generator
 * ========================================================================
 *
 * (C) Copyright 2009, Arnaud Roques//from ww  w. j a  va 2s.c  o m
 *
 * Project Info:  http://plantuml.sourceforge.net
 * 
 * This file is part of PlantUML.
 *
 * PlantUML is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * PlantUML distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
 * in the United States and other countries.]
 *
 * Original Author:  Arnaud Roques
 *
 * Revision $Revision: 7638 $
 *
 */

import java.util.ArrayList;
import java.util.Collections;

import java.util.List;

public class Main {
    public static List<String> removeEmptyColumns(List<String> data) {
        if (firstColumnRemovable(data) == false) {
            return data;
        }
        final List<String> result = new ArrayList<String>(data);
        do {
            removeFirstColumn(result);
        } while (firstColumnRemovable(result));
        return Collections.unmodifiableList(result);
    }

    private static boolean firstColumnRemovable(List<String> data) {
        boolean allEmpty = true;
        for (String s : data) {
            if (s.length() == 0) {
                continue;
            }
            allEmpty = false;
            final char c = s.charAt(0);
            if (c != ' ' && c != '\t') {
                return false;
            }
        }
        return allEmpty == false;
    }

    private static void removeFirstColumn(List<String> data) {
        for (int i = 0; i < data.size(); i++) {
            final String s = data.get(i);
            if (s.length() > 0) {
                data.set(i, s.substring(1));
            }
        }
    }
}

Related

  1. removeByRef(List list, Object obj)
  2. removeElement(T element, List list)
  3. removeElementsFromList(List inputList, List elementsToRemove)
  4. removeEmpties(List original)
  5. removeEmpty(List strings)
  6. removeEmptyLines(List lines)
  7. removeEmptyLinesFromEnd(List list)
  8. removeEmptyLinesOnSides(List lines)
  9. removeEmptyLists(Map map)