Rev 223 | Rev 255 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
242 | ligi | 1 | import java.util.Vector; |
2 | |||
223 | ligi | 3 | public final class DUBwiseHelper |
206 | ligi | 4 | { |
223 | ligi | 5 | public final static String ip_digit_zeroes(int digit) |
206 | ligi | 6 | { return "" + digit/100 + "" + (digit/10)%10 + "" + (digit)%10; } |
7 | |||
8 | |||
223 | ligi | 9 | public final static String ip_str(int[] ip,boolean with_zeroes) |
206 | ligi | 10 | { |
11 | 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]) ; |
||
13 | else |
||
14 | return ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]+":"+ip[4]; |
||
15 | |||
16 | } |
||
17 | |||
223 | ligi | 18 | public final static int pow(int val,int pow) |
206 | ligi | 19 | { |
20 | int res=1; |
||
21 | |||
22 | for (int p=0;p<pow;p++) |
||
23 | res*=val; |
||
24 | |||
25 | return res; |
||
26 | } |
||
27 | |||
28 | |||
242 | ligi | 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 | |||
58 | |||
59 | |||
223 | ligi | 60 | public final static int mod_decimal(int val,int mod_power,int modder,int setter,int clipper) |
206 | ligi | 61 | { |
62 | |||
63 | int res=0; |
||
64 | |||
65 | for (int power=0;power<4;power++) |
||
66 | { |
||
67 | |||
68 | int act_digit=(val/pow(10,power))%10; |
||
69 | |||
70 | int new_digit=act_digit; |
||
71 | if (power==mod_power) |
||
72 | { |
||
73 | if (setter!=-1) |
||
74 | new_digit=setter; |
||
75 | |||
76 | new_digit+=modder; |
||
77 | |||
78 | if(new_digit<0) |
||
79 | new_digit=0; |
||
80 | |||
81 | if(new_digit>clipper) |
||
82 | new_digit=clipper; |
||
83 | |||
84 | } |
||
85 | |||
86 | // new_digit=1; |
||
87 | res+=new_digit*pow(10,power); |
||
88 | } |
||
89 | |||
90 | |||
91 | return res; |
||
92 | |||
93 | |||
94 | } |
||
95 | |||
96 | } |