DELL
2024-08-06 b9f963aba187310ac39ba84e8ef46e38aaaed80c
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
package com;
 
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;
 
import javax.swing.JComboBox;
import javax.swing.JTextField;
 
 
public class Com {
    final public static int UploadData_ClientType_BS_CLI = 0;
    final public static int UploadData_ClientType_CS_CLI = 1;
    final public static int UploadData_ClientType_CS_SVR = 2;
    
    public static final int EDIT_VIEW = 0;
    public static final int EDIT_ADD = 1;
    public static final int EDIT_MODIFY = 2;
    
    public static final int CNT_MAX    = 99999999;
    
    public static final String DTF_YMDhms_S = "yyyy-MM-dd HH:mm:ss.SSS";
    public static final String DTF_YMDhms = "yyyy-MM-dd HH:mm:ss";
    public static final String DTF_YMDhm = "yyyy-MM-dd HH:mm";
    public static final String DTF_YMDh = "yyyy-MM-dd HH";
    public static final String DTF_YMD = "yyyy-MM-dd";
    public static final String DTF_hms = "HH:mm:ss";
    public static final long DT_OFFSET = 3600*8*1000;
    
    public static final String[] YesNoText = new String[] {
        "·ñ",
        "ÊÇ",
    };
    //final public static DateFormat DateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
    
    /**
     * ½«´«ÈëµÄʱ¼äת»»³ÉÖ¸¶¨µÄµÄʱ¼ä¸ñʽ²¢·µ»ØÊ±¼ä¸ñʽ»¯Ö®ºóµÄ×Ö·û´®
     * @param dt        ÐèҪת»»µÄʱ¼ä
     * @param format    ¸ñʽ»¯×Ö·û´®
     * @return
     */
    public static String getDateTimeFormat(Date dt, String format){
        DateFormat dtf = new SimpleDateFormat(format);
        return dtf.format(dt);
    }
    
    /**
     * ½«´«ÈëµÄ×Ö·û´®°´Ö¸¶¨µÄ¸ñʽ½âÎö³Éʱ¼äÀàÐͲ¢·µ»Ø
     * @param dt       ÐèÒª½âÎöµÄ×Ö·û´®
     * @param format   Ö¸¶¨µÄʱ¼ä¸ñʽ
     * @return
     */
    public static Date getDateTimeFromStr(String dt, String format){
        DateFormat dtf = new SimpleDateFormat(format);
        Date date = new Date();
        try {
            date = dtf.parse(dt);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        
        return date;
    }
    
    public static String getNowTimeWithAt() {
        return " @ " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms);
    }
    
    
    public static String get_DTF(Date dt, String format){
        DateFormat dtf = new SimpleDateFormat(format);
        return dtf.format(dt);
    }
    
    public static Date get_DT_FromStr(String dt, String format){
        DateFormat dtf = new SimpleDateFormat(format);
        Date date = new Date();
        try {
            date = dtf.parse(dt);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        
        return date;
    }
    
    /**
     * ÅжÏnumber²ÎÊýÊÇ·ñÊÇÕûÐÍÊý±íʾ·½Ê½
     * @param number
     * @return
     */
    public static boolean isIntegerNumber(String number){
        number = number.trim();
        String intNumRegex = "\\-{0,1}\\d+";    //ÕûÊýµÄÕýÔò±í´ïʽ
        if(number.matches(intNumRegex))
            return true;
        else
            return false;
    }
      
    /**
     * ÅжÏnumber²ÎÊýÊÇ·ñÊǸ¡µãÊý±íʾ·½Ê½
     * @param numbe
     * @return
     */
    public static boolean isFloatPointNumber(String number){
        number = number.trim();
        String intNumRegex = "\\-{0,1}\\d+";                //ÕûÊýµÄÕýÔò±í´ïʽ
        String pointPrefix = "(\\-|\\+){0,1}\\d*\\.\\d+";    //¸¡µãÊýµÄÕýÔò±í´ïʽ-СÊýµãÔÚÖмäÓëÇ°Ãæ
        String pointSuffix = "(\\-|\\+){0,1}\\d+\\.";        //¸¡µãÊýµÄÕýÔò±í´ïʽ-СÊýµãÔÚºóÃæ
        if(number.matches(intNumRegex) || number.matches(pointPrefix) || number.matches(pointSuffix))
            return true;
        else
            return false;
    }
    
    /**
     * ÅжÏnumber²ÎÊýÊÇ·ñÊÇÈÕÆÚ±íʾ·½Ê½
     * @param str
     * @return
     */
    public static boolean isValidDate(String str, String format) {
        boolean convertSuccess = true;
        try {
            //DateTimeFormat.setLenient(false);
            DateFormat dtf = new SimpleDateFormat(format);
            dtf.parse(str);
         } catch (ParseException e) {
             convertSuccess = false;
         }
         return convertSuccess;
    }
    
    /**
     * 
     * @param 
     * @return
     */
    public static float[] sortData(float[] data, int len) {
        float[] sort_data = new float[len];
        for(int n=0; n<sort_data.length; n++)
            sort_data[n] = data[n];
        
        float tmp;
        for(int n=0; n<sort_data.length; n++)
        {
            tmp = sort_data[n];
            for(int m=n; m<sort_data.length; m++)
            {
                if(sort_data[n] > sort_data[m])
                {
                    sort_data[n] = sort_data[m];
                    sort_data[m] = tmp;
                    tmp = sort_data[n];
                }
            }
        }
        
        return sort_data;
    }
    
    /**
     * 
     * @param 
     * @return
     */
    public static float getAvrageData(float[] data, int len) {
        float sum_data = 0;
        for(int n=0; n<len; n++)
            sum_data += data[n];
        
        return (sum_data/len);
    }
    
    /**
     * 
     * @param 
     * @return
     */
    /*
    public static short CalCRC16(byte[] Pushdata, int length)
    {
        int Reg_CRC = 0xFFFF;
        for(int i = 0; i<length; i ++)
        {
            Reg_CRC ^= Pushdata[i];
            for (int j = 0; j<8; j++)
            {
                if((Reg_CRC & 0x0001) > 0)
                    Reg_CRC = (Reg_CRC>>1) ^ 0xA001;
                else
                    Reg_CRC >>= 1;
            }
        }
        return (short)(Reg_CRC&0xFFFF);
    }
    */
    /**
     * 
     * @param 
     * @return
     */
    static public String getLoacalHostIp()
    {
        Enumeration<?> allNetInterfaces = null;  
        try {  
            allNetInterfaces = NetworkInterface.getNetworkInterfaces();  
        } catch (java.net.SocketException e) {  
            e.printStackTrace();  
        }
        
        while (allNetInterfaces.hasMoreElements())  
        {  
            NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();  
            System.out.println(netInterface.getName());
            
            Enumeration<?> addresses = netInterface.getInetAddresses();  
            while (addresses.hasMoreElements())
            {
                InetAddress ip = (InetAddress) addresses.nextElement();  
                if (ip != null && ip instanceof Inet4Address)  
                {  
                    System.out.println(netInterface.getName() + ": " + ip.getHostAddress()); 
                    if(netInterface.getName().contains("wlan0"))
                    {
                        return ip.getHostAddress();
                    }
                }
            }
        }
        
        return "127.0.0.1";
    }
    /**
     * 
     * @param 
     * @return
     */
    public static boolean getIPFromStr(String ipstr, byte ip[])
    {
        boolean res = false;
        try {
            for(int n=0; n<3; n++) {
                int index = ipstr.indexOf('.');
                if(index > 0)
                    ip[n] = (byte)Integer.parseInt(ipstr.substring(0, index));
                
                ipstr = ipstr.substring(index+1);
            }
            ip[3] = (byte)Integer.parseInt(ipstr);
            
            res = true;
        } catch(Exception e) {
            System.out.println(e.getMessage());
        }
        
        return res;
    }
    /**
     * 
     * @param 
     * @return
     */
    public static Object getComboBoxItemText(JComboBox<Object> cb, int it_index)
    {
        Object obj = "";
        if(it_index < cb.getItemCount())
            obj = cb.getItemAt(it_index);
        
        return obj;
    }
    /**
     * 
     * @param 
     * @return
     */
    public static int getComboBoxItemIndex(JComboBox<String> cb_sex, String it_obj)
    {
        int it_index = -1;
        for(int n=0; n<cb_sex.getItemCount(); n++)
        {
            if(cb_sex.getItemAt(n).equals(it_obj))
            {
                it_index = n;
                break;
            }
        }
        
        return it_index;
    }
    
    public static int getComboBoxItemIndex(String[] cb, String it_obj)
    {
        int it_index = -1;
        for(int n=0; n<cb.length; n++)
        {
            if(cb[n].equals(it_obj))
            {
                it_index = n;
                break;
            }
        }
        
        return it_index;
    }
    
    public static String getAppPath() {
        String app_path = System.getProperty("user.dir");
        return app_path;
    }
    
    public static void copyTableRowData(Vector<Vector<Object>> src_vvo, Vector<Vector<Object>> target_vvo)
    {
        if((null != src_vvo) && (null != target_vvo)) {
            if(target_vvo.size() < src_vvo.size()) {
                for(int n=0; n<src_vvo.size(); n++) {
                    if(n < target_vvo.size()) {
                        target_vvo.setElementAt(src_vvo.get(n), n);
                    } else {
                        target_vvo.add(src_vvo.get(n));
                    }
                }
            } else {
                for(int n=(target_vvo.size()-1); n>=0; n--) {
                    if(n >= src_vvo.size()) {
                        target_vvo.removeElementAt(n);
                    } else {
                        target_vvo.setElementAt(src_vvo.get(n), n);
                    }
                }
            }
        }
    }
    
    public static int getPid() {
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        String name = runtime.getName(); // format: "pid@hostname"
        try {
            return Integer.parseInt(name.substring(0, name.indexOf('@')));
        } catch (Exception e) {
            return -1;
        }
    }
    
    public static void setTFDocLimit(JTextField tf, int charlen, String str) {
        tf.setDocument(new LimitedDocument(charlen, str));
    }
    
    /**
     * ½«Ê±¼äת»¯³ÉH:M:S
     * @param min
     * @return
     */
    public static String minConvertHourMinSecond(Integer min) {
        String result = "";
        if (min != null) {
            Integer m = min;
            String format;
            Object[] array;
            Integer days = m / (60 * 24);
            Integer hours = m / (60) - days * 24;
            Integer minutes;
            Integer second;
            if (days > 0) {
                hours += days * 24;
                minutes = m - hours * 60;
                second = ( m - minutes - hours * 60) / 60;
            }else{
                minutes = m - hours * 60 - days * 24 * 60;
                second = (m - minutes - hours * 60) / 60;
            }
            String hoursstr = null;
            String minutesstr  = null;
            String secondstr = null;
            if(hours < 10){
                hoursstr = "0"+hours;
            }else {
                hoursstr = hours + "";
            }
            if(minutes < 10){
                minutesstr="0"+minutes;
            }else {
                minutesstr = minutes + "";
            }
            if(second < 10){
                secondstr="0"+second;
            }else {
                secondstr = second + "";
            }
            format = "%1$s:%2$s:%3$s";
            array = new Object[]{hoursstr, minutesstr,secondstr};
            result = String.format(format, array);
        }
        return result;
    }
    
    public static void main(String[] args) {
        System.out.println(minConvertHourMinSecond(61));
    }
}