commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject Mutables Was: [lang] TODO for 2.1
Date Mon, 01 Sep 2003 01:58:02 GMT


On Sun, 31 Aug 2003, Henri Yandell wrote:

>
>
> On Thu, 28 Aug 2003, Stephen Colebourne wrote:
>
> > - Mutable Number classes

Assuming we don't already have the mutable code in another project, I've
put together a simple MBoolean class to act as a framework on which to
argue. Code follows, then questions:

***********************************
package org.apache.commons.lang.mutable;

import java.io.Serializable;

public final class MBoolean implements Serializable, Mutable {

    public static final MBoolean TRUE = new MBoolean(true);
    public static final MBoolean FALSE = new MBoolean(false);
    public static final Class TYPE = MBoolean.class;

    private Boolean value;

    /// Start copy of Boolean 'interface'
    public MBoolean(boolean b) {
        this.value = new Boolean(b);
    }
    public MBoolean(String str) {
        this.value = new Boolean(str);
    }

    public boolean booleanValue() {
        return this.value.booleanValue();
    }
    public static MBoolean valueOf(boolean b) {
        return b ? TRUE : FALSE;
    }
    public static MBoolean valueOf(String str) {
        // does Boolean return TRUE/FALSE here? Bet it does.
        Boolean b = new Boolean(str);
        return valueOf(b.booleanValue());
    }
    public static String toString(boolean b) {
        return b ? TRUE.toString() : FALSE.toString();
    }
    public String toString() {
        return this.value.toString();
    }
    public int hashCode() {
        return this.hashCode.toString();
    }
    public boolean equals(Object obj) {
        // Implementation needs thought....
    }
    public static boolean getBoolean(String str) {
        return Boolean.getBoolean(str);
    }
    // End of copy of Boolean 'interface'

    // Start of Mutable interface
    public void setValue(Object obj) {
        if(obj instanceof Boolean) {
            this.value = (Boolean)obj;
        } else {
            throw new IllegalArgumentException("Cannot set an MBoolean
with a no
n-Boolean.  ");
        }
    }
    // End of Mutable interface

    // Helper methods
    public void setValue(boolean b) {
        this.value = new Boolean(b);
    }

}

***********************************************

Things that I think are worth arguing:

*) Should there be a Mutable interface?
*) Should helper mutable methods exist?
*) Should static methods from the Boolean class be implemented?
*) Should the naming convention be MXxxx
*) Should the MXxxx decorate an Xxxx or an xxxx. [ie primitive or wrapper?]
*) Is a .mutable subpackage okay?
*) How exactly should equals() work [I'm ignoring it for the moment]

Hen


Mime
View raw message