Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-358

ObjectUtils.coalesce

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0
    • lang.*
    • None

    Description

      I like to see the coalesce-function from SQL implemented in ObjectUtils. Something like this:
      <T> T ObjectUtils.coalesce(T... t)
      The first object, which is not null will be returned. This would replace all the defaultValue/defaultString/... methods, with al flexibler and shorter method. It will also reuse an existing name.

      I think it's simple. Perhaps there should be overloading methods with fixed parameter sizes. Following the jdk this seems to a little faster:
      <T> T ObjectUtils.coalesce(T t1, T t2)
      <T> T ObjectUtils.coalesce(T t1, T t2, T t3)
      ...

      I would provide it, including tests, if you like.

      Attachments

        1. ObjectUtils.java
          2 kB
          Jörg Gottschling
        2. ObjectUtilsTest.java
          1 kB
          Jörg Gottschling

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jogi Jörg Gottschling
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: