KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nl > hippo > asserts > FileAsserts


1 /*
2  * Copyright 2004 Hippo Webworks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
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.apache.org/licenses/LICENSE-2.0
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 package nl.hippo.asserts;
17
18 import java.io.File JavaDoc;
19
20 public class FileAsserts extends Asserts
21 {
22     
23     public static void existingDirectory(String JavaDoc directoryName, ExceptionFactory exceptionFactory, String JavaDoc identifier)
24     {
25         if (isNonExistingDirectory(new File JavaDoc(directoryName)))
26         {
27             throw createException(exceptionFactory, identifier + " must be an existing directory");
28         }
29     }
30     
31     public static void existingDirectory(File JavaDoc directory, ExceptionFactory exceptionFactory, String JavaDoc identifier)
32     {
33         if (isNonExistingDirectory(directory))
34         {
35             throw createException(exceptionFactory, identifier + " must be an existing directory");
36         }
37     }
38     
39     /**
40      * @deprecated Use the overloaded method using an exception factory instead.
41      * @param directoryName
42      * @param exception
43      */

44     public static void existingDirectory(String JavaDoc directoryName, RuntimeException JavaDoc exception)
45     {
46         existingDirectory(new File JavaDoc(directoryName), exception);
47     }
48
49     /**
50      * @deprecated Use the overloaded method using an exception factory instead.
51      * @param directory
52      * @param exception
53      */

54     public static void existingDirectory(File JavaDoc directory, RuntimeException JavaDoc exception)
55     {
56         if (isNonExistingDirectory(directory))
57         {
58             throw exception;
59         }
60     }
61
62     private static boolean isNonExistingDirectory(File JavaDoc directory)
63     {
64         return !directory.exists() || !directory.isDirectory();
65     }
66
67     private FileAsserts()
68     {
69         super();
70     }
71
72 }
Popular Tags