From ab1a21d89853752d341f74abba3be0022cf9fd05 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Sun, 2 Feb 2014 19:03:13 +0100 Subject: [PATCH] Add getFirst, getLast, repeatLast methods. --- src/fr/devinsy/util/StringList.java | 70 +++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/fr/devinsy/util/StringList.java b/src/fr/devinsy/util/StringList.java index e663390..dbce24f 100755 --- a/src/fr/devinsy/util/StringList.java +++ b/src/fr/devinsy/util/StringList.java @@ -368,6 +368,46 @@ public class StringList extends ArrayList implements CharSequence 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 @@ -460,6 +500,36 @@ public class StringList extends ArrayList implements CharSequence 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