no message
This commit is contained in:
@@ -1,19 +1,32 @@
|
||||
package Common.Utils;
|
||||
import Common.CommonConstants;
|
||||
import Common_old.Utils.Utils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.stream.Collectors;
|
||||
public class CommonUtils {
|
||||
//Текущая оперционная система
|
||||
public static boolean isWindows=true;
|
||||
//Домашняя папка.
|
||||
public static String Home;
|
||||
//ГЛОБАЛЬНЫЙ ЖУРНАЛ
|
||||
public static Loggable MainLog;
|
||||
//------------------------------------------------------------------------
|
||||
//JSON
|
||||
//--
|
||||
// public static String jsonToPrettyFormat(String packed) {
|
||||
@@ -24,13 +37,62 @@ public class CommonUtils {
|
||||
// }
|
||||
//--
|
||||
public static Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
|
||||
//------------------------------------------------------------------
|
||||
//-
|
||||
public static <T> T jsonFromFile(File file, Class<T> json_class) throws Exception {
|
||||
return gson.fromJson(FileUtils.readFileToString(file, Charset.defaultCharset()), json_class);
|
||||
}
|
||||
public static void jsonToFile(Object json_object, File file) throws Exception {
|
||||
FileUtils.writeStringToFile(file, gson.toJson(json_object));
|
||||
}
|
||||
//Синтаксис и регулярные выражения
|
||||
//БУФЕР ОБМЕНА
|
||||
public static void CopyToClipboard(String text) {
|
||||
Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard()
|
||||
.setContents(
|
||||
new StringSelection(text),
|
||||
null
|
||||
);
|
||||
}
|
||||
public static String getFromClipboard() {
|
||||
String res = "";
|
||||
try {
|
||||
res = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
|
||||
} catch (Exception ex) {
|
||||
MainLog.PrintException(ex);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static String strikeThrough(String s) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : s.toCharArray()) {
|
||||
res.append(c);
|
||||
if (c != CommonConstants.toStrike)
|
||||
res.append(CommonConstants.toStrike);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
public static String noStrikeThrough(String s) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : s.toCharArray()) {
|
||||
if (c != (CommonConstants.toStrike))
|
||||
res.append(c);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
public static boolean validateEmail(String address, TextLog log) {
|
||||
Matcher matcher = CommonConstants.VALID_EMAIL_ADDRESS_REGEX.matcher(address);
|
||||
if (!matcher.find()) {
|
||||
log.Writeln_("введённый адрес электронной почты некорректен.");
|
||||
return false;
|
||||
}
|
||||
String match = address.substring(matcher.start(), matcher.end());
|
||||
if (!match.equals(address)) {
|
||||
log.Writeln_("введённый адрес электронной почты некорректен.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static String hideRegularMetasymbols(String word) {
|
||||
String res = word.replace("\\", "\\\\");
|
||||
for (char c : CommonConstants.regular_metasymbols)
|
||||
@@ -52,6 +114,28 @@ public class CommonUtils {
|
||||
public static String TBrackets(Object o) {
|
||||
return "<" + o.toString() + ">";
|
||||
}//FortranSPFTokenMaker
|
||||
public static boolean ContainsForbiddenName(String string) {
|
||||
char[] chars = string.toCharArray();
|
||||
for (char c : chars)
|
||||
if (isForbiddenCharacter(c)) return true;
|
||||
return false;
|
||||
}
|
||||
public static boolean isForbiddenCharacter(char c) {
|
||||
return CommonConstants.forbidden_file_name_characters.contains(c);
|
||||
}
|
||||
public static String ReplaceForbiddenCharacters(String name) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (char c : name.toCharArray())
|
||||
res.append(isForbiddenCharacter(c) ? '_' : c);
|
||||
return res.toString();
|
||||
}
|
||||
//Синтаксис и регулярные выражения
|
||||
public static String printAllForbiddenCharacters(){
|
||||
Vector<String> res = new Vector<>();
|
||||
for (char c: CommonConstants.forbidden_file_name_characters)
|
||||
res.add(String.valueOf(c));
|
||||
return String.join(" ", res);
|
||||
}
|
||||
public static boolean ContainsCyrillic(String string) {
|
||||
return string.chars()
|
||||
.mapToObj(Character.UnicodeBlock::of)
|
||||
@@ -285,6 +369,15 @@ public class CommonUtils {
|
||||
public static double getFileSizeMegaBytes(File file) {
|
||||
return ((double)file.length()) / (1024 * 1024);
|
||||
}
|
||||
public static byte[] fileToBytes(File src) throws Exception {
|
||||
byte[] dst = Files.readAllBytes(src.toPath());
|
||||
return dst;
|
||||
}
|
||||
public static void bytesToFile(byte[] bytes, File dst) throws Exception {
|
||||
FileOutputStream os = new FileOutputStream(dst);
|
||||
os.write(bytes);
|
||||
os.close();
|
||||
}
|
||||
//Иконки
|
||||
public static ImageIcon getIcon(String path) {
|
||||
URL imageUrl = CommonUtils.class.getResource(path);
|
||||
@@ -304,8 +397,11 @@ public class CommonUtils {
|
||||
18,
|
||||
Image.SCALE_DEFAULT));
|
||||
}
|
||||
//Даты
|
||||
public static String print_date(Date date) {
|
||||
return new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(date);
|
||||
}
|
||||
//-
|
||||
//ГЕНЕРАЦИЯ ИМЕН Старт задачи
|
||||
|
||||
//ГЕНЕРАЦИЯ ИМЕН
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user