11/*******************************************************************************
2- * Copyright (c) 2014, 2025 Pivotal, Inc.
2+ * Copyright (c) 2014-2017 Pivotal, Inc.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License v1.0
55 * which accompanies this distribution, and is available at
1111package org .springframework .ide .vscode .commons .util ;
1212
1313import java .util .Collection ;
14- import java .util .Set ;
14+ import java .util .Collections ;
1515import java .util .TreeSet ;
1616import java .util .concurrent .Callable ;
1717import java .util .function .Supplier ;
18- import java .util .stream .Collectors ;
1918
2019import com .google .common .collect .ImmutableSet ;
2120
@@ -31,7 +30,6 @@ public class EnumValueParser implements ValueParser {
3130 private Supplier <PartialCollection <String >> values ;
3231 private final boolean longRunning ;
3332
34- private transient Set <String > _canonicalValues ;
3533
3634 public EnumValueParser (String typeName , String ... values ) {
3735 this (typeName , ImmutableSet .copyOf (values ));
@@ -72,14 +70,24 @@ public Object parse(String str) throws Exception {
7270 throw errorOnBlank (createBlankTextErrorMessage ());
7371 }
7472
75- Set <String > canonicalValues = getCanonicalValues ();
76-
77- if (canonicalValues == null || canonicalValues .contains (getCanonicalName (str ))) {
73+ PartialCollection <String > values = this .values .get ();
74+
75+ // If values is not fully known then just assume the str is acceptable.
76+ if (values == null || !values .isComplete () || hasMatchingValue (str , values .getElements ())) {
7877 return str ;
7978 } else {
80- throw errorOnParse (createErrorMessage (str , this . values . get () .getElements ()));
79+ throw errorOnParse (createErrorMessage (str , values .getElements ()));
8180 }
8281 }
82+
83+ protected final Collection <String > getAllKnownValues () {
84+ PartialCollection <String > partialCollection = this .values .get ();
85+ return partialCollection == null ? Collections .emptyList () : this .values .get ().getElements ();
86+ }
87+
88+ protected boolean hasMatchingValue (String str , Collection <String > values ) {
89+ return values .contains (str );
90+ }
8391
8492 protected String createBlankTextErrorMessage () {
8593 return "'" + typeName + "'" + " cannot be blank." ;
@@ -100,21 +108,4 @@ protected Exception errorOnBlank(String message) {
100108 public boolean longRunning () {
101109 return this .longRunning ;
102110 }
103-
104- private Set <String > getCanonicalValues () {
105- PartialCollection <String > partialCollection = this .values .get ();
106- if (partialCollection != null ) {
107- _canonicalValues = partialCollection .getElements ().stream ().map (EnumValueParser ::getCanonicalName ).collect (Collectors .toSet ());
108- }
109- return _canonicalValues ;
110- }
111-
112- static String getCanonicalName (String name ) {
113- StringBuilder canonicalName = new StringBuilder (name .length ());
114- name .chars ()
115- .filter (Character ::isLetterOrDigit )
116- .map (Character ::toLowerCase )
117- .forEach ((c ) -> canonicalName .append ((char ) c ));
118- return canonicalName .toString ();
119- }
120111}
0 commit comments