Rev 242 | 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 | |||
252 | ligi | 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 | |||
19 | |||
223 | ligi | 20 | public final static String ip_str(int[] ip,boolean with_zeroes) |
206 | ligi | 21 | { |
22 | if(with_zeroes) |
||
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]) ; |
||
24 | else |
||
25 | return ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]+":"+ip[4]; |
||
26 | |||
27 | } |
||
28 | |||
223 | ligi | 29 | public final static int pow(int val,int pow) |
206 | ligi | 30 | { |
31 | int res=1; |
||
32 | |||
33 | for (int p=0;p<pow;p++) |
||
34 | res*=val; |
||
35 | |||
36 | return res; |
||
37 | } |
||
38 | |||
39 | |||
242 | ligi | 40 | public final static String[] split_str(String str,String sep) |
41 | { |
||
42 | |||
43 | Vector nodes = new Vector(); |
||
44 | |||
45 | // Parse nodes into vector |
||
46 | int index = str.indexOf(sep); |
||
47 | while(index>=0) { |
||
48 | nodes.addElement( str.substring(0, index) ); |
||
49 | str = str.substring(index+sep.length()); |
||
50 | index = str.indexOf(sep); |
||
51 | } |
||
52 | // add last element |
||
53 | nodes.addElement( str ); |
||
54 | |||
55 | // Create splitted string array |
||
56 | String[] result = new String[ nodes.size() ]; |
||
57 | if( nodes.size()>0 ) { |
||
58 | for(int loop=0; loop<nodes.size(); loop++) |
||
59 | { |
||
60 | result[loop] = (String)nodes.elementAt(loop); |
||
61 | System.out.println(result[loop]); |
||
62 | } |
||
63 | |||
64 | } |
||
65 | |||
66 | return result; |
||
67 | } |
||
68 | |||
69 | |||
70 | |||
223 | ligi | 71 | public final static int mod_decimal(int val,int mod_power,int modder,int setter,int clipper) |
206 | ligi | 72 | { |
73 | |||
74 | int res=0; |
||
75 | |||
76 | for (int power=0;power<4;power++) |
||
77 | { |
||
78 | |||
79 | int act_digit=(val/pow(10,power))%10; |
||
80 | |||
81 | int new_digit=act_digit; |
||
82 | if (power==mod_power) |
||
83 | { |
||
84 | if (setter!=-1) |
||
85 | new_digit=setter; |
||
86 | |||
87 | new_digit+=modder; |
||
88 | |||
89 | if(new_digit<0) |
||
90 | new_digit=0; |
||
91 | |||
92 | if(new_digit>clipper) |
||
93 | new_digit=clipper; |
||
94 | |||
95 | } |
||
96 | |||
97 | // new_digit=1; |
||
98 | res+=new_digit*pow(10,power); |
||
99 | } |
||
100 | |||
101 | |||
102 | return res; |
||
103 | |||
104 | |||
105 | } |
||
106 | |||
107 | } |