Rev 206 | Rev 242 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 206 | Rev 223 | ||
---|---|---|---|
1 | public class DUBwiseHelper |
1 | public final class DUBwiseHelper |
2 | { |
2 | { |
3 | public String ip_digit_zeroes(int digit) |
3 | public final static String ip_digit_zeroes(int digit) |
4 | { return "" + digit/100 + "" + (digit/10)%10 + "" + (digit)%10; } |
4 | { return "" + digit/100 + "" + (digit/10)%10 + "" + (digit)%10; } |
5 | 5 | ||
6 | 6 | ||
7 | public String ip_str(int[] ip,boolean with_zeroes) |
7 | public final static String ip_str(int[] ip,boolean with_zeroes) |
8 | { |
8 | { |
9 | if(with_zeroes) |
9 | 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]) ; |
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]) ; |
11 | else |
11 | else |
12 | return ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]+":"+ip[4]; |
12 | return ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]+":"+ip[4]; |
13 | 13 | ||
14 | } |
14 | } |
15 | 15 | ||
16 | public int pow(int val,int pow) |
16 | public final static int pow(int val,int pow) |
17 | { |
17 | { |
18 | int res=1; |
18 | int res=1; |
19 | 19 | ||
20 | for (int p=0;p<pow;p++) |
20 | for (int p=0;p<pow;p++) |
21 | res*=val; |
21 | res*=val; |
22 | 22 | ||
23 | return res; |
23 | return res; |
24 | } |
24 | } |
25 | 25 | ||
26 | 26 | ||
27 | public int mod_decimal(int val,int mod_power,int modder,int setter,int clipper) |
27 | public final static int mod_decimal(int val,int mod_power,int modder,int setter,int clipper) |
28 | { |
28 | { |
29 | 29 | ||
30 | int res=0; |
30 | int res=0; |
31 | 31 | ||
32 | for (int power=0;power<4;power++) |
32 | for (int power=0;power<4;power++) |
33 | { |
33 | { |
34 | 34 | ||
35 | int act_digit=(val/pow(10,power))%10; |
35 | int act_digit=(val/pow(10,power))%10; |
36 | 36 | ||
37 | int new_digit=act_digit; |
37 | int new_digit=act_digit; |
38 | if (power==mod_power) |
38 | if (power==mod_power) |
39 | { |
39 | { |
40 | if (setter!=-1) |
40 | if (setter!=-1) |
41 | new_digit=setter; |
41 | new_digit=setter; |
42 | 42 | ||
43 | new_digit+=modder; |
43 | new_digit+=modder; |
44 | 44 | ||
45 | if(new_digit<0) |
45 | if(new_digit<0) |
46 | new_digit=0; |
46 | new_digit=0; |
47 | 47 | ||
48 | if(new_digit>clipper) |
48 | if(new_digit>clipper) |
49 | new_digit=clipper; |
49 | new_digit=clipper; |
50 | 50 | ||
51 | } |
51 | } |
52 | 52 | ||
53 | // new_digit=1; |
53 | // new_digit=1; |
54 | res+=new_digit*pow(10,power); |
54 | res+=new_digit*pow(10,power); |
55 | } |
55 | } |
56 | 56 | ||
57 | 57 | ||
58 | return res; |
58 | return res; |
59 | 59 | ||
60 | 60 | ||
61 | } |
61 | } |
62 | 62 | ||
63 | } |
63 | } |
64 | 64 |