Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2880

Enhance ObjectGraphBuilder to support additional plural logic

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 1.1-rc-3
    • 1.6.3, 1.7-beta-1
    • None
    • None
    • Patch

    Description

      groovy.util.ObjectGraphBuilder$DefaultRelationNameResolver currently pluralizes Strings by simply appending 's' to the end of the word. While this works under many scenarios, it breaks down under numerous more. See http://en.wikipedia.org/wiki/English_plural for what I assume is a comprehensive list of rules.

      While I'm not proposing enhancing DefaultRelationNameResolver to support all of the English plural rules, there are some "low hanging fruit" rules that we can support fairly easily. One such rule is the -ies rule. Essentially, under most scenarios, words ending in 'y' preceded by a consonant are pluralized by replacing the 'y' with "ies". For example, allergy --> allergies. However, monkey --> monkeys.

      I understand this proposal does not satisfy all plural scenarios. To do so would require much more work and support for irregular one-off cases. I've attached a patch containing the small change to DefaultRelationNameResolver as well as a unit test verifying the change in behavior.

      Attachments

        1. patch.txt
          4 kB

        Activity

          People

            aalmiray Andres Almiray
            kpshek Kevin Shekleton
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: