< prev index next >

src/jdk.jpackage/share/classes/jdk/jpackage/internal/EnumeratedBundlerParam.java

Print this page




  47  *
  48  *     String key = getLastValue(keys); // get last value for example
  49  *
  50  *     String value = MAC_CATEGORY.getValueForDisplayableKey(key);
  51  *     params.put(MAC_CATEGORY.getID(), value);
  52  * }</pre>
  53  *
  54  */
  55 class EnumeratedBundlerParam<T> extends BundlerParamInfo<T> {
  56     // Not sure if this is the correct order, my idea is that from IDE
  57     // perspective the string to display to the user is the key and then the
  58     // value is some type of object (although probably a String in most cases)
  59     private final Map<String, T> elements;
  60     private final boolean strict;
  61 
  62     EnumeratedBundlerParam(String name, String description,
  63             String id, Class<T> valueType,
  64             Function<Map<String, ? super Object>, T> defaultValueFunction,
  65             BiFunction<String, Map<String, ? super Object>, T> stringConverter,
  66             Map<String, T> elements, boolean strict) {
  67         this.name = name;
  68         this.description = description;
  69         this.id = id;
  70         this.valueType = valueType;
  71         this.defaultValueFunction = defaultValueFunction;
  72         this.stringConverter = stringConverter;
  73         this.elements = elements;
  74         this.strict = strict;
  75     }
  76 
  77     boolean isInPossibleValues(T value) {
  78         return elements.values().contains(value);
  79     }
  80 
  81     // Having the displayable values as the keys seems a bit wacky
  82     Set<String> getDisplayableKeys() {
  83         return Collections.unmodifiableSet(elements.keySet());
  84     }
  85 
  86     // mapping from a "displayable" key to an "identifier" value.
  87     T getValueForDisplayableKey(String displayableKey) {
  88         return elements.get(displayableKey);
  89     }
  90 
  91     boolean isStrict() {
  92         return strict;
  93     }
  94 
  95     boolean isLoose() {
  96         return !isStrict();
  97     }
  98 
  99     T validatedFetchFrom(Map<String, ? super Object> params)
 100             throws InvalidBundlerParamException {
 101         if (isStrict()) {
 102             T value = fetchFrom(params);
 103             if (!isInPossibleValues(value)) {
 104                 throw new InvalidBundlerParamException("Parameter "
 105                         + value.toString()
 106                         + " not in valid set of values for BundlerParam "
 107                         + name);
 108             }
 109             return value;
 110         }
 111         return fetchFrom(params);
 112     }
 113 
 114 }


  47  *
  48  *     String key = getLastValue(keys); // get last value for example
  49  *
  50  *     String value = MAC_CATEGORY.getValueForDisplayableKey(key);
  51  *     params.put(MAC_CATEGORY.getID(), value);
  52  * }</pre>
  53  *
  54  */
  55 class EnumeratedBundlerParam<T> extends BundlerParamInfo<T> {
  56     // Not sure if this is the correct order, my idea is that from IDE
  57     // perspective the string to display to the user is the key and then the
  58     // value is some type of object (although probably a String in most cases)
  59     private final Map<String, T> elements;
  60     private final boolean strict;
  61 
  62     EnumeratedBundlerParam(String name, String description,
  63             String id, Class<T> valueType,
  64             Function<Map<String, ? super Object>, T> defaultValueFunction,
  65             BiFunction<String, Map<String, ? super Object>, T> stringConverter,
  66             Map<String, T> elements, boolean strict) {


  67         this.id = id;
  68         this.valueType = valueType;
  69         this.defaultValueFunction = defaultValueFunction;
  70         this.stringConverter = stringConverter;
  71         this.elements = elements;
  72         this.strict = strict;
  73     }
  74 
  75     boolean isInPossibleValues(T value) {
  76         return elements.values().contains(value);
  77     }
  78 
  79     // Having the displayable values as the keys seems a bit wacky
  80     Set<String> getDisplayableKeys() {
  81         return Collections.unmodifiableSet(elements.keySet());
  82     }
  83 
  84     // mapping from a "displayable" key to an "identifier" value.
  85     T getValueForDisplayableKey(String displayableKey) {
  86         return elements.get(displayableKey);
  87     }
  88 
  89     boolean isStrict() {
  90         return strict;
  91     }
  92 
  93     boolean isLoose() {
  94         return !isStrict();















  95     }
  96 
  97 }
< prev index next >