Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to create yaml hierachy using camel case, because u… #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
public enum ConfigMode {
DEFAULT,
PATH_BY_UNDERSCORE,
PATH_BY_CAMEL_CASE,
FIELD_IS_KEY
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ private void internalSave(Class clazz) throws InvalidConfigurationException {
case FIELD_IS_KEY:
path = field.getName();
break;
case PATH_BY_CAMEL_CASE:
path = getCamelCasePath(field.getName());
break;
case DEFAULT:
default:
String fieldName = field.getName();
Expand Down Expand Up @@ -214,4 +217,26 @@ public void load(File file) throws InvalidConfigurationException {
CONFIG_FILE = file;
load();
}

/**
* Converts the name of a field to a YAML Path, e.g. databaseUsername --> database.Username
* by GitGraf
* @param fieldName The name of the field that needs to be converted
* @return A dot seperated yaml path
*/
private String getCamelCasePath(String fieldName)
{
StringBuffer pathBuffer = new StringBuffer();
char[] fieldArray = fieldName.toCharArray();
for(int i = 0; i < fieldArray.length; i++) {

if(Character.isUpperCase(fieldArray[i])) {
pathBuffer.append(".");
}

pathBuffer.append(fieldArray[i]);

}
return pathBuffer.toString();
}
}