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

Refactored and added methods.

parent ee450891
......@@ -18,7 +18,6 @@
*/
package fr.devinsy.util.strings;
import java.io.IOException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collection;
......@@ -84,66 +83,59 @@ public class StringList extends ArrayList<String> implements CharSequence
}
/**
* Constructs a list of string from a string array.
* Constructs a list of string from an Object array.
*
* @param source
*/
public StringList(final String... source)
public StringList(final Object... source)
{
super();
if (source != null)
{
//
ensureCapacity(source.length);
//
for (String string : source)
{
this.add(string);
}
append(source);
}
}
/**
* Appends the string of the array argument to this boolean list.
* Constructs a list of string from a string array.
*
* @param strings
* @return
* @param source
*/
public StringList append(final boolean... items)
public StringList(final String... source)
{
StringList result;
super();
if (items != null)
if (source != null)
{
for (boolean item : items)
//
ensureCapacity(source.length);
//
for (String string : source)
{
this.append(item);
this.add(string);
}
}
result = this;
//
return result;
}
/**
* Appends the string of the array argument to this byte list.
* Appends the string of the array argument to this string list.
*
* @param strings
* @return
*/
public StringList append(final byte... items)
public StringList append(final boolean... values)
{
StringList result;
if (items != null)
if (values != null)
{
for (byte item : items)
for (boolean value : values)
{
this.append(item);
this.append(value);
}
}
......@@ -172,30 +164,6 @@ public class StringList extends ArrayList<String> implements CharSequence
return result;
}
/**
* Appends the string of the array argument to this char list.
*
* @param strings
* @return
*/
public StringList append(final char... items)
{
StringList result;
if (items != null)
{
for (char item : items)
{
this.append(item);
}
}
result = this;
//
return result;
}
/**
* Appends the string of the specified collection, in the order they are
* returned by the collection's iterator.
......@@ -272,6 +240,30 @@ public class StringList extends ArrayList<String> implements CharSequence
return result;
}
/**
* Appends the string of the array argument to this string list.
*
* @param values
* @return
*/
public StringList append(final Long... values)
{
StringList result;
if (values != null)
{
for (Long value : values)
{
this.append(value);
}
}
result = this;
//
return result;
}
/**
* Appends the string representation of the int argument to this string
* list.
......@@ -295,20 +287,20 @@ public class StringList extends ArrayList<String> implements CharSequence
}
/**
* Appends the string of the array argument to this short list.
* Appends the string of the array argument to this string list.
*
* @param strings
* @return
*/
public StringList append(final short... items)
public StringList append(final Object... values)
{
StringList result;
if (items != null)
if (values != null)
{
for (short item : items)
for (Object value : values)
{
this.append(item);
this.append(value);
}
}
......@@ -372,7 +364,7 @@ public class StringList extends ArrayList<String> implements CharSequence
{
for (String string : strings)
{
this.add(string);
this.append(string);
}
}
......@@ -399,60 +391,6 @@ public class StringList extends ArrayList<String> implements CharSequence
return result;
}
/**
* Appends the string of the array argument to this boolean list.
*
* @param items
* @return
*/
public StringList appendln(final boolean... items)
{
StringList result;
append(items).appendln();
result = this;
//
return result;
}
/**
* Appends the string of the array argument to this byte list.
*
* @param items
* @return
*/
public StringList appendln(final byte... items)
{
StringList result;
append(items).appendln();
result = this;
//
return result;
}
/**
* Appends the string of the array argument to this char list.
*
* @param strings
* @return
*/
public StringList appendln(final char... items)
{
StringList result;
append(items).appendln();
result = this;
//
return result;
}
/**
* Appends the string representation of the char argument to this string
* list, then append a break line too.
......@@ -539,35 +477,35 @@ public class StringList extends ArrayList<String> implements CharSequence
}
/**
* Appendln.
* Appends the string of the array argument to this string list.
*
* @param value
* the value
* @return the string list
* @param values
* @return
*/
public StringList appendln(final Object value)
public StringList appendln(final Object... values)
{
StringList result;
result = this.append(value).appendln();
append(values).appendln();
result = this;
//
return result;
}
/**
* Appends the string of the array argument to this short list.
* Appendln.
*
* @param strings
* @return
* @param value
* the value
* @return the string list
*/
public StringList appendln(final short... items)
public StringList appendln(final Object value)
{
StringList result;
append(items).appendln();
result = this;
result = this.append(value).appendln();
//
return result;
......@@ -1797,35 +1735,4 @@ public class StringList extends ArrayList<String> implements CharSequence
return result;
}
/**
* Writes the strings of this list into a {@code PrintWriter}.
*
* @param out
* The {@code PrintWriter} where to write.
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void writeInto(final java.io.PrintWriter out) throws IOException
{
for (String string : this)
{
out.write(string);
}
}
/**
* Writes the strings of this list into a {@code Writer}.
*
* @param out
* The {@code Writer} where to write.
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void writeInto(final java.io.Writer out) throws IOException
{
for (String string : this)
{
out.write(string);
}
}
}
......@@ -1004,6 +1004,266 @@ public class StringsUtils
return result;
}
public static StringList toStringList(final boolean... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (boolean value : source)
{
result.append(value);
}
}
//
return result;
}
public static StringList toStringList(final Boolean... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (Boolean value : source)
{
result.append(String.valueOf(value));
}
}
//
return result;
}
public static StringList toStringList(final byte... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (byte value : source)
{
result.append(value);
}
}
//
return result;
}
public static StringList toStringList(final Byte... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (Byte value : source)
{
result.add(String.valueOf(value));
}
}
//
return result;
}
public static StringList toStringList(final char... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (char value : source)
{
result.append(value);
}
}
//
return result;
}
public static StringList toStringList(final double... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (double value : source)
{
result.append(value);
}
}
//
return result;
}
public static StringList toStringList(final Double... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (Double value : source)
{
result.add(String.valueOf(value));
}
}
//
return result;
}
public static StringList toStringList(final float... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (float value : source)
{
result.append(value);
}
}
//
return result;
}
public static StringList toStringList(final Float... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (Float value : source)
{
result.add(String.valueOf(value));
}
}
//
return result;
}
public static StringList toStringList(final long... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (long value : source)
{
result.append(value);
}
}
//
return result;
}
public static StringList toStringList(final Long... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (Long value : source)
{
result.add(String.valueOf(value));
}
}
//
return result;
}
public static StringList toStringList(final short... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (short value : source)
{
result.append(value);
}
}
//
return result;
}
public static StringList toStringList(final Short... source)
{
StringList result;
result = new StringList();
if (source != null)
{
result.ensureCapacity(source.length);
for (Short value : source)
{
result.add(String.valueOf(value));
}
}
//
return result;
}
/**
* Concatenates the string from an array to a string.
*
......@@ -1520,4 +1780,42 @@ public class StringsUtils
source.addAll(values);
}
}
/**
* Writes the strings of this list into a {@code PrintWriter}.
*
* @param out
* The {@code PrintWriter} where to write.
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void writeTo(final StringList source, final java.io.PrintWriter out) throws IOException