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:
Christian P. MOMON 2013-09-24 00:42:47 +02:00
parent b2c058caf3
commit 438bf2e618

View file

@ -7,6 +7,7 @@ package fr.devinsy.util;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
/** /**
* This class is a collection of String objects with specific methods. It makes * 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) 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) for (String string : source)
{ {
this.add(string); this.add(string);
@ -308,6 +333,28 @@ public class StringList extends ArrayList<String> implements CharSequence
return result; 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 (result);
} }
/**
*
* @return
*/
public StringList sort()
{
StringList result;
Collections.sort(this);
//
result = this;
//
return result;
}
/** /**
* *
*/ */