db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Beams (JIRA)" <j...@apache.org>
Subject [jira] Commented: (JDO-528) JDOHelper.getObjectState() : convenience method to return the state of an object
Date Sun, 16 Sep 2007 15:18:32 GMT

    [ https://issues.apache.org/jira/browse/JDO-528?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12527869
] 

Chris Beams commented on JDO-528:
---------------------------------

Andy,

Looks nice, thanks for implementing.  One question:  Why not just assign the string value
directly in the constructor of the enum?

Currently it looks like:

public enum ObjectState {
    TRANSIENT(1),
    TRANSIENT_CLEAN(2),
    ...;

    private final int value;

    ObjectState(int v) {
        this.value = v;
    }

    public final int getValue() {
        return v;
    }

    public String toString() {
        if(value == 1) {
            return "transient";
        }
        else if (value == 2) {
            return "transient-clean";
        }
        // ...
    }
}


I believe it would be simpler / cleaner to implement as follows:


public enum ObjectState {
    TRANSIENT("transient"),
    TRANSIENT_CLEAN("transient-clean"),
    HOLLOW_PERSISTENT_NONTRANSACTIONAL("hollow/persistent-nontransactional")
    ...;

    private final String value;

    ObjectState(String value) {
        this.value = value;
    }

    // omitting the 'getValue()' method...

    public String toString() {
        return value;
    }
}


This implementation eliminates the conditional logic in toString(), and eliminates any potential
confusion between an explicitly assigned integer value and the implicitly assigned ordinal
value (See Enum.ordinal()).

Perhaps you see some other justification for assigning an integer value to this enum?  Please
describe if so.

> JDOHelper.getObjectState() : convenience method to return the state of an object
> --------------------------------------------------------------------------------
>
>                 Key: JDO-528
>                 URL: https://issues.apache.org/jira/browse/JDO-528
>             Project: JDO
>          Issue Type: New Feature
>          Components: api2
>            Reporter: Andy Jefferson
>            Priority: Minor
>             Fix For: JDO 2 maintenance release 1
>
>         Attachments: JDOHelper.patch, ObjectState.patch
>
>
> As discussed on the jdo-dev mailing list cerca 5th August 2007, it would be desirable
for JDOHelper to have a method to return the object "state" of a passed object.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message