A way to count unique occurrences using automation

XMLWordPrintable

      Issue Summary

      Arguably, today, there is no way to count unique occurrences of items (Strings, numbers, list items, etc..) without relying on an external system. Distinct (Jira smart values - lists) is close enough, but it removes duplicates and we would need a way to count them instead:

      Java example:
      https://stackoverflow.com/questions/12719998/how-to-count-unique-values-in-an-arraylist

      Starting from Java 8 you can use Stream:

      After you add the elements in your ArrayList:
       
      long n = wordStore.stream().distinct().count();

      It converts your ArrayList to a stream and then it counts only the distinct elements.

      Shell example:

      $ echo word1 word1 word2 word3 word1 word4 word2 word2 | xargs -n1 | sort | uniq -c
         3 word1
         3 word2
         1 word3
         1 word4
      

      Usage scenarios

      • Counting the occurrences of a given word in a ticket's description
      • Counting and grouping the number of selected items in a list custom field that have something in common (a substring for example)
      • Counting and grouping the number of selected Objects in an Assets custom field that holds multiple objects

       

      Workaround

      An external system. ScriptRunner for Jira might be an option (citation needed)

            Assignee:
            Unassigned
            Reporter:
            Wesley Nery
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: