Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-5476

Refactor the way gender constants are maintained

    Details

    • Type: Task
    • Status: Closed
    • Priority: Could
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Core 2.3.0
    • Component/s: None
    • Labels:
      None
    • Complexity:
      Low

      Description

      This Sonar issue is about not following naming convention for method:

      public static final Map<String, String> GENDER() {
      	Map<String, String> genders = new LinkedHashMap<>();
      	genders.put("M", "Male");
      	genders.put("F", "Female");
      	return genders;
      }
      

      After checking it, I think a better thing to do is to do a little bit more than fix the name.
      Right now the returned object is a map but it is actually never used as a map. The way it is used, is only to check if it contains a key: "M", or "F" - it never uses the values stored in the map.
      It is also modifiable right now, which is confusing and allows for making mistakes in the code.

      So I'm offering an improvement:

      public static final List<String> GENDERS = Collections.unmodifiableList(asList("M", "F"));
      

      which will:

      • fix the sonar issue,
      • keep the current behavior
      • make the system simpler and less error-prone

        Attachments

          Activity

            People

            • Assignee:
              michal Michal Fotyga
              Reporter:
              michal Michal Fotyga
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: