Rev 242 | Rev 255 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 242 | Rev 252 | ||
---|---|---|---|
1 | import java.util.Vector; |
1 | import java.util.Vector; |
2 | 2 | ||
3 | public final class DUBwiseHelper |
3 | public final class DUBwiseHelper |
4 | { |
4 | { |
5 | public final static String ip_digit_zeroes(int digit) |
5 | public final static String ip_digit_zeroes(int digit) |
6 | { return "" + digit/100 + "" + (digit/10)%10 + "" + (digit)%10; } |
6 | { return "" + digit/100 + "" + (digit/10)%10 + "" + (digit)%10; } |
7 | 7 | ||
- | 8 | ||
- | 9 | public final static String pound_progress(int val,int max) |
|
- | 10 | { |
|
- | 11 | String res="" + (val+1) + "/" + max + " |"; |
|
- | 12 | for (int i=0;i<max;i++) |
|
- | 13 | res+=(i<(val+1))?"#":"_"; |
|
- | 14 | res+="|"; |
|
- | 15 | return res; |
|
- | 16 | } |
|
- | 17 | ||
- | 18 | ||
8 | 19 | ||
9 | public final static String ip_str(int[] ip,boolean with_zeroes) |
20 | public final static String ip_str(int[] ip,boolean with_zeroes) |
10 | { |
21 | { |
11 | if(with_zeroes) |
22 | if(with_zeroes) |
12 | return ip_digit_zeroes(ip[0]) + "." +ip_digit_zeroes(ip[1]) + "."+ip_digit_zeroes(ip[2]) + "."+ip_digit_zeroes(ip[3]) + ":"+ip_digit_zeroes(ip[4]) ; |
23 | return ip_digit_zeroes(ip[0]) + "." +ip_digit_zeroes(ip[1]) + "."+ip_digit_zeroes(ip[2]) + "."+ip_digit_zeroes(ip[3]) + ":"+ip_digit_zeroes(ip[4]) ; |
13 | else |
24 | else |
14 | return ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]+":"+ip[4]; |
25 | return ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]+":"+ip[4]; |
15 | 26 | ||
16 | } |
27 | } |
17 | 28 | ||
18 | public final static int pow(int val,int pow) |
29 | public final static int pow(int val,int pow) |
19 | { |
30 | { |
20 | int res=1; |
31 | int res=1; |
21 | 32 | ||
22 | for (int p=0;p<pow;p++) |
33 | for (int p=0;p<pow;p++) |
23 | res*=val; |
34 | res*=val; |
24 | 35 | ||
25 | return res; |
36 | return res; |
26 | } |
37 | } |
27 | 38 | ||
28 | 39 | ||
29 | public final static String[] split_str(String str,String sep) |
40 | public final static String[] split_str(String str,String sep) |
30 | { |
41 | { |
31 | 42 | ||
32 | Vector nodes = new Vector(); |
43 | Vector nodes = new Vector(); |
33 | 44 | ||
34 | // Parse nodes into vector |
45 | // Parse nodes into vector |
35 | int index = str.indexOf(sep); |
46 | int index = str.indexOf(sep); |
36 | while(index>=0) { |
47 | while(index>=0) { |
37 | nodes.addElement( str.substring(0, index) ); |
48 | nodes.addElement( str.substring(0, index) ); |
38 | str = str.substring(index+sep.length()); |
49 | str = str.substring(index+sep.length()); |
39 | index = str.indexOf(sep); |
50 | index = str.indexOf(sep); |
40 | } |
51 | } |
41 | // add last element |
52 | // add last element |
42 | nodes.addElement( str ); |
53 | nodes.addElement( str ); |
43 | 54 | ||
44 | // Create splitted string array |
55 | // Create splitted string array |
45 | String[] result = new String[ nodes.size() ]; |
56 | String[] result = new String[ nodes.size() ]; |
46 | if( nodes.size()>0 ) { |
57 | if( nodes.size()>0 ) { |
47 | for(int loop=0; loop<nodes.size(); loop++) |
58 | for(int loop=0; loop<nodes.size(); loop++) |
48 | { |
59 | { |
49 | result[loop] = (String)nodes.elementAt(loop); |
60 | result[loop] = (String)nodes.elementAt(loop); |
50 | System.out.println(result[loop]); |
61 | System.out.println(result[loop]); |
51 | } |
62 | } |
52 | 63 | ||
53 | } |
64 | } |
54 | 65 | ||
55 | return result; |
66 | return result; |
56 | } |
67 | } |
57 | 68 | ||
58 | 69 | ||
59 | 70 | ||
60 | public final static int mod_decimal(int val,int mod_power,int modder,int setter,int clipper) |
71 | public final static int mod_decimal(int val,int mod_power,int modder,int setter,int clipper) |
61 | { |
72 | { |
62 | 73 | ||
63 | int res=0; |
74 | int res=0; |
64 | 75 | ||
65 | for (int power=0;power<4;power++) |
76 | for (int power=0;power<4;power++) |
66 | { |
77 | { |
67 | 78 | ||
68 | int act_digit=(val/pow(10,power))%10; |
79 | int act_digit=(val/pow(10,power))%10; |
69 | 80 | ||
70 | int new_digit=act_digit; |
81 | int new_digit=act_digit; |
71 | if (power==mod_power) |
82 | if (power==mod_power) |
72 | { |
83 | { |
73 | if (setter!=-1) |
84 | if (setter!=-1) |
74 | new_digit=setter; |
85 | new_digit=setter; |
75 | 86 | ||
76 | new_digit+=modder; |
87 | new_digit+=modder; |
77 | 88 | ||
78 | if(new_digit<0) |
89 | if(new_digit<0) |
79 | new_digit=0; |
90 | new_digit=0; |
80 | 91 | ||
81 | if(new_digit>clipper) |
92 | if(new_digit>clipper) |
82 | new_digit=clipper; |
93 | new_digit=clipper; |
83 | 94 | ||
84 | } |
95 | } |
85 | 96 | ||
86 | // new_digit=1; |
97 | // new_digit=1; |
87 | res+=new_digit*pow(10,power); |
98 | res+=new_digit*pow(10,power); |
88 | } |
99 | } |
89 | 100 | ||
90 | 101 | ||
91 | return res; |
102 | return res; |
92 | 103 | ||
93 | 104 | ||
94 | } |
105 | } |
95 | 106 | ||
96 | } |
107 | } |
97 | 108 |