Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0
    • Component/s: lang.*
    • Labels:
      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.

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

        Issue Links

          Activity

          Jörg Gottschling created issue -
          Jörg Gottschling made changes -
          Field Original Value New Value
          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. 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.
          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.
          Henri Yandell made changes -
          Fix Version/s LangTwo 1.0 [ 12312130 ]
          Affects Version/s LangTwo 1.0 [ 12312130 ]
          Hide
          Jörg Gottschling added a comment -

          trivial implementation of coalesce

          Show
          Jörg Gottschling added a comment - trivial implementation of coalesce
          Jörg Gottschling made changes -
          Attachment ObjectUtils.java [ 12368096 ]
          Hide
          Jörg Gottschling added a comment -

          test for the method

          Show
          Jörg Gottschling added a comment - test for the method
          Jörg Gottschling made changes -
          Attachment ObjectUtilsTest.java [ 12368097 ]
          Henri Yandell made changes -
          Fix Version/s 3.0 [ 12311714 ]
          Fix Version/s LangTwo 1.0 [ 12312130 ]
          Hide
          Henri Yandell added a comment -

          Ponders coalesce vs 'firstNotNull'.

          Interesting that the first doc I found on SQL coalesce uses firstNotNull as the label:

          http://msdn.microsoft.com/en-us/library/ms190349.aspx

          Show
          Henri Yandell added a comment - Ponders coalesce vs 'firstNotNull'. Interesting that the first doc I found on SQL coalesce uses firstNotNull as the label: http://msdn.microsoft.com/en-us/library/ms190349.aspx
          thomas menzel made changes -
          Link This issue is duplicated by LANG-550 [ LANG-550 ]
          Hide
          Henri Yandell added a comment -

          svn ci -m "Applying Jörg Gottschling's patch from LANG-358 with Thomas Menzel's naming from LANG-550 and some of his tests. This adds a firstNonNull method to ObjectUtils. " src
          Sending src/java/org/apache/commons/lang/ObjectUtils.java
          Sending src/test/org/apache/commons/lang/ObjectUtilsTest.java
          Transmitting file data ..
          Committed revision 833016.

          Show
          Henri Yandell added a comment - svn ci -m "Applying Jörg Gottschling's patch from LANG-358 with Thomas Menzel's naming from LANG-550 and some of his tests. This adds a firstNonNull method to ObjectUtils. " src Sending src/java/org/apache/commons/lang/ObjectUtils.java Sending src/test/org/apache/commons/lang/ObjectUtilsTest.java Transmitting file data .. Committed revision 833016.
          Henri Yandell made changes -
          Status Open [ 1 ] Closed [ 6 ]
          Resolution Fixed [ 1 ]
          Henri Yandell made changes -
          Component/s lang.* [ 12313203 ]
          Mark Thomas made changes -
          Workflow jira [ 12414851 ] Default workflow, editable Closed status [ 12602602 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Jörg Gottschling
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development