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