< prev index next >

langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Options.java

Print this page


   1 /*
   2  * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  54         return instance;
  55     }
  56 
  57     protected Options(Context context) {
  58 // DEBUGGING -- Use LinkedHashMap for reproducability
  59         values = new LinkedHashMap<>();
  60         context.put(optionsKey, this);
  61     }
  62 
  63     /**
  64      * Get the value for an undocumented option.
  65      */
  66     public String get(String name) {
  67         return values.get(name);
  68     }
  69 
  70     /**
  71      * Get the value for an option.
  72      */
  73     public String get(Option option) {
  74         return values.get(option.text);
  75     }
  76 
  77     /**
  78      * Get the boolean value for an option, patterned after Boolean.getBoolean,
  79      * essentially will return true, iff the value exists and is set to "true".
  80      */
  81     public boolean getBoolean(String name) {
  82         return getBoolean(name, false);
  83     }
  84 
  85     /**
  86      * Get the boolean with a default value if the option is not set.
  87      */
  88     public boolean getBoolean(String name, boolean defaultValue) {
  89         String value = get(name);
  90         return (value == null) ? defaultValue : Boolean.parseBoolean(value);
  91     }
  92 
  93     /**
  94      * Check if the value for an undocumented option has been set.
  95      */
  96     public boolean isSet(String name) {
  97         return (values.get(name) != null);
  98     }
  99 
 100     /**
 101      * Check if the value for an option has been set.
 102      */
 103     public boolean isSet(Option option) {
 104         return (values.get(option.text) != null);
 105     }
 106 
 107     /**
 108      * Check if the value for a choice option has been set to a specific value.
 109      */
 110     public boolean isSet(Option option, String value) {
 111         return (values.get(option.text + value) != null);
 112     }
 113 
 114     /**
 115      * Check if the value for an undocumented option has not been set.
 116      */
 117     public boolean isUnset(String name) {
 118         return (values.get(name) == null);
 119     }
 120 
 121     /**
 122      * Check if the value for an option has not been set.
 123      */
 124     public boolean isUnset(Option option) {
 125         return (values.get(option.text) == null);
 126     }
 127 
 128     /**
 129      * Check if the value for a choice option has not been set to a specific value.
 130      */
 131     public boolean isUnset(Option option, String value) {
 132         return (values.get(option.text + value) == null);
 133     }
 134 
 135     public void put(String name, String value) {
 136         values.put(name, value);
 137     }
 138 
 139     public void put(Option option, String value) {
 140         values.put(option.text, value);
 141     }
 142 
 143     public void putAll(Options options) {
 144         values.putAll(options.values);
 145     }
 146 
 147     public void remove(String name) {
 148         values.remove(name);
 149     }
 150 
 151     public Set<String> keySet() {
 152         return values.keySet();
 153     }
 154 
 155     public int size() {
 156         return values.size();
 157     }
 158 
 159     // light-weight notification mechanism
 160 


   1 /*
   2  * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  54         return instance;
  55     }
  56 
  57     protected Options(Context context) {
  58 // DEBUGGING -- Use LinkedHashMap for reproducability
  59         values = new LinkedHashMap<>();
  60         context.put(optionsKey, this);
  61     }
  62 
  63     /**
  64      * Get the value for an undocumented option.
  65      */
  66     public String get(String name) {
  67         return values.get(name);
  68     }
  69 
  70     /**
  71      * Get the value for an option.
  72      */
  73     public String get(Option option) {
  74         return values.get(option.primaryName);
  75     }
  76 
  77     /**
  78      * Get the boolean value for an option, patterned after Boolean.getBoolean,
  79      * essentially will return true, iff the value exists and is set to "true".
  80      */
  81     public boolean getBoolean(String name) {
  82         return getBoolean(name, false);
  83     }
  84 
  85     /**
  86      * Get the boolean with a default value if the option is not set.
  87      */
  88     public boolean getBoolean(String name, boolean defaultValue) {
  89         String value = get(name);
  90         return (value == null) ? defaultValue : Boolean.parseBoolean(value);
  91     }
  92 
  93     /**
  94      * Check if the value for an undocumented option has been set.
  95      */
  96     public boolean isSet(String name) {
  97         return (values.get(name) != null);
  98     }
  99 
 100     /**
 101      * Check if the value for an option has been set.
 102      */
 103     public boolean isSet(Option option) {
 104         return (values.get(option.primaryName) != null);
 105     }
 106 
 107     /**
 108      * Check if the value for a choice option has been set to a specific value.
 109      */
 110     public boolean isSet(Option option, String value) {
 111         return (values.get(option.primaryName + value) != null);
 112     }
 113 
 114     /**
 115      * Check if the value for an undocumented option has not been set.
 116      */
 117     public boolean isUnset(String name) {
 118         return (values.get(name) == null);
 119     }
 120 
 121     /**
 122      * Check if the value for an option has not been set.
 123      */
 124     public boolean isUnset(Option option) {
 125         return (values.get(option.primaryName) == null);
 126     }
 127 
 128     /**
 129      * Check if the value for a choice option has not been set to a specific value.
 130      */
 131     public boolean isUnset(Option option, String value) {
 132         return (values.get(option.primaryName + value) == null);
 133     }
 134 
 135     public void put(String name, String value) {
 136         values.put(name, value);
 137     }
 138 
 139     public void put(Option option, String value) {
 140         values.put(option.primaryName, value);
 141     }
 142 
 143     public void putAll(Options options) {
 144         values.putAll(options.values);
 145     }
 146 
 147     public void remove(String name) {
 148         values.remove(name);
 149     }
 150 
 151     public Set<String> keySet() {
 152         return values.keySet();
 153     }
 154 
 155     public int size() {
 156         return values.size();
 157     }
 158 
 159     // light-weight notification mechanism
 160 


< prev index next >