no message

This commit is contained in:
2024-10-07 14:22:52 +03:00
parent 6b1576461d
commit 61fc37b574
173 changed files with 960 additions and 1526 deletions

View File

@@ -0,0 +1,7 @@
package Common;
public class CommonConstants {
public static final int Nan = -1;
public static char[] regular_metasymbols = new char[]{
'<', '>', '(', ')', '[', ']', '{', '}', '^', '-', '=', '$', '!', '|', '?', '*', '+', '.'
};
}

View File

@@ -1,8 +1,8 @@
package Common.Database;
import Common_old.Constants;
import Common.CommonConstants;
import Common.Utils.CommonUtils;
import Common.Database.Tables.DBTable;
import _VisualDVM.Global;
import Common_old.Utils.Utils;
import Common.Database.Objects.DBObject;
import Common.Database.Tables.DataSet;
import Common.Database.Objects.iDBObject;
@@ -85,7 +85,7 @@ public abstract class Database {
public DBObject InsertS(DBObject object) throws Exception {
DBTable table = tables.get(object.getClass());
if (!(object instanceof iDBObject) && table.Data.containsKey(object.getPK()))
throw new RepositoryRefuseException("Таблица " + Utils.Brackets(table.Name) + " уже содержит объект с ключом " + Utils.Brackets(object.getPK().toString()));
throw new RepositoryRefuseException("Таблица " + CommonUtils.Brackets(table.Name) + " уже содержит объект с ключом " + CommonUtils.Brackets(object.getPK().toString()));
insert(table, object);
table.Data.put(object.getPK(), object);
return object;
@@ -112,7 +112,7 @@ public abstract class Database {
table.Data.remove(o.getPK());
return o;
} else
throw new RepositoryRefuseException("Таблица " + Utils.Brackets(table.Name) + " не содержит объект с ключом " + Utils.Brackets(to_delete.getPK().toString()));
throw new RepositoryRefuseException("Таблица " + CommonUtils.Brackets(table.Name) + " не содержит объект с ключом " + CommonUtils.Brackets(to_delete.getPK().toString()));
}
public DBObject DeleteByPK(Class object_class, Object key) throws Exception {
DBTable table = tables.get(object_class);
@@ -122,7 +122,7 @@ public abstract class Database {
table.Data.remove(key);
return o;
} else
throw new RepositoryRefuseException("Таблица " + Utils.Brackets(table.Name) + " не содержит объект с ключом " + Utils.Brackets(key.toString()));
throw new RepositoryRefuseException("Таблица " + CommonUtils.Brackets(table.Name) + " не содержит объект с ключом " + CommonUtils.Brackets(key.toString()));
}
// не работает с автоинкрементом.
public DBObject getObjectCopyByPK(Class table_class, Object pk) throws Exception {
@@ -233,7 +233,7 @@ public abstract class Database {
(O) (tables.get(class_in).Data.get(pk)) : null;
}
public <O extends iDBObject> O getById(Class<O> class_in, int pk) {
return getByPK(class_in, pk, Constants.Nan);
return getByPK(class_in, pk, CommonConstants.Nan);
}
public <G, O extends DBObject, F extends DBObject> LinkedHashMap<G, F> getByFKAndGroupBy(O owner, Class<F> fk_class, String group_field, Class<G> group_class) {
LinkedHashMap<G, F> res = new LinkedHashMap<>();

View File

@@ -1,7 +1,7 @@
package Common.Database.Objects;
import Common.Utils.CommonUtils;
import Common_old.UI.Selectable;
import Common.Utils.Index;
import Common_old.Utils.Utils;
import com.sun.org.glassfish.gmbal.Description;
import java.io.Serializable;
@@ -34,7 +34,7 @@ public abstract class DBObject implements Selectable, Serializable {
}
public abstract Object getPK();
public String getBDialogName() {
return Utils.Brackets(getDialogName());
return CommonUtils.Brackets(getDialogName());
}
public String getDialogName() {
return getPK().toString();

View File

@@ -1,5 +1,5 @@
package Common.Database.Objects;
import Common_old.Constants;
import Common.CommonConstants;
import com.google.gson.annotations.Expose;
import com.sun.org.glassfish.gmbal.Description;
//автоинкрементальный ключ
@@ -13,7 +13,7 @@ public class iDBObject extends DBObject {
}
@Override
public Object getEmptyFK() {
return Constants.Nan;
return CommonConstants.Nan;
}
//---
@Override

View File

@@ -3,6 +3,7 @@ import Common.Database.Objects.DBObject;
import Common.Database.Tables.DBTable;
import Common.Database.Tables.DBTableColumn;
import Common.Database.Database;
import Common.Utils.CommonUtils;
import Common_old.UI.UI;
import Common_old.Utils.Utils;
import Visual_DVM_2021.Passes.PassException;
@@ -116,7 +117,7 @@ public abstract class SQLiteDatabase extends Database {
Vector<String> columns_names = new Vector<>();
for (DBTableColumn column : table.columns.values())
columns_names.add(column.toString());
cmd += Utils.RBrackets(String.join(",", columns_names));
cmd += CommonUtils.RBrackets(String.join(",", columns_names));
statement.execute(cmd);
}
}
@@ -135,8 +136,8 @@ public abstract class SQLiteDatabase extends Database {
}
insertStatements.put(table.d, conn.prepareStatement(
"INSERT OR REPLACE INTO " + table.QName() + " " +
Utils.RBrackets(String.join(",", column_names)) + " " + "VALUES " +
Utils.RBrackets(String.join(",", column_values))));
CommonUtils.RBrackets(String.join(",", column_names)) + " " + "VALUES " +
CommonUtils.RBrackets(String.join(",", column_values))));
//------------------------------------------------------------------------------->>
Vector<String> new_values = new Vector();
for (DBTableColumn column : table.columns.values()) {
@@ -194,7 +195,7 @@ public abstract class SQLiteDatabase extends Database {
if (field_value != null) {
table.d.getField(column.Name).set(o, field_value);
} else
throw new PassException("Ошибка при загрузке поля " + Utils.Brackets(column.Name) + " класса " + Utils.Brackets(table.d.getSimpleName()));
throw new PassException("Ошибка при загрузке поля " + CommonUtils.Brackets(column.Name) + " класса " + CommonUtils.Brackets(table.d.getSimpleName()));
}
return new Pair<>((K) o.getPK(), o);
}

View File

@@ -1,26 +1,274 @@
package Common.Utils;
import Common.CommonConstants;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.nio.charset.Charset;
public class CommonUtils {
//JSON
//--
// public static String jsonToPrettyFormat(String packed) {
// JsonParser parser = new JsonParser();
// JsonObject json = parser.parse(packed).getAsJsonObject();
// Gson gson = new GsonBuilder().setPrettyPrinting().create();
// return gson.toJson(json);
// }
//--
public static Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create();
/*
public static String jsonToPrettyFormat(String packed) {
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(packed).getAsJsonObject();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
return gson.toJson(json);
}
*/
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 String hideRegularMetasymbols(String word) {
String res = word.replace("\\", "\\\\");
for (char c : CommonConstants.regular_metasymbols)
res = res.replace(String.valueOf(c), "\\" + c);
return res;
}
public static String DQuotes(Object o) {
return "\"" + o.toString() + "\"";
}
public static String Quotes(Object o) {
return "'" + o.toString() + "'";
}
public static String Brackets(Object o) {
return "[" + o.toString() + "]";
}
public static String RBrackets(Object o) {
return "(" + o.toString() + ")";
}
public static String TBrackets(Object o) {
return "<" + o.toString() + ">";
}
public static boolean ContainsCyrillic(String string) {
return string.chars()
.mapToObj(Character.UnicodeBlock::of)
.anyMatch(b -> b.equals(Character.UnicodeBlock.CYRILLIC));
}
public static boolean isDigit(String s) {
try {
Integer.parseInt(s);
return true;
} catch (NumberFormatException e) {
return false;
}
}
public static boolean isEnglishLetter(char c) {
return (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')));
}
public static boolean isRussianLetter(char c) {
return ((c >= 'а') && (c <= 'я'))
|| ((c >= 'А') && (c <= 'Я'))
|| (c == 'Ё')
|| (c == 'ё');
}
public static boolean isSign(char c) {
switch (c) {
//арифметика.
case '+':
case '-':
case '*':
case '/':
case '<':
case '>':
case '&':
case '=':
case '%':
case '^':
//- обр слеш
case '\\':
//препинание
case ' ':
case '_':
case '.':
case ',':
case '!':
case '?':
case ';':
case ':':
//escape последовательности
case '\t':
case '\n':
case '\r':
//кавычки
case '\'':
case '"':
//- скобки
case '(':
case ')':
case '[':
case ']':
case '{':
case '}':
//прочее
case '~':
case '`':
case '|':
case '@':
case '$':
case '#':
case '№':
return true;
}
return false;
}
public static char Translit(char c) {
switch (c) {
case 'А':
case 'а':
case 'Я':
case 'я':
return 'A';
//
case 'Б':
case 'б':
return 'B';
//-
case 'В':
case 'в':
return 'V';
//
case 'Г':
case 'г':
return 'G';
//
case 'Д':
case 'д':
return 'D';
//
case 'Е':
case 'е':
case 'Ё':
case 'ё':
case 'Э':
case 'э':
return 'E';
//
case 'Ж':
case 'ж':
return 'J';
//
case 'З':
case 'з':
return 'Z';
//
case 'И':
case 'и':
case 'Й':
case 'й':
return 'I';
//
case 'К':
case 'к':
return 'K';
//
case 'Л':
case 'л':
return 'L';
//
case 'М':
case 'м':
return 'M';
//
case 'Н':
case 'н':
return 'N';
//
case 'О':
case 'о':
return 'O';
//
case 'П':
case 'п':
return 'P';
//
case 'Р':
case 'р':
return 'R';
//
case 'С':
case 'с':
return 'S';
case 'Т':
case 'т':
return 'T';
//
case 'У':
case 'у':
case 'Ю':
case 'ю':
return 'U';
case 'Х':
case 'х':
case 'Щ':
case 'щ':
case 'Ш':
case 'ш':
return 'H';
//
case 'Ф':
case 'ф':
return 'F';
//
case 'Ч':
case 'ч':
case 'Ц':
case 'ц':
return 'C';
//
case 'Ы':
case 'ы':
return 'Y';
//
}
return ' ';
}
public static String ending(boolean flag) {
return flag ? ")" : ",";
}
public static boolean isRBracketsBalanced(String fragment) {
int cc = 0;
for (char c : fragment.toCharArray()) {
if (c == '(')
cc++;
if (c == ')')
cc--;
if (cc < 0)
return false;
}
return (cc == 0);
}
//ФАЙЛЫ
public static String getExtension(File file) {
String fn = file.getName();
int di = fn.lastIndexOf(".");
return (di >= 0) ? fn.substring(di + 1).toLowerCase() : "";
}
public static String getExtensionFromName(String fn) {
int di = fn.lastIndexOf(".");
return (di >= 0) ? fn.substring(di + 1).toLowerCase() : "";
}
public static String getFileNameWithoutExtension(File file) {
return getNameWithoutExtension(file.getName());
}
public static String getNameWithoutExtension(String fn) {
return (fn.contains(".")) ? fn.substring(0, fn.lastIndexOf(".")).toLowerCase() : fn.toLowerCase();
}
public static String toU(String path) {
return path.replace('\\', '/');
}
public static String toW(String path) {
return path.replace('/', '\\');
}
public static double getFileSizeMegaBytes(File file) {
return ((double)file.length()) / (1024 * 1024);
}
//-
//ГЕНЕРАЦИЯ ИМЕН
}

View File

@@ -1,4 +1,5 @@
package Common.Visual;
import Common.Utils.CommonUtils;
import Common_old.UI.Menus_2023.StableMenuItem;
import Common_old.Utils.Utils;
import Common.Database.Objects.DBObject;
@@ -53,7 +54,7 @@ public abstract class DBObjectFilter<D extends DBObject> {
count = 0;
}
public void Refresh() {
menuItem.setText(description + " " + Utils.RBrackets(count));
menuItem.setText(description + " " + CommonUtils.RBrackets(count));
}
public boolean isActive() {
return active;

View File

@@ -14,14 +14,14 @@ public abstract class DataSetFilter<D extends DBObject> {
protected Vector<DBObjectFilter<D>> field_filters;
public DataSetFilter(String name, DataSet dataSet_in) {
dataSet = dataSet_in;
menu = new VisualiserMenu(name, "/icons/Filter.png", true);
menu = new VisualiserMenu(name, "/Common/icons/Filter.png", true);
field_filters = new Vector<>();
fill();
//-
for (DBObjectFilter<D> filter : field_filters)
menu.add(filter.menuItem);
menu.addSeparator();
menu.add(new StableMenuItem("Выбрать всё", "/icons/SelectAll.png") {
menu.add(new StableMenuItem("Выбрать всё", "/Common/icons/SelectAll.png") {
{
addActionListener(new ActionListener() {
@Override
@@ -32,7 +32,7 @@ public abstract class DataSetFilter<D extends DBObject> {
});
}
});
menu.add(new StableMenuItem("Отменить всё", "/icons/UnselectAll.png") {
menu.add(new StableMenuItem("Отменить всё", "/Common/icons/UnselectAll.png") {
{
addActionListener(new ActionListener() {
@Override

BIN
src/Common/icons/Filter.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B