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 package de.nierbeck.timeTrack;
29
30 /***
31 * Utility Class.
32 *
33 * @author Achim
34 *
35 */
36 public final class Assert {
37
38 /***
39 * Checks if the given Object equals "null" if so it throws an
40 * IllegalArgumentException.
41 *
42 * @param obj the given Object
43 *
44 * @throws IllegalArgumentException
45 */
46 public static void notNull(final Object obj) {
47 if (obj == null) {
48 throw new IllegalArgumentException();
49 }
50 }
51
52 private Assert() {
53 super();
54
55 }
56
57 /***
58 * validates the given Time string.
59 *
60 * @param time - the time to validate
61 * @return the validated time string
62 */
63 public static String timeValidation(final String time) {
64 final int length = time.length();
65 int colonCount = 0;
66 String cloneTime = new String(time);
67
68 for (int i = 0; i < length; i++) {
69 char character = cloneTime.charAt(i);
70 if (character == ':') {
71 colonCount++;
72 }
73 }
74
75
76
77
78
79 StringBuffer timeBuff = new StringBuffer(cloneTime);
80
81 if (colonCount < 2) {
82 if (colonCount < 1) {
83 if (cloneTime.length() == 1) {
84 timeBuff = new StringBuffer("0");
85 timeBuff.append(cloneTime);
86 }
87 timeBuff.append(':');
88 timeBuff.append("00");
89 } else if (cloneTime.indexOf(':') < 2) {
90 timeBuff = new StringBuffer("0");
91 timeBuff.append(cloneTime);
92 }
93 String minutes = cloneTime.substring(3);
94 if (minutes.length() < 2) {
95 minutes = "0" + minutes;
96 timeBuff.append(minutes);
97 }
98 timeBuff.append(':');
99 timeBuff.append("00");
100
101
102 }
103
104 return timeBuff.toString();
105 }
106
107 /***
108 *
109 * @param date - does nothing
110 * @return nothing
111 */
112 public static String dateValidation(final String date) {
113
114
115 throw new UnsupportedOperationException();
116 }
117 }