From b66727b4fde5afcb5cf40384b685261aff25a103 Mon Sep 17 00:00:00 2001 From: Marco Zanon Date: Thu, 5 Apr 2012 21:16:18 +0000 Subject: [PATCH] Added repeat() method to MText. --- src/java/com/marcozanon/macaco/text/MText.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/java/com/marcozanon/macaco/text/MText.java b/src/java/com/marcozanon/macaco/text/MText.java index 6500fe3..2bed714 100644 --- a/src/java/com/marcozanon/macaco/text/MText.java +++ b/src/java/com/marcozanon/macaco/text/MText.java @@ -10,7 +10,7 @@ import com.marcozanon.macaco.MObject; public class MText extends MObject { - /* */ + /* Checks */ public static boolean isBlank(String x) { if ((null == x) || ("".equals(x))) { @@ -19,4 +19,18 @@ public class MText extends MObject { return false; } + /* Utility methods */ + + public static String repeat(String x, int times) { + if (times < 1) { + throw new IllegalArgumentException(String.format("Invalid 'times': %s.", times)); + } + // + StringBuilder y = new StringBuilder(""); + for (int i = 0; i < times; i++) { + y = y.append(x); + } + return y.toString(); + } + } -- 2.30.2