From 438bf2e618341697ab03a1bec5ba12330f5c4fc6 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Tue, 24 Sep 2013 00:42:47 +0200 Subject: [PATCH] Add clone method and clone constructor (no issue about deep or shallow copy because StringList is an array of immutable objects. --- src/fr/devinsy/util/StringList.java | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/fr/devinsy/util/StringList.java b/src/fr/devinsy/util/StringList.java index e4bbc75..e663390 100755 --- a/src/fr/devinsy/util/StringList.java +++ b/src/fr/devinsy/util/StringList.java @@ -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 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 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 implements CharSequence return (result); } + /** + * + * @return + */ + public StringList sort() + { + StringList result; + + Collections.sort(this); + + // + result = this; + + // + return result; + } + /** * */