View Javadoc

1   /* ======================================
2    * Copyright (c) 2004-2005 Achim Nierbeck
3    * All rights reserved.
4    *
5    * You may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *       http://www.gnu.org/licenses/lgpl.html
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   * ======================================
16   */
17  
18  /*
19   *
20   * Assert.java
21   * $Revision: 1.6 $
22   * Date 14.12.2005
23   *
24   * $Author: nierbeck $ 
25   * $Date: 2006/02/03 22:32:36 $ 
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  		// private Constructor for this utility class
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  //		if (length == 8 && colonCount == 2) {
76  //			return time;
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 			//return timeBuff.toString();
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 		// TODO Auto-generated method stub
114 		//return date;
115 		throw new UnsupportedOperationException();
116 	}
117 }