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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.ui.cleanup;
13 import java.util.Collections;
14 import java.util.Hashtable;
18 import org.eclipse.core.runtime.Assert;
20 import org.eclipse.jdt.internal.corext.fix.CleanUpConstants;
24 * Allows to set and retrieve clean up settings for given options keys.
27 * @noextend This class is not intended to be subclassed by clients.
29 public class CleanUpOptions {
31 private final Map<String, String> fOptions;
36 public static final String TRUE= "true"; //$NON-NLS-1$
41 public static final String FALSE= "false"; //$NON-NLS-1$
44 * Creates a new CleanUpOptions instance with the given options.
46 * @param options map that maps clean ups keys (<code>String</code>) to a non-<code>null</code>
49 protected CleanUpOptions(Map<String, String> options) {
54 * Creates a new instance.
56 public CleanUpOptions() {
57 fOptions= new Hashtable<String, String>();
61 * Tells whether the option with the given <code>key</code> is enabled.
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
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);
75 * Returns the value for the given key.
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
81 public String getValue(String key) {
82 Assert.isLegal(key != null);
83 String value= fOptions.get(key);
84 Assert.isLegal(value != null);
89 * Sets the option for the given key to the given value.
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
97 public void setOption(String key, String value) {
98 Assert.isLegal(key != null);
99 Assert.isLegal(value != null);
100 fOptions.put(key, value);
104 * Returns an unmodifiable set of all known keys.
106 * @return an unmodifiable set of all keys
108 public Set<String> getKeys() {
109 return Collections.unmodifiableSet(fOptions.keySet());