mbien commented on code in PR #5970:
URL: https://github.com/apache/netbeans/pull/5970#discussion_r1199627949


##########
enterprise/j2ee.core/src/org/netbeans/api/j2ee/core/Profile.java:
##########
@@ -140,134 +123,23 @@ public String toString() {
 
     @CheckForNull
     public static Profile fromPropertiesString(@NullAllowed String value) {
-        String valueMinusQuotes = value;
-        if(value != null && value.contains("\"")){
-            valueMinusQuotes = value.replace("\"","");
-        }
-        if (J2EE_13.toPropertiesString().equals(valueMinusQuotes)) {
-            return J2EE_13;
-        } else if (J2EE_14.toPropertiesString().equals(valueMinusQuotes)) {
-            return J2EE_14;
-        } else if (JAVA_EE_5.toPropertiesString().equals(valueMinusQuotes)) {
-            return JAVA_EE_5;
-        } else if (JAVA_EE_6_FULL.toPropertiesString().equals(valueMinusQuotes)
-                || "EE_6_FULL".equals(value)){ // NOI18N
-            return JAVA_EE_6_FULL;
-        } else if (JAVA_EE_6_WEB.toPropertiesString().equals(valueMinusQuotes)
-                || "EE_6_WEB".equals(value)) {
-            return JAVA_EE_6_WEB;
-        } else if (JAVA_EE_7_FULL.toPropertiesString().equals(valueMinusQuotes)
-                || "EE_7_FULL".equals(value)) { // NOI18N
-            return JAVA_EE_7_FULL;
-        } else if (JAVA_EE_7_WEB.toPropertiesString().equals(valueMinusQuotes)
-                || "EE_7_WEB".equals(value)) {
-            return JAVA_EE_7_WEB;
-        } else if (JAVA_EE_8_FULL.toPropertiesString().equals(valueMinusQuotes)
-                || "EE_8_FULL".equals(value)) { // NOI18N
-            return JAVA_EE_8_FULL;
-        } else if (JAVA_EE_8_WEB.toPropertiesString().equals(valueMinusQuotes)
-                || "EE_8_WEB".equals(value)) {
-            return JAVA_EE_8_WEB;
-        } else if 
(JAKARTA_EE_8_FULL.toPropertiesString().equals(valueMinusQuotes)
-                || "JAKARTA_EE_8_FULL".equals(value)) {
-            return JAKARTA_EE_8_FULL;
-        } else if 
(JAKARTA_EE_8_WEB.toPropertiesString().equals(valueMinusQuotes)
-                || "JAKARTA_EE_8_WEB".equals(value)) {
-            return JAKARTA_EE_8_WEB;
-        } else if 
(JAKARTA_EE_9_FULL.toPropertiesString().equals(valueMinusQuotes)
-                || "JAKARTA_EE_9_FULL".equals(value)) {
-            return JAKARTA_EE_9_FULL;
-        } else if 
(JAKARTA_EE_9_WEB.toPropertiesString().equals(valueMinusQuotes)
-                || "JAKARTA_EE_9_WEB".equals(value)) {
-            return JAKARTA_EE_9_WEB;
-        } else if 
(JAKARTA_EE_9_1_FULL.toPropertiesString().equals(valueMinusQuotes)
-                || "JAKARTA_EE_9_1_FULL".equals(value)) {
-            return JAKARTA_EE_9_1_FULL;
-        } else if 
(JAKARTA_EE_9_1_WEB.toPropertiesString().equals(valueMinusQuotes)
-                || "JAKARTA_EE_9_1_WEB".equals(value)) {
-            return JAKARTA_EE_9_1_WEB;
-        } else if 
(JAKARTA_EE_10_FULL.toPropertiesString().equals(valueMinusQuotes)
-                || "JAKARTA_EE_10_FULL".equals(value)) {
-            return JAKARTA_EE_10_FULL;
-        } else if 
(JAKARTA_EE_10_WEB.toPropertiesString().equals(valueMinusQuotes)
-                || "JAKARTA_EE_10_WEB".equals(value)) {
-            return JAKARTA_EE_10_WEB;
-        } else {
-          return null;
+        if (value == null) {
+            return null;
         }
-    }
-
-    private static String getProfileVersion(@NonNull Profile profile) {
-        String profileDetails = profile.toPropertiesString();
-        int indexOfDash = profileDetails.indexOf("-");
-        if (indexOfDash != -1) {
-            return profileDetails.substring(0, indexOfDash);
-        }
-        return profileDetails;
-    }
 
-    private static boolean compareWebAndFull(@NonNull Profile 
profileToCompare, @NonNull Profile comparingVersion) {
-        boolean isThisFullProfile = isFullProfile(profileToCompare);
-        boolean isParamFullProfile = isFullProfile(comparingVersion);
-        if (isThisFullProfile && isParamFullProfile) {
-            // Both profiles are Java EE Full
-            return true;
-        }
-        if (!isThisFullProfile && !isParamFullProfile) {
-            // Both profiles are Java EE Web
-            return true;
-        }
-        if (isThisFullProfile && !isParamFullProfile) {
-            // profileToCompare is Java EE Full profile and comparingVersion 
is only Java EEWeb profile
-            return true;
-        }
-        return false;
-    }
-
-    private static boolean isFullProfile(@NonNull Profile profile) {
-        final String profileDetails = profile.toPropertiesString();
-        if (profileDetails.indexOf("-") == -1) {
-            return true;
+        String valueMinusQuotes = value;
+        if(value.contains("\"")){
+            valueMinusQuotes = value.replace("\"","");
         }
-        return false;
-    }
 
-    /**
-     * Compares if the first given profile has equal or higher Java EE version
-     * in comparison to the second profile.
-     *
-     * Please be aware of the following rules:
-     * <br/><br/>
-     *
-     * 1) Each Java EE X version is considered as lower than Java EE X+1 
version
-     * (this applies regardless on Web/Full specification and in reality it 
means
-     * that even Java EE 6 Full version is considered as lower than Java EE 7 
Web)
-     * <br/><br/>
-     *
-     * 2) Each Java EE X Web version is considered as lower than Java EE X Full
-     * <br/>
-     *
-     * @param profileToCompare profile that we want to compare
-     * @param comparingVersion version which we are comparing with
-     * @return <code>true</code> if the profile version is equal or higher in
-     *         comparison with the second one, <code>false</code> otherwise
-     * @since 1.19
-     */
-    private static boolean isVersionEqualOrHigher(@NonNull Profile 
profileToCompare, @NonNull Profile comparingVersion) {
-        int comparisonResult = Profile.UI_COMPARATOR.compare(profileToCompare, 
comparingVersion);
-        if (comparisonResult == 0) {
-            // The same version for both
-            return true;
-        } else {
-            String profileToCompareVersion = 
getProfileVersion(profileToCompare);
-            String comparingProfileVersion = 
getProfileVersion(comparingVersion);
-            if (profileToCompareVersion.equals(comparingProfileVersion)) {
-                return compareWebAndFull(profileToCompare, comparingVersion);
-            } else {
-                // profileToCompare has lower version than comparingVersion
-                return comparisonResult <= 0;
+        for (Profile profile : Profile.values()) {
+            if (profile.toPropertiesString().equals(valueMinusQuotes)
+                    || profile.name().equals(value)
+                    || profile.name().endsWith(value)) {
+                return profile;
             }
         }

Review Comment:
   I think I get it: So the input can be `"6-web"` or `"EE_6_WEB" `and you 
match it against the postfix of the enum name `JAVA_EE_6_WEB`
   
   how about:
   ```java
           for (Profile profile : Profile.values()) {
               if (profile.toPropertiesString().equals(valueMinusQuotes)
                       || profile.name().equals(valueMinusQuotes)
                       || (valueMinusQuotes.startsWith("EE_") && 
profile.name().endsWith(valueMinusQuotes))) {
                   return profile;
               }
           }
   ```
   this is likely less risky and does also communicate a bit better what is 
going on there.
   
   To me, a `equals` followed by `endsWith` looks a bit suspicious since it 
makes the equals redundant. It looks like a bug.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to