KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > classycle > dependency > DefaultPreferenceFactory


1 /*
2  * Copyright (c) 2003-2006, Franz-Josef Elmer, All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
15  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */

25 package classycle.dependency;
26
27 import java.util.HashMap JavaDoc;
28
29
30 /**
31  * Factory of {@link Preference Preferences} known by the
32  * {@link DefaultResultRenderer}.
33  *
34  * <table border="1" cellspacing="0" cellpadding="5">
35  * <tr><th>Preference Key</th><th>Description</th></tr>
36  * <tr><td><tt>onlyShortestPaths</tt></td>
37  * <td>Only the shortest paths are reported in the case of
38  * unwanted dependencies.</td>
39  * </tr>
40  * <tr><td><tt>allPaths</tt></td>
41  * <td>All paths are reported in the case of
42  * unwanted dependencies.</td>
43  * </tr>
44  * <tr><td><tt>onlyFailures</tt></td>
45  * <td>Only results are reported which are not ok.</td>
46  * </tr>
47  * <tr><td><tt>allResults</tt></td>
48  * <td>All results are reported.</td>
49  * </tr>
50  * </table>
51  * @author Franz-Josef Elmer
52  */

53 public class DefaultPreferenceFactory implements PreferenceFactory
54 {
55   public static final Preference ONLY_SHORTEST_PATHS
56                   = new DefaultPreference("onlyShortestPaths");
57   public static final Preference ALL_PATHS = new DefaultPreference("allPaths");
58   public static final Preference ALL_RESULTS
59                   = new DefaultPreference("allResults");
60   public static final Preference ONLY_FAILURES
61                   = new DefaultPreference("onlyFailures");
62   
63   private static class DefaultPreference implements Preference
64   {
65     private static final HashMap JavaDoc REPOSITORY = new HashMap JavaDoc();
66     public static Preference getPreference(String JavaDoc key)
67     {
68       return (Preference) REPOSITORY.get(key);
69     }
70     private final String JavaDoc _key;
71     protected DefaultPreference(String JavaDoc key)
72     {
73       _key = key;
74       if (REPOSITORY.containsKey(key))
75       {
76         throw new IllegalArgumentException JavaDoc(
77                     "There exists already an instance for '" + key + "'.");
78       }
79       REPOSITORY.put(key, this);
80     }
81     public final String JavaDoc getKey()
82     {
83       return _key;
84     }
85     public String JavaDoc toString()
86     {
87       return getKey();
88     }
89   }
90
91   public Preference get(String JavaDoc key)
92   {
93     return DefaultPreference.getPreference(key);
94   }
95
96 }
97
Popular Tags