Java List Move Item getLongestLine(String text, List partsToRemove, String separator)

Here you can find the source of getLongestLine(String text, List partsToRemove, String separator)

Description

get Longest Line

License

LGPL

Declaration

public static String getLongestLine(String text, List<String> partsToRemove, String separator) 

Method Source Code

//package com.java2s;
/*/*from w w  w. ja va 2s. co  m*/
Strandz LGPL - an API that matches the user to the data.
Copyright (C) 2007 Chris Murphy
    
Strandz LGPL is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
    
This library is 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 Lesser 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
    
    
The authors can be contacted via www.strandz.org
*/

import java.util.List;

public class Main {
    public static String getLongestLine(String text, List<String> partsToRemove, String separator) {
        String result = null;
        String toInvestigate = removeParts(text, partsToRemove);
        String longest = "";
        String words[] = toInvestigate.split(separator);
        for (int i = 0; i < words.length; i++) {
            String word = words[i];
            if (word.length() > longest.length()) {
                longest = word;
            }
        }
        if (!longest.equals("")) {
            result = longest;
        }
        return result;
    }

    public static String removeParts(String text, List<String> parts) {
        String result;
        if (text != null) {
            for (int i = 0; i < parts.size(); i++) {
                String part = parts.get(i);
                while (text.contains(part)) {
                    text = remove(text, part);
                }
            }
        }
        result = text;
        return result;
    }

    /**
     * If result == in then nothing happened so don't do it again
     *
     * @param in
     * @param toRemove
     * @return
     */
    public static String remove(String in, String toRemove) {
        String result = in;
        int index = in.indexOf(toRemove);
        if (index != -1) {
            String before = in.substring(0, index);
            String after = in.substring(index + toRemove.length(), in.length());
            result = before.concat(after);
        }
        return result;
    }
}

Related

  1. addRemoveChangeToString(int from, int to, List list, List removed)
  2. canMoveUp(List list, int[] indices)
  3. getRemoveAll(List list1, Collection list2)
  4. minus(List initialList, List elementsToRemove)
  5. move(List aList, int anIndex1, int anIndex2)
  6. move(List collection, int indexToMoveFrom, int indexToMoveAt)