Repository navigation
Expand file tree
/
Copy pathExtensionJ.java
More file actions
50 lines (37 loc) · 1.48 KB
/
Copy pathExtensionJ.java
File metadata and controls
50 lines (37 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package au.com.auspost.training.ext;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
public class ExtensionJ {
static class URLUtils {
public static String decode(String value) throws UnsupportedEncodingException {
return URLDecoder.decode(value, StandardCharsets.UTF_8.toString());
}
public static String encode(String value) throws UnsupportedEncodingException {
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
}
}
static class IntegerUtils {
public static Integer modulas(Integer number, Integer base) {
return number % base;
}
public static Integer pow(Integer number, Integer exponent) {
return (int) Math.pow(number, exponent);
}
}
public static void main(String args[]) throws UnsupportedEncodingException {
//1. power of function
Integer num = 2;
System.out.println(IntegerUtils.pow(num, 3));
//2. modulas function
num = 15;
System.out.println(IntegerUtils.modulas(num, 10));
//3. safe URL encoding of a string
String test = "Hello world safe URL string";
String encoded = URLUtils.encode(test);
String decoded = URLUtils.decode(encoded);
System.out.println("encoded string = " + encoded);
System.out.println("decoded string = " + decoded);
}
}