Util.java
2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package org.emercit.model;
import java.util.Random;
import java.io.*;
import org.emercit.szsterminal.*;
import java.util.regex.*;
public class Util {
public static void StopSiren() {
try {
SZSTerminal.siren.sirenOff();
} catch (Exception e) {
}
}
public static void RunSiren() {
try {
SZSTerminal.siren.sirenOn();
} catch (Exception e) {
}
}
public static final void Alarm() {
try {
AePlayWave player = new AePlayWave("/Alarm.wav");
player.start();
} catch (Exception e) {
}
}
public static final String reverse(String str) {
if (str.length() <= 1)
return str;
String result = "";
result += str.charAt(str.length() - 1)
+ reverse(str.substring(0, str.length() - 1));
return result;
}
public static boolean[] toBinary(int number, int base) {
final boolean[] ret = new boolean[base];
for (int i = 0; i < base; i++) {
ret[base - 1 - i] = (1 << i & number) != 0;
}
return ret;
}
public static double round(double value, int places) {
if (places < 0)
throw new IllegalArgumentException();
long factor = (long) Math.pow(10, places);
value = value * factor;
long tmp = Math.round(value);
return (double) tmp / factor;
}
public static int randInt(int min, int max) {
Random rand = new Random();
int randomNum = rand.nextInt((max - min) + 1) + min;
return randomNum;
}
public static String DoubleToString(double d) {
String result = String.valueOf(d);
String buff = "";
int i = 0;
while (result.charAt(i) != '.') {
buff += result.charAt(i);
i++;
}
buff += result.charAt(i); // '.'
buff += result.charAt(i + 1); // 1 число после точки
return buff;
}
// представление дробной части
public static final int Drob(String str) {
double j = 0;
str = reverse(str);
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '1') {
j = j + Math.pow(2, str.length() - 1 - i);
}
}
return (int) j;
}
public static final byte[] stringToBytesASCII(char[] buffer) {
byte[] b = new byte[buffer.length];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) buffer[i];
}
return b;
}
private static String ParserID(String input) {
String pattern = "id=[0-9]*";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(input);
if (m.find()) {
String buff = m.group(0);
if (buff.length() >= 12) {
char[] str = buff.toCharArray();
String res = "";
for (int i = 3; i < buff.length(); i++)
res += str[i];
return res;
}
}
return "";
}
}