Johannes Lichtenberger
2010-12-04 00:55:36 UTC
Hallo,
ich habe folgenes enum:
/** XPath enum to determine if current item is found by an XPath
expression or not. */
enum XPathState {
/** Item is found. */
ISFOUND(StateType.ISFOUND),
/** Default: Item is not found. */
ISNOTFOUND(StateType.ISNOTFOUND);
/** {@link StateType}. */
private final StateType mStateType;
/**
* Constructor.
*
* @param paramType
* private {@link StateType}
*/
XPathState(final StateType paramType) {
mStateType = paramType;
}
/**
* Set stroke.
*
* @param paramApplet
* Processing {@link PApplet} core.
* @param paramColor
* The color to use.
*/
void setStroke(final PApplet paramApplet, final float paramColor) {
mStateType.setStroke(paramApplet, paramColor);
}
/** Determines state of XPath expression evaluation. */
private enum StateType {
/** Item is found. */
ISFOUND {
@Override
void setStroke(final PApplet paramApplet, final float
paramColor) {
paramApplet.stroke(1f);
}
},
/** Default: Item is not found. */
ISNOTFOUND {
@Override
void setStroke(final PApplet paramApplet, final float
paramColor) {
paramApplet.stroke(paramColor);
}
};
/**
* Set stroke.
*
* @param paramApplet
* Processing {@link PApplet} core.
* @param paramColor
* The color to use.
*/
abstract void setStroke(final PApplet paramApplet, final
float paramColor);
}
}
und eine XPathState Instanz:
/** State which determines if current item is found by an XPath
expression or not. */
private transient XPathState mXPathState = XPathState.ISNOTFOUND;
Was ist denn der großartige Unterschied zwischen:
switch (mXPathState) {
case ISFOUND:
mParent.stroke(1f);
break;
case ISNOTFOUND:
mParent.stroke(mCol);
break;
default:
throw new AssertionError("XPathState not known!");
}
Das war bevor ich das "strategy enum pattern" verwendet habe, also als
es noch einfach enum XPathState { ISFOUND, ISNOTFOUND }; war und das danach:
mXPathState.setStroke(mParent, mCol);
Ersteres klappt, d.h. die richtige Farbe wird für das Zeichnen genommen,
letzteres nimmt immer 1f, also schwarz, egal ob es nun ISFOUND oder
ISNOTFOUND nach einer Änderung mittles
/**
* Set XPath state.
*
* @param paramState
* set state to this value
*/
void setXPathState(final XPathState paramState) {
mXPathState = paramState;
}
ist. Ich nehme an ein simpler Fehler bzw. geistige Umnachtung, vll.
fällt es mir morgen auch selbst auf oder ich muss den Debugger wieder
bemühen...
Viele Grüße,
Johannes
ich habe folgenes enum:
/** XPath enum to determine if current item is found by an XPath
expression or not. */
enum XPathState {
/** Item is found. */
ISFOUND(StateType.ISFOUND),
/** Default: Item is not found. */
ISNOTFOUND(StateType.ISNOTFOUND);
/** {@link StateType}. */
private final StateType mStateType;
/**
* Constructor.
*
* @param paramType
* private {@link StateType}
*/
XPathState(final StateType paramType) {
mStateType = paramType;
}
/**
* Set stroke.
*
* @param paramApplet
* Processing {@link PApplet} core.
* @param paramColor
* The color to use.
*/
void setStroke(final PApplet paramApplet, final float paramColor) {
mStateType.setStroke(paramApplet, paramColor);
}
/** Determines state of XPath expression evaluation. */
private enum StateType {
/** Item is found. */
ISFOUND {
@Override
void setStroke(final PApplet paramApplet, final float
paramColor) {
paramApplet.stroke(1f);
}
},
/** Default: Item is not found. */
ISNOTFOUND {
@Override
void setStroke(final PApplet paramApplet, final float
paramColor) {
paramApplet.stroke(paramColor);
}
};
/**
* Set stroke.
*
* @param paramApplet
* Processing {@link PApplet} core.
* @param paramColor
* The color to use.
*/
abstract void setStroke(final PApplet paramApplet, final
float paramColor);
}
}
und eine XPathState Instanz:
/** State which determines if current item is found by an XPath
expression or not. */
private transient XPathState mXPathState = XPathState.ISNOTFOUND;
Was ist denn der großartige Unterschied zwischen:
switch (mXPathState) {
case ISFOUND:
mParent.stroke(1f);
break;
case ISNOTFOUND:
mParent.stroke(mCol);
break;
default:
throw new AssertionError("XPathState not known!");
}
Das war bevor ich das "strategy enum pattern" verwendet habe, also als
es noch einfach enum XPathState { ISFOUND, ISNOTFOUND }; war und das danach:
mXPathState.setStroke(mParent, mCol);
Ersteres klappt, d.h. die richtige Farbe wird für das Zeichnen genommen,
letzteres nimmt immer 1f, also schwarz, egal ob es nun ISFOUND oder
ISNOTFOUND nach einer Änderung mittles
/**
* Set XPath state.
*
* @param paramState
* set state to this value
*/
void setXPathState(final XPathState paramState) {
mXPathState = paramState;
}
ist. Ich nehme an ein simpler Fehler bzw. geistige Umnachtung, vll.
fällt es mir morgen auch selbst auf oder ich muss den Debugger wieder
bemühen...
Viele Grüße,
Johannes