From b6fd646b5cde349c397bc47afa7c71ac65fbc295 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Wed, 20 May 2015 15:27:04 +0000 Subject: [PATCH] Added spaced String generation method --- src/zutil/StringUtil.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/zutil/StringUtil.java b/src/zutil/StringUtil.java index 8cb5a92..c87aa7c 100644 --- a/src/zutil/StringUtil.java +++ b/src/zutil/StringUtil.java @@ -24,6 +24,8 @@ package zutil; import zutil.converters.Converter; +import java.util.ArrayList; + /** * This is a class whit utility methods. * @@ -207,4 +209,24 @@ public class StringUtil { return output.toString(); } + + + private static ArrayList SPACES = new ArrayList(); + /** + * @return A string containing a specific amount of spaces + */ + public static String getSpaces(int i){ + if(SPACES.size() <= i){ // Generate the String with spaces + synchronized (SPACES) { // Make sure no one else updates the list at the same time + if(SPACES.size() <= i) { // Make sure the previous synchronized thread hasn't already generated strings + if (SPACES.isEmpty()) + SPACES.add(""); + for (int j = SPACES.size(); j <= i; j++) { + SPACES.add(SPACES.get(j - 1) + " "); + } + } + } + } + return SPACES.get(i); + } }