org.nuiton.eugene.java.extension.ConstantsManager Maven / Gradle / Ivy
/*
* #%L
* EUGene :: EUGene
*
* $Id: ConstantsManager.java 1079 2011-06-28 09:15:23Z tchemit $
* $HeadURL: https://nuiton.org/svn/eugene/tags/eugene-2.7.4/eugene/src/main/java/org/nuiton/eugene/java/extension/ConstantsManager.java $
* %%
* Copyright (C) 2004 - 2010 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package org.nuiton.eugene.java.extension;
import org.nuiton.eugene.GeneratorUtil;
import java.util.Map;
import java.util.TreeMap;
/**
* Manager of constant names.
*
* @author tchemit
* @since ?
*/
public class ConstantsManager {
/**
* cache of constant name (values) for property name (keys)
*/
protected Map nameToConstant;
/**
* Obtain a constant nmae from a property name and store it in cache
* the first time it had to build it.
*
* @param propertyName the propertyName to convert
* @return the equivalent constant name
*/
public String getConstantName(String propertyName) {
Map map = getNameToConstant();
if (map.containsKey(propertyName)) {
return map.get(propertyName);
}
// convert propertyName to constant name
String constantName =
GeneratorUtil.convertVariableNameToConstantName(propertyName);
map.put(propertyName,constantName);
return constantName;
}
protected Map getNameToConstant() {
if (nameToConstant == null) {
nameToConstant = new TreeMap();
}
return nameToConstant;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy