Last active
September 29, 2015 02:58
-
-
Save richashworth/1537048 to your computer and use it in GitHub Desktop.
Default Values Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.richashworth.testingutils.mocking; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class DefaultValues { | |
private Map<String, Object> defaultValuesMap; | |
public DefaultValues() { | |
this.defaultValuesMap = new HashMap<String, Object>(); | |
initMapWithPresets(); | |
} | |
public DefaultValues(Map<String, Object> defaultValuesMap) { | |
this.defaultValuesMap = defaultValuesMap; | |
initMapWithPresets(); | |
} | |
private void initMapWithPresets() { | |
if (defaultValuesMap == null) { | |
defaultValuesMap = new HashMap<String, Object>(); | |
} | |
for(PresetDefaultValue pdv : PresetDefaultValue.values()){ | |
defaultValuesMap.put(pdv.typeName, pdv.defaultValue); | |
} | |
} | |
public Map<String, Object> getDefaultValuesMap() { | |
return defaultValuesMap; | |
} | |
public void setDefaultValuesMap(Map<String, Object> defaultValuesMap) { | |
this.defaultValuesMap = defaultValuesMap; | |
} | |
private enum PresetDefaultValue { | |
DOUBLE(Double.class.getName(), 0.0), | |
STRING(String.class.getName(), ""), | |
FLOAT(Float.class.getName(), Float.MIN_VALUE), | |
LONG(Long.class.getName(), Long.MIN_VALUE), | |
SHORT(Short.class.getName(), Short.MIN_VALUE), | |
INTEGER(Integer.class.getName(), 0), | |
BOOLEAN(Boolean.class.getName(), false), | |
BYTE(Byte.class.getName(), Byte.MIN_VALUE), | |
CHARACTER(Character.class.getName(), ' '); | |
private String typeName; | |
private Object defaultValue; | |
private PresetDefaultValue(String typeName, Object defaultValue) { | |
this.typeName = typeName; | |
this.defaultValue = defaultValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment