рефакторинг. ввел оберточные методы работы с json объектами
This commit is contained in:
@@ -34,7 +34,15 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
public class Utils {
|
||||
public static Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
public static final Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||
public static Object jsonFromFile(File file, Class json_class) throws Exception {
|
||||
String packed = FileUtils.readFileToString(file, Charset.defaultCharset());
|
||||
return Utils.gson.fromJson(packed, json_class);
|
||||
}
|
||||
public static void jsonToFile(Object json_object, File file) throws Exception {
|
||||
FileUtils.writeStringToFile(file, Utils.jsonToPrettyFormat(Utils.gson.toJson(json_object)));
|
||||
}
|
||||
//--->>
|
||||
public static String hideRegularMetasymbols(String word) {
|
||||
String res = word.replace("\\", "\\\\");
|
||||
for (char c : Constants.regular_metasymbols)
|
||||
@@ -896,72 +904,23 @@ public class Utils {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static char toStrike = (char) 822;
|
||||
public static String strikeThrough(String s) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : s.toCharArray()) {
|
||||
res.append(c);
|
||||
if (c != toStrike)
|
||||
res.append(toStrike);
|
||||
if (c != Constants.toStrike)
|
||||
res.append(Constants.toStrike);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
public static String noStrikeThrough(String s) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : s.toCharArray()) {
|
||||
if (c != (toStrike))
|
||||
if (c != (Constants.toStrike))
|
||||
res.append(c);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
public static String splitToolTip(String tip, int length) {
|
||||
int DIALOG_TOOLTIP_MAX_SIZE = 75;
|
||||
int SPACE_BUFFER = 10;
|
||||
if (tip.length() <= length + SPACE_BUFFER) {
|
||||
return tip;
|
||||
}
|
||||
Vector<String> parts = new Vector<>();
|
||||
int maxLength = 0;
|
||||
String overLong = tip.substring(0, length + SPACE_BUFFER);
|
||||
int lastSpace = overLong.lastIndexOf(' ');
|
||||
if (lastSpace >= length) {
|
||||
parts.add(tip.substring(0, lastSpace));
|
||||
maxLength = lastSpace;
|
||||
} else {
|
||||
parts.add(tip.substring(0, length));
|
||||
maxLength = length;
|
||||
}
|
||||
while (maxLength < tip.length()) {
|
||||
if (maxLength + length < tip.length()) {
|
||||
parts.add(tip.substring(maxLength, maxLength + length));
|
||||
maxLength += maxLength + length;
|
||||
} else {
|
||||
parts.add(tip.substring(maxLength));
|
||||
break;
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("<html>");
|
||||
for (int i = 0; i < parts.size() - 1; i++) {
|
||||
sb.append(parts.get(i) + "<br>");
|
||||
}
|
||||
sb.append(parts.get(parts.size() - 1));
|
||||
sb.append(("</html>"));
|
||||
return sb.toString();
|
||||
}
|
||||
/*
|
||||
public static String appendString(String s, int sizeTo, char symbol) {
|
||||
int delta = sizeTo - s.length();
|
||||
StringBuilder res = new StringBuilder(s);
|
||||
if (delta <= 0) {
|
||||
for (int i = 0; i < sizeTo; ++i)
|
||||
res.append(symbol);
|
||||
}
|
||||
for (int i = 0; i < delta; ++i) {
|
||||
res.append(symbol);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
*/
|
||||
public static void addEmptyLines(Vector<String> lines, int num) {
|
||||
IntStream.range(0, num).mapToObj(i -> "").forEach(lines::add);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user