Commons Lang
  1. Commons Lang
  2. LANG-186

[lang] Request for MutableBoolean implementation

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      I ran into a situation where a MutableBoolean implementation was actually useful and wondered if
      Commons Lang might consider adding the implementation. My example:

      final MutableBoolean success = new MutableBoolean(false);
      doSomething(new MyCallbackInterface() {
      public void callback()

      { // do something... success.setValue(true); }

      );

      Basically the ability to change the boolean's state within an inner class, where the declared object must
      be 'final'. Pretty obscure I realize, but this turned out to be quite useful in the application I was working
      on.

        Activity

        Hide
        ggregory@seagullsw.com added a comment -

        Seems reasonable since we have other types covered in
        org.apache.commons.lang.mutable. Feel free to provide a patch.

        Show
        ggregory@seagullsw.com added a comment - Seems reasonable since we have other types covered in org.apache.commons.lang.mutable. Feel free to provide a patch.
        Hide
        Matt Magoffin added a comment -

        Created an attachment (id=16725)
        Proposed patch

        Proposed implementation for MutableBoolean class.

        Show
        Matt Magoffin added a comment - Created an attachment (id=16725) Proposed patch Proposed implementation for MutableBoolean class.
        Hide
        Jörg Gottschling added a comment -

        The proposal has a method compareTo(Object) but does not implement Comparable.

        Show
        Jörg Gottschling added a comment - The proposal has a method compareTo(Object) but does not implement Comparable.
        Hide
        Matt Magoffin added a comment -

        Created an attachment (id=16736)
        Proposed patch

        My mistake, this version implements Comparable as well.

        Show
        Matt Magoffin added a comment - Created an attachment (id=16736) Proposed patch My mistake, this version implements Comparable as well.
        Hide
        Matt Magoffin added a comment -

        Created an attachment (id=16737)
        Proposed patch

        I noticed a bug in the compareTo method.

        Show
        Matt Magoffin added a comment - Created an attachment (id=16737) Proposed patch I noticed a bug in the compareTo method.
        Hide
        ggregory@seagullsw.com added a comment -

        If you provide a patch for the unit tests as well, I'll integrate this feature
        over the next couple of days.

        Show
        ggregory@seagullsw.com added a comment - If you provide a patch for the unit tests as well, I'll integrate this feature over the next couple of days.
        Hide
        Matt Magoffin added a comment -

        Created an attachment (id=16763)
        Proposed patch unit test

        Here's a unit test, based off the MutableIntTest.

        Show
        Matt Magoffin added a comment - Created an attachment (id=16763) Proposed patch unit test Here's a unit test, based off the MutableIntTest.
        Hide
        Jörg Gottschling added a comment -

        Why does new MutableBoolean(null) throw a NullPointerException? setValue does
        this also. I think a IllegalArgumentException would suite better. I propose a
        ~.commons.lang.NullArgumentException.

        setValue("false") should throw a IllegalClassException, I think. How does the
        other mutables handle this?

        Show
        Jörg Gottschling added a comment - Why does new MutableBoolean(null) throw a NullPointerException? setValue does this also. I think a IllegalArgumentException would suite better. I propose a ~.commons.lang.NullArgumentException. setValue("false") should throw a IllegalClassException, I think. How does the other mutables handle this?
        Hide
        Matt Magoffin added a comment -

        (In reply to comment #8)
        I simply based the class off the way MutableInt and the other Mutable implementations work. Perhaps Gary
        can speak to your questions.

        Show
        Matt Magoffin added a comment - (In reply to comment #8) I simply based the class off the way MutableInt and the other Mutable implementations work. Perhaps Gary can speak to your questions.
        Hide
        ggregory@seagullsw.com added a comment -

        Committed to SVN with minor tweaks.

        Matt: Would you like to be credited as a contributor in project.xml?

        Thanks.

        Show
        ggregory@seagullsw.com added a comment - Committed to SVN with minor tweaks. Matt: Would you like to be credited as a contributor in project.xml? Thanks.
        Hide
        Matt Magoffin added a comment -

        (In reply to comment #10)
        Sure, that would be great, thank you.

        Show
        Matt Magoffin added a comment - (In reply to comment #10) Sure, that would be great, thank you.

          People

          • Assignee:
            Unassigned
            Reporter:
            Matt Magoffin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development