Commit ee450891 authored by Christian P. MOMON's avatar Christian P. MOMON
Browse files

Fixed name.

parent ff98c0ae
/*
* Copyright (C) 2008-2010,2013-2016,2017 Christian Pierre MOMON
*
* This file is part of Devinsy-strings.
*
* Devinsy-strings 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 3 of the License, or
* (at your option) any later version.
*
* Devinsy-strings 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 Devinsy-strings. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.util.strings;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.lang3.StringUtils;
/**
* The {@code StringUtils} class defines helper methods to string collection.
*
* Operations that are null safe.
*/
public class StringsUtils
{
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
/**
* Instantiates a new stringst utils.
*/
private StringsUtils()
{
}
/**
* Capitalize.
*
* @param sourceStringUtils
* .lo the source
*/
public static void capitalize(final StringList source)
{
if (source != null)
{
for (int index = 0; index < source.size(); index++)
{
source.set(index, StringUtils.capitalize(source.get(index)));
}
}
}
/**
* Capitalize.
*
* @param source
* the source
*/
public static void capitalize(final StringSet source)
{
if (source != null)
{
StringList values = new StringList(source);
capitalize(values);
source.clear();
source.addAll(values);
}
}
/**
* Builds a string concatenating many times a source string.
*
* @param source
* The string to concatenate several time.
* @param multiplier
* The number of concatenate to produce.
* @return the string
*/
public static String concatenate(final String source, final int multiplier)
{
String result;
result = repeat(source, multiplier).toString();
//
return result;
}
/**
* Contains blank.
*
* @param source
* the source
* @return true, if successful
*/
public static boolean containsBlank(final Collection<String> source)
{
boolean result;
if (source == null)
{
result = false;
}
else if (source instanceof StringList)
{
result = ((StringList) source).containsBlank();
}
else
{
result = new StringList(source).containsBlank();
}
//
return result;
}
/**
* Contains blank.
*
* @param source
* the source
* @return true, if successful
*/
public static boolean containsBlank(final String... source)
{
boolean result;
if (source == null)
{
result = false;
}
else
{
result = new StringList(source).containsBlank();
}
//
return result;
}
/**
* Contains empty.
*
* @param source
* the source
* @return true, if successful
*/
public static boolean containsEmpty(final Collection<String> source)
{
boolean result;
if (source == null)
{
result = false;
}
else if (source instanceof StringList)
{
result = ((StringList) source).containsEmpty();
}
else
{
result = new StringList(source).containsEmpty();
}
//
return result;
}
/**
* Contains empty.
*
* @param source
* the source
* @return true, if successful
*/
public static boolean containsEmpty(final String... source)
{
boolean result;
if (source == null)
{
result = false;
}
else
{
result = new StringList(source).containsEmpty();
}
//
return result;
}
/**
* Contains null.
*
* @param source
* the source
* @return true, if successful
*/
public static boolean containsNull(final Collection<String> source)
{
boolean result;
if (source == null)
{
result = false;
}
else if (source instanceof StringList)
{
result = ((StringList) source).containsNull();
}
else
{
result = new StringList(source).containsNull();
}
//
return result;
}
/**
* Contains null.
*
* @param source
* the source
* @return true, if successful
*/
public static boolean containsNull(final String... source)
{
boolean result;
if (source == null)
{
result = false;
}
else
{
result = new StringList(source).containsNull();
}
//
return result;
}
/**
* Find longest.
*
* @param source
* the source
* @return the string
*/
public static String findLongest(final Collection<String> source)
{
String result;
if ((source == null) || (source.isEmpty()))
{
result = null;
}
else
{
int value = 0;
result = null;
for (String string : source)
{
if ((string != null) && (string.length() > value))
{
value = string.length();
result = string;
}
}
}
//
return result;
}
/**
* Find longest length.
*
* @param source
* the source
* @return the int
*/
public static int findLongestLength(final Collection<String> source)
{
int result;
String string = findLongest(source);
if (string == null)
{
result = 0;
}
else
{
result = string.length();
}
//
return result;
}
/**
* Find smallest.
*
* @param source
* the source
* @return the string
*/
public static String findShortest(final Collection<String> source)
{
String result;
if ((source == null) || (source.isEmpty()))
{
result = null;
}
else
{
int value = Integer.MAX_VALUE;
result = null;
for (String string : source)
{
if ((string != null) && (string.length() < value))
{
value = string.length();
result = string;
}
}
}
//
return result;
}
/**
* Find smallest length.
*
* @param source
* the source
* @return the int
*/
public static int findShortestLength(final Collection<String> source)
{
int result;
String string = findShortest(source);
if (string == null)
{
result = 0;
}
else
{
result = string.length();
}
//
return result;
}
/**
* Gets the complement.
*
* @param alpha
* the alpha
* @param bravo
* the bravo
* @return the complement
*/
public static StringSet getComplement(final Collection<String> alpha, final Collection<String> bravo)
{
StringSet result;
result = getDifference(bravo, alpha);
//
return result;
}
/**
* Gets the difference.
*
* @param alpha
* the alpha
* @param bravo
* the bravo
* @return the difference
*/
public static StringSet getDifference(final Collection<String> alpha, final Collection<String> bravo)
{
StringSet result;
result = new StringSet(alpha);
result.removeAll(bravo);
//
return result;
}
/**
* Gets the disjunction.
*
* @param alpha
* the alpha
* @param bravo
* the bravo
* @return the disjunction
*/
public static StringSet getDisjunction(final Collection<String> alpha, final Collection<String> bravo)
{
StringSet result;
result = new StringSet();
for (String string : alpha)
{
if (!bravo.contains(string))
{
result.add(string);
}
}
for (String string : bravo)
{
if (!alpha.contains(string))
{
result.add(string);
}
}
//
return result;
}
/**
* Gets the intersection of.
*
* @param alpha
* the alpha
* @param bravo
* the bravo
* @return the intersection of
*/
public static StringSet getIntersectionOf(final Collection<String> alpha, final Collection<String> bravo)
{
StringSet result;
result = new StringSet();
for (String string : alpha)
{
if (bravo.contains(string))
{
result.add(string);
}
}
//
return result;
}
/**
* Gets the union of.
*
* @param alpha
* the alpha
* @param bravo
* the bravo
* @return the union of
*/
public static StringSet getUnionOf(final Collection<String> alpha, final Collection<String> bravo)
{
StringSet result;
result = new StringSet(alpha);
for (String string : bravo)
{
result.add(string);
}
//
return result;
}
/**
* Checks if is blank.
*
* @param source
* the source
*/
public static boolean isBlank(final Collection<String> source)
{
boolean result;
if (source == null)
{
result = true;
}
else
{
Iterator<String> iterator = source.iterator();
boolean ended = false;
result = false;
while (!ended)
{
if (iterator.hasNext())
{
String value = iterator.next();
if (StringUtils.isNotBlank(value))
{
ended = true;
result = false;
}
}
else
{
ended = true;
result = true;
}
}
}
//
return result;
}
/**
* Checks if is empty.
*
* @param source
* the source
* @return true, if is empty
*/
public static boolean isEmptyFully(final Collection<String> source)
{
boolean result;
if ((source == null) || (source.isEmpty()))
{
result = true;
}
else
{
Iterator<String> iterator = source.iterator();
boolean ended = false;
result = false;
while (!ended)
{
if (iterator.hasNext())
{
String value = iterator.next();
if (StringUtils.isNotEmpty(value))
{
ended = true;
result = false;
}
}
else
{
ended = true;
result = true;
}
}
}
//
return result;
}
/**
* Load.
*
* @param source
* the source
* @return the string list
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static StringList load(final File source) throws IOException
{
StringList result;
result = load(source, DEFAULT_CHARSET_NAME);
//
return result;
}
/**
* Load.
*
* @param file
* the file
* @param charsetName
* the charset name
* @return the string list
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static StringList load(final File file, final String charsetName) throws IOException
{
StringList result;
//