Added repeat() method to MText.
authorMarco Zanon <info@marcozanon.com>
Thu, 5 Apr 2012 21:16:18 +0000 (21:16 +0000)
committerMarco Zanon <info@marcozanon.com>
Thu, 5 Apr 2012 21:16:18 +0000 (21:16 +0000)
src/java/com/marcozanon/macaco/text/MText.java

index 6500fe3688bff63160202b2bcc59857484c5bc89..2bed7140663b41b65a8a9c3d958267513405ba33 100644 (file)
@@ -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();
+    }
+
 }