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

Remove not needed checks on collections

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Code Review (Initial)
    • Priority: Could
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: OpenMRS 1.7.5, Core 2.2.0
    • Component/s: None
    • Labels:
    • Complexity:
      Low

      Description

      There are some not needed checks on List and Set collections that don't bring any value besides restating the behavior or these collections.

      private List<String> proxies = ...
      if (proxies.contains(privilege)) {
      	proxies.remove(privilege);
      }
      

      Calling contains on a list only takes processing power but does not add any value.
      Even if contains returns true, remove will have to locate the element once again so there is no performance gain of having this check.
      This means that without loosing the behavior, it can be replaced with a simpler:

      private List<String> proxies = ...
      proxies.remove(privilege);
      

      Similarly with sets:

      private Set<MutableMessageSource> availableMessageSources = ...
      if (!availableMessageSources.contains(activeMessageSource)) {
      	availableMessageSources.add(activeMessageSource);
      }
      

      It's a Set, so the uniqueness of elements is given to us for free.
      This can be replaced with:

      private Set<MutableMessageSource> availableMessageSources = ...
      availableMessageSources.add(activeMessageSource);
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours
                2h