*/
package jalview.util;
+import java.util.Arrays;
+
/**
* DOCUMENT ME!
*
}
/**
- * DOCUMENT ME!
+ * Returns a string consisting of n repeats of character c
*
* @param c
- * DOCUMENT ME!
* @param n
- * DOCUMENT ME!
*
- * @return DOCUMENT ME!
+ * @return
*/
- private static String repeat(char c, int n)
+ static String repeat(char c, int n)
{
if (n <= 0)
{
return "";
}
-
- StringBuffer s = new StringBuffer(n);
-
- for (int i = 0; i < n; i++)
- {
- s.append(c);
- }
-
- return s.toString();
+ char[] chars = new char[n];
+ Arrays.fill(chars, c);
+ return new String(chars);
}
/**
assertEquals(f.form(123.6f), "124.");
assertEquals(f.form(129.6f), "130.");
}
+
+ @Test(groups = "Functional")
+ public void testRepeat()
+ {
+ assertEquals(Format.repeat('a', 3), "aaa");
+ assertEquals(Format.repeat('b', 0), "");
+ assertEquals(Format.repeat('c', -1), "");
+ }
}