Add getFirst, getLast, repeatLast methods.

This commit is contained in:
Christian P. MOMON 2014-02-02 19:03:13 +01:00
parent 19d2f6f0b0
commit ab1a21d898

View file

@ -368,6 +368,46 @@ public class StringList extends ArrayList<String> implements CharSequence
return (result); return (result);
} }
/**
*
*/
public String getFirst()
{
String result;
if (this.size() == 0)
{
result = null;
}
else
{
result = get(0);
}
//
return (result);
}
/**
*
*/
public String getLast()
{
String result;
if (this.size() == 0)
{
result = null;
}
else
{
result = get(this.size() - 1);
}
//
return (result);
}
/** /**
* *
* @param index * @param index
@ -460,6 +500,36 @@ public class StringList extends ArrayList<String> implements CharSequence
return (result); return (result);
} }
/**
*
*/
public StringList repeatLast(final int count)
{
StringList result;
//
if ((this.size() != 0) && (count > 0))
{
//
this.ensureCapacity(this.size() + count);
//
String last = getLast();
//
for (int index = 0; index < count; index++)
{
this.append(last);
}
}
//
result = this;
//
return (result);
}
/** /**
* *
* @return * @return