Added join method to StringUtil

This commit is contained in:
Ziver Koc 2015-12-10 21:45:14 +01:00
parent 78b1171754
commit 515bf60309
4 changed files with 33 additions and 3 deletions

View file

@ -27,6 +27,8 @@ package zutil;
import zutil.converters.Converter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* This is a class whit utility methods.
@ -128,6 +130,23 @@ public class StringUtil {
return str.reverse().toString();
}
/**
* @param list a list of object that toString() will be called on
* @param delimiter a String delimiter that will be added between every entry in the list
* @return a String containing all entries in the list with the specified delimiter in between entries
*/
public static String join(Iterable<?> list, String delimiter){
StringBuilder str = new StringBuilder();
Iterator<?> it = list.iterator();
if(it.hasNext()) {
str.append(it.next());
while (it.hasNext()) {
str.append(delimiter).append(it.next());
}
}
return str.toString();
}
/**
* Trims the given char and whitespace at the beginning and the end
*

View file

@ -1,6 +1,6 @@
package zutil.db;
import com.sun.deploy.util.StringUtils;
import zutil.StringUtil;
import zutil.db.handler.ListSQLResult;
import zutil.db.handler.SimpleSQLResult;
import zutil.log.LogUtil;
@ -18,7 +18,7 @@ import java.util.logging.Logger;
/**
* This class will take a reference DB and alter
* the source DB to have the same structure.
* NOTE: only works with sqllite
* NOTE: only works with SQLite
*
* Created by Ziver
*/
@ -162,7 +162,7 @@ public class DBUpgradeHandler {
// Restoring data
logger.fine("Forced Upgrade: Restoring data for table: "+table);
String cols = StringUtils.join(refStruct, ",");
String cols = StringUtil.join(refStruct, ",");
target.exec(String.format(
"INSERT INTO %s (%s) SELECT %s FROM %s",
table, cols, cols, backupTable));