]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui/org/eclipse/jdt/ui/cleanup/CleanUpOptions.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / ui / cleanup / CleanUpOptions.java
1 /*******************************************************************************
2  * Copyright (c) 2008, 2011 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.ui.cleanup;
12
13 import java.util.Collections;
14 import java.util.Hashtable;
15 import java.util.Map;
16 import java.util.Set;
17
18 import org.eclipse.core.runtime.Assert;
19
20 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
21
22
23 /**
24  * Allows to set and retrieve clean up settings for given options keys.
25  * 
26  * @since 3.5
27  * @noextend This class is not intended to be subclassed by clients.
28  */
29 public class CleanUpOptions {
30
31         private final Map<String, String> fOptions;
32
33         /**
34          * True value
35          */
36         public static final String TRUE= "true"; //$NON-NLS-1$
37
38         /**
39          * False value
40          */
41         public static final String FALSE= "false"; //$NON-NLS-1$
42
43         /**
44          * Creates a new CleanUpOptions instance with the given options.
45          * 
46          * @param options map that maps clean ups keys (<code>String</code>) to a non-<code>null</code>
47          *            string value
48          */
49         protected CleanUpOptions(Map<String, String> options) {
50                 fOptions= options;
51         }
52
53         /**
54          * Creates a new instance.
55          */
56         public CleanUpOptions() {
57                 fOptions= new Hashtable<String, String>();
58         }
59
60         /**
61          * Tells whether the option with the given <code>key</code> is enabled.
62          * 
63          * @param key the name of the option
64          * @return <code>true</code> if enabled, <code>false</code> if not enabled or unknown key
65          * @throws IllegalArgumentException if the key is <code>null</code>
66          * @see CleanUpConstants
67          */
68         public boolean isEnabled(String key) {
69                 Assert.isLegal(key != null);
70                 Object value= fOptions.get(key);
71                 return CleanUpOptions.TRUE == value || CleanUpOptions.TRUE.equals(value);
72         }
73
74         /**
75          * Returns the value for the given key.
76          * 
77          * @param key the key of the value
78          * @return the value associated with the key
79          * @throws IllegalArgumentException if the key is null or unknown
80          */
81         public String getValue(String key) {
82                 Assert.isLegal(key != null);
83                 String value= fOptions.get(key);
84                 Assert.isLegal(value != null);
85                 return value;
86         }
87
88         /**
89          * Sets the option for the given key to the given value.
90          * 
91          * @param key the name of the option to set
92          * @param value the value of the option
93          * @throws IllegalArgumentException if the key is <code>null</code>
94          * @see CleanUpOptions#TRUE
95          * @see CleanUpOptions#FALSE
96          */
97         public void setOption(String key, String value) {
98                 Assert.isLegal(key != null);
99                 Assert.isLegal(value != null);
100                 fOptions.put(key, value);
101         }
102
103         /**
104          * Returns an unmodifiable set of all known keys.
105          * 
106          * @return an unmodifiable set of all keys
107          */
108         public Set<String> getKeys() {
109                 return Collections.unmodifiableSet(fOptions.keySet());
110         }
111 }