Skip to content

Commit

Permalink
Added methods to ExperimentManager returning default values over thro…
Browse files Browse the repository at this point in the history
…wing Exceptions.
  • Loading branch information
Nicolas Gramlich committed Mar 23, 2013
1 parent 4f88ee7 commit 2b1e862
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 4 deletions.
98 changes: 98 additions & 0 deletions src/org/andengine/util/experiment/ExperimentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.andengine.util.StreamUtils;
import org.andengine.util.call.Callback;
import org.andengine.util.debug.Debug;
import org.andengine.util.experiment.exception.ExperimentException;
import org.andengine.util.experiment.exception.ExperimentNotFoundException;
import org.andengine.util.experiment.exception.ExperimentTypeException;
import org.andengine.util.system.SystemUtils;
Expand Down Expand Up @@ -105,51 +106,148 @@ public boolean getExperimentBooleanValue(final String pExperimentName) throws Ex
return this.getExperimentValue(pExperimentName, Boolean.class);
}

public boolean getExperimentBooleanValue(final String pExperimentName, final boolean pDefaultValue) {
try {
return this.getExperimentBooleanValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

public byte getExperimentByteValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, Byte.class);
}

public byte getExperimentByteValue(final String pExperimentName, final byte pDefaultValue) {
try {
return this.getExperimentByteValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

public short getExperimentShortValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, Short.class);
}

public short getExperimentShortValue(final String pExperimentName, final short pDefaultValue) {
try {
return this.getExperimentShortValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

public char getExperimentCharacterValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, Character.class);
}

public char getExperimentCharacterValue(final String pExperimentName, final char pDefaultValue) {
try {
return this.getExperimentCharacterValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

public int getExperimentIntegerValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, Integer.class);
}

public int getExperimentIntegerValue(final String pExperimentName, final int pDefaultValue) {
try {
return this.getExperimentIntegerValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

public long getExperimentLongValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, Long.class);
}

public long getExperimentLongValue(final String pExperimentName, final long pDefaultValue) {
try {
return this.getExperimentLongValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

public float getExperimentFloatValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, Float.class);
}

public float getExperimentFloatValue(final String pExperimentName, final float pDefaultValue) {
try {
return this.getExperimentFloatValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

public double getExperimentDoubleValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, Double.class);
}

public double getExperimentDoubleValue(final String pExperimentName, final double pDefaultValue) {
try {
return this.getExperimentDoubleValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

public String getExperimentStringValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, String.class);
}

public String getExperimentStringValue(final String pExperimentName, final String pDefaultValue) {
try {
return this.getExperimentStringValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

public JSONObject getExperimentJSONObjectValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, JSONObject.class);
}

public JSONObject getExperimentJSONObjectValue(final String pExperimentName, final JSONObject pDefaultValue) {
try {
return this.getExperimentJSONObjectValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

public JSONArray getExperimentJSONArrayValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, JSONArray.class);
}

public JSONArray getExperimentJSONArrayValue(final String pExperimentName, final JSONArray pDefaultValue) {
try {
return this.getExperimentJSONArrayValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

@Deprecated
public Object getExperimentValue(final String pExperimentName) throws ExperimentTypeException, ExperimentNotFoundException {
return this.getExperimentValue(pExperimentName, Object.class);
}

@Deprecated
public Object getExperimentValue(final String pExperimentName, final Object pDefaultValue) {
try {
return this.getExperimentValue(pExperimentName);
} catch (final ExperimentException e) {
return pDefaultValue;
}
}

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.andengine.util.experiment.exception;

import org.andengine.util.exception.AndEngineException;

/**
* (c) 2013 Nicolas Gramlich
*
* @author Nicolas Gramlich
* @since 00:45:14 - 23.03.2013
*/
public class ExperimentException extends AndEngineException {
// ===========================================================
// Constants
// ===========================================================

private static final long serialVersionUID = 8028018956559796977L;

// ===========================================================
// Fields
// ===========================================================

// ===========================================================
// Constructors
// ===========================================================

public ExperimentException() {
super();
}

public ExperimentException(final String pMessage) {
super(pMessage);
}

public ExperimentException(final Throwable pThrowable) {
super(pThrowable);
}

public ExperimentException(final String pMessage, final Throwable pThrowable) {
super(pMessage, pThrowable);
}

// ===========================================================
// Getter & Setter
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

// ===========================================================
// Methods
// ===========================================================

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.andengine.util.experiment.exception;

import org.andengine.util.exception.AndEngineException;

/**
* (c) 2013 Nicolas Gramlich
*
* @author Nicolas Gramlich
* @since 08:25:34 - 22.03.2013
*/
public class ExperimentNotFoundException extends AndEngineException {
public class ExperimentNotFoundException extends ExperimentException {
// ===========================================================
// Constants
// ===========================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.andengine.util.experiment.exception;

import org.andengine.util.exception.AndEngineException;

/**
* (c) 2013 Nicolas Gramlich
*
* @author Nicolas Gramlich
* @since 08:25:34 - 22.03.2013
*/
public class ExperimentTypeException extends AndEngineException {
public class ExperimentTypeException extends ExperimentException {
// ===========================================================
// Constants
// ===========================================================
Expand Down

0 comments on commit 2b1e862

Please sign in to comment.