Add clone method and clone constructor (no issue about deep or shallow
copy because StringList is an array of immutable objects.
This commit is contained in:
parent
b2c058caf3
commit
438bf2e618
1 changed files with 64 additions and 0 deletions
|
@ -7,6 +7,7 @@ package fr.devinsy.util;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* This class is a collection of String objects with specific methods. It makes
|
||||
|
@ -45,6 +46,30 @@ public class StringList extends ArrayList<String> implements CharSequence
|
|||
|
||||
if (source != null)
|
||||
{
|
||||
//
|
||||
ensureCapacity(source.length);
|
||||
|
||||
//
|
||||
for (String string : source)
|
||||
{
|
||||
this.add(string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public StringList(final StringList source)
|
||||
{
|
||||
super();
|
||||
|
||||
if (source != null)
|
||||
{
|
||||
//
|
||||
ensureCapacity(source.size());
|
||||
|
||||
//
|
||||
for (String string : source)
|
||||
{
|
||||
this.add(string);
|
||||
|
@ -308,6 +333,28 @@ public class StringList extends ArrayList<String> implements CharSequence
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep copy and shallow copy have no sense about a list of immutable
|
||||
* objects.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public StringList clone()
|
||||
{
|
||||
StringList result;
|
||||
|
||||
result = new StringList(size());
|
||||
|
||||
for (String string : this)
|
||||
{
|
||||
result.add(string);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -413,6 +460,23 @@ public class StringList extends ArrayList<String> implements CharSequence
|
|||
return (result);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public StringList sort()
|
||||
{
|
||||
StringList result;
|
||||
|
||||
Collections.sort(this);
|
||||
|
||||
//
|
||||
result = this;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue