Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCT...
If you think the Android project NexusData listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.github.dkharrat.nexusdata.modelgen.metamodel;
//fromwww.java2s.comimport com.google.gson.annotations.SerializedName;
import java.util.HashMap;
import java.util.Map;
publicclass Attribute extends Property {
privatestaticfinal Map<String,String> typeToJavaType = new HashMap<>();
static
{
typeToJavaType.put("String", "String");
typeToJavaType.put("Int", "Integer");
typeToJavaType.put("Long", "Long");
typeToJavaType.put("Bool", "Boolean");
typeToJavaType.put("Date", "Date");
typeToJavaType.put("Float", "Float");
typeToJavaType.put("Double", "Double");
}
privatestaticfinal Map<String,String> typeToPrimType = new HashMap<>();
static
{
typeToPrimType.put("String", "String");
typeToPrimType.put("Int", "int");
typeToPrimType.put("Long", "long");
typeToPrimType.put("Bool", "boolean");
typeToPrimType.put("Date", "Date");
typeToPrimType.put("Float", "float");
typeToPrimType.put("Double", "double");
}
private Entity entity;
private String type;
@SerializedName("default") private String defaultValue;
// use to set parent entity when object is de-serialized
publicvoid setEntity(Entity entity) {
this.entity = entity;
}
@Override
public String getJavaType() {
return getJavaType(true);
}
public String getJavaTypeForParam() {
return getJavaType(!required);
}
private String getJavaType(boolean useObjectType) {
String javaType = useObjectType ? typeToJavaType.get(type): typeToPrimType.get(type);
if (javaType == null) {
if (isEnumProperty(type)) {
javaType = type;
}
}
if (javaType == null) {
thrownew RuntimeException("Unknown type '" + type + "' for attribute '" + name + "'");
}
return javaType;
}
privateboolean isEnumProperty(String name) {
for (EnumProperty enumProp : entity.getEnums()) {
if (enumProp.getName().equals(name)) {
return true;
}
}
return false;
}
public String getMethodNameForGetter() {
if (type.equals("Bool")) {
if (name.substring(0, 2).equalsIgnoreCase("is")) {
return name;
} else {
return"is" + getCapitalizedName();
}
} else {
return super.getMethodNameForGetter();
}
}
}