Merge branch 'development' into task/seperated-library-loading

This commit is contained in:
Jeroen Ketelaar
2017-02-03 22:52:20 +01:00
committed by GitHub
4 changed files with 38 additions and 57 deletions
+2 -11
View File
@@ -210,17 +210,8 @@ public class Core {
* Method that removes the cache contents after 3 days
*/
private static void validateCache() {
File[] cache = Directories.getCachePath().listFiles();
if (cache != null) {
for (File f : cache) {
long age = new Date().getTime() - f.lastModified();
if (age > 3 * 24 * 60 * 60 * 1000) {
f.delete();
}
}
}
// Already handled by Directories initiating
// Method will be used once BDN V3 has a functionality for this
}
public static void downloadNewVersion() {
@@ -1,52 +1,10 @@
package org.parabot.environment.api.utils;
import org.parabot.api.misc.StringUtil;
/**
* @author mkyong, JKetelaar
*/
public class StringUtils {
public class StringUtils extends StringUtil {
private static java.util.Random random = new java.util.Random();
private static char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
public static String convertHexToString(String hex) {
StringBuilder sb = new StringBuilder();
StringBuilder temp = new StringBuilder();
for (int i = 0; i < hex.length() - 1; i += 2) {
// grab the hex in pairs
String output = hex.substring(i, (i + 2));
// convert hex to decimal
int decimal = Integer.parseInt(output, 16);
// convert the decimal to character
sb.append((char) decimal);
temp.append(decimal);
}
return sb.toString();
}
public static String implode(String separator, String... data) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.length - 1; i++) {
//data.length - 1 => to not add separator at the end
if (!data[i].matches(" *")) {//empty string are ""; " "; " "; and so on
sb.append(data[i]);
sb.append(separator);
}
}
sb.append(data[data.length - 1].trim());
return sb.toString();
}
public static String randomString(final int length) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 20; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
}
return sb.toString();
}
}