no message
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
package Common;
|
||||
import Common.Utils.Vector_;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Pattern;
|
||||
public class CommonConstants {
|
||||
public static final int Nan = -1;
|
||||
public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
|
||||
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
|
||||
public static char[] regular_metasymbols = new char[]{
|
||||
'<', '>', '(', ')', '[', ']', '{', '}', '^', '-', '=', '$', '!', '|', '?', '*', '+', '.'
|
||||
};
|
||||
public static char toStrike = (char) 822;
|
||||
public static char boop = (char) 7;
|
||||
public static Vector<Character> forbidden_file_name_characters = new Vector_<>(
|
||||
'#', '%', '&', '{', '}',
|
||||
'<', '>', '*', '?', '!',
|
||||
'$', '\'', '\"', '@', '+',
|
||||
'`', '|', '=', '#', ':', '/', '\\',
|
||||
'~', '^'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package Common.Database;
|
||||
import Common.CommonConstants;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Database.Tables.DBTable;
|
||||
import _VisualDVM.Global;
|
||||
import Common.Database.Objects.DBObject;
|
||||
import Common.Database.Tables.DataSet;
|
||||
import Common.Database.Objects.iDBObject;
|
||||
@@ -179,7 +178,7 @@ public abstract class Database {
|
||||
if (fk_class.getField(owner.getFKName()).get(o).equals(owner.getPK())) res.add((DBObject) o);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Global.Log.PrintException(e);
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -208,7 +207,7 @@ public abstract class Database {
|
||||
if (fk_class.getField(owner.getFKName()).get(f).equals(owner.getPK())) res.put((K) f.getPK(), f);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Global.Log.PrintException(e);
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -223,7 +222,7 @@ public abstract class Database {
|
||||
if (fk_class.getField(owner.getFKName()).get(o).equals(owner.getPK())) res.add(o.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Global.Log.PrintException(e);
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -244,7 +243,7 @@ public abstract class Database {
|
||||
res.put((G) (fk_class.getField(group_field).get(f)), f);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Global.Log.PrintException(e);
|
||||
CommonUtils.MainLog.PrintException(e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
//-
|
||||
//ГЕНЕРАЦИЯ ИМЕН Старт задачи
|
||||
|
||||
//ГЕНЕРАЦИЯ ИМЕН
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
package Common.Utils;
|
||||
import _VisualDVM.Global;
|
||||
public class TextLog {
|
||||
public String text = "";
|
||||
public void Writeln(String line) {
|
||||
@@ -7,7 +6,7 @@ public class TextLog {
|
||||
}
|
||||
public void Writeln_(String line) {
|
||||
text += line + "\n";
|
||||
Global.Log.Print(line);
|
||||
CommonUtils.MainLog.Print(line);
|
||||
}
|
||||
public void Clear() {
|
||||
text = "";
|
||||
|
||||
Reference in New Issue
Block a user