no message

This commit is contained in:
2024-10-07 22:22:51 +03:00
parent 17c0bf7eb3
commit 3516b58127
34 changed files with 115 additions and 202 deletions

View File

@@ -1,5 +1,4 @@
package Common_old.Utils;
import Common.CommonConstants;
import Common.Utils.CommonUtils;
import Common.Utils.Index;
import Common.Utils.StringTemplate;
@@ -28,7 +27,6 @@ import java.nio.file.*;
import java.security.MessageDigest;
import java.util.List;
import java.util.*;
import java.util.concurrent.Semaphore;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
@@ -70,9 +68,6 @@ public class Utils {
}
}
}
public static Object requireNonNullElse(Object value, Object default_value) {
return (value != null) ? value : default_value;
}
public static String ReadAllText(File file) {
try {
return new String(Files.readAllBytes(file.toPath()));
@@ -95,33 +90,6 @@ public class Utils {
}
}
}
public static long last_ticks = CommonConstants.Nan;
public static void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (Exception ignore) {
}
}
public static Semaphore date_semaphore = new Semaphore(1);
public static long getDateNumber() {
//-
try {
date_semaphore.acquire();
} catch (Exception ignore) {
}
//-
long ticks = new Date().toInstant().getEpochSecond();
while (ticks == last_ticks) {
sleep(1);
ticks = new Date().toInstant().getEpochSecond();
}
last_ticks = ticks; // Это и есть разделяемый ресурс.
date_semaphore.release();
return ticks;
}
public static String getDateName(String name_) {
return name_ + "_" + getDateNumber();
}
public static void WriteToFile(File f, String text) throws IOException {
Files.write(
f.toPath(),
@@ -145,7 +113,7 @@ public class Utils {
public static File CreateTempResourceFile(String res_name) throws Exception {
URL u = (Utils.class.getResource("/files/" + res_name));
InputStream i = u.openStream();
Path p = Paths.get(Global.TempDirectory.getAbsolutePath(), getDateName(res_name));
Path p = Paths.get(Global.TempDirectory.getAbsolutePath(), CommonUtils.getDateName(res_name));
Files.copy(i, p, StandardCopyOption.REPLACE_EXISTING);
return p.toFile();
}
@@ -166,7 +134,7 @@ public class Utils {
return res;
}
public static File getTempFileName(String name, String ext) {
return Paths.get(System.getProperty("user.dir"), "Temp", getDateName(name) + (ext.isEmpty() ? "" : ("." + ext))).toFile();
return Paths.get(System.getProperty("user.dir"), "Temp", CommonUtils.getDateName(name) + (ext.isEmpty() ? "" : ("." + ext))).toFile();
}
public static File getTempFileName(String name) {
return getTempFileName(name, "");
@@ -625,11 +593,6 @@ public class Utils {
}
return false;
}
//временно.
public static int getTestingMaxKernels() {
return 64; // (Current.getAccount().isAdmin()) ? 64 : 14;
}
//--
public static boolean isCrushedLine(String line) {
String l_line = line.toLowerCase();
for (String crushed : Constants.crushed_cases)
@@ -714,20 +677,10 @@ public class Utils {
public static boolean isVersion(File directory) throws Exception {
return new File(directory, Constants.data).exists();
}
public static String printSplittedDateInterval(long milliseconds) {
//--
long seconds = milliseconds / 1000;
long hours = seconds / 3600;
seconds = seconds - hours * 3600;
long minutes = (seconds) / 60;
seconds = seconds - minutes * 60;
//--
return hours + " часов, " + minutes + " минут, " + seconds + " секунд";
}
public static boolean checkFileCreation(File file) {
for (int i = 1; i <= 10; ++i) {
if (file.exists()) return true;
else sleep(1000);
else CommonUtils.sleep(1000);
}
return false;
}
@@ -887,17 +840,6 @@ public class Utils {
System.out.println(new Date(dates.lastElement()));
return dates.firstElement();
}
public static Vector<String> unpack_s(String packed, String separator) {
Vector<String> ids = new Vector<>();
String[] data = packed.split(separator);
if (data.length > 0) {
for (String s : data) {
if (!s.isEmpty())
ids.add(s);
}
}
return ids;
}
public static void addDefaultMails(Vector<String> mails) {
if (!mails.contains(Constants.MailAddress))
mails.add(Constants.MailAddress);