Added methods and tests.

This commit is contained in:
Christian P. MOMON 2017-05-04 21:59:40 +02:00
parent 774651dd10
commit 17c37ba07f
3 changed files with 228 additions and 0 deletions

View file

@ -1274,6 +1274,29 @@ public class StringList extends ArrayList<String> implements CharSequence
return result;
}
/**
* Shrink all string of the list to only one string.
*
* @return the string list
*/
public StringList shrink()
{
StringList result;
if (!isEmpty())
{
String shrinked = toString();
clear();
add(shrinked);
}
//
result = this;
//
return result;
}
/**
* Sorts this list.
*

View file

@ -31,6 +31,7 @@ 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;
@ -502,6 +503,92 @@ public class StringstUtils
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.
*
@ -748,6 +835,40 @@ public class StringstUtils
}
}
/**
* Swap case.
*
* @param source
* the source
*/
public static void swapCase(final StringList source)
{
if (source != null)
{
for (int index = 0; index < source.size(); index++)
{
source.set(index, StringUtils.swapCase(source.get(index)));
}
}
}
/**
* Swap case.
*
* @param source
* the source
*/
public static void swapCase(final StringSet source)
{
if (source != null)
{
StringList values = new StringList(source);
swapCase(values);
source.clear();
source.addAll(values);
}
}
/**
* Concatenates the string from an array to a string.
*
@ -1338,6 +1459,40 @@ public class StringstUtils
return result;
}
/**
* Uncapitalize.
*
* @param source
* the source
*/
public static void uncapitalize(final StringList source)
{
if (source != null)
{
for (int index = 0; index < source.size(); index++)
{
source.set(index, StringUtils.uncapitalize(source.get(index)));
}
}
}
/**
* Uncapitalize.
*
* @param source
* the source
*/
public static void uncapitalize(final StringSet source)
{
if (source != null)
{
StringList values = new StringList(source);
uncapitalize(values);
source.clear();
source.addAll(values);
}
}
/**
* Upper case.
*

View file

@ -245,6 +245,56 @@ public class StringListTest
logger.debug("===== test done.");
}
/**
* Test shrink 01.
*/
@Test
public void testShrink01()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
Assert.assertEquals(0, source.size());
source.shrink();
Assert.assertEquals(0, source.size());
//
logger.debug("===== test done.");
}
/**
* Test shrink 01.
*/
@Test
public void testShrink02()
{
//
logger.debug("===== test starting...");
//
StringList source = new StringList();
source.append("alpha");
source.append("bravo");
source.append("charlie");
source.append("delta");
Assert.assertEquals(4, source.size());
source.shrink();
Assert.assertEquals(1, source.size());
Assert.assertEquals("alphabravocharliedelta", source.get(0));
//
logger.debug("===== test done.");
}
/**
* Test substring 01.
*/