-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate ParamValue and ParamValueList
new data template engine templates remains old
- Loading branch information
Showing
18 changed files
with
148 additions
and
75 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package greed.model; | ||
|
||
/** | ||
* Greed is good! Cheers! | ||
*/ | ||
public class ParamValueList extends ParamValue { | ||
|
||
private ParamValue[] values; | ||
private String[] valueStrings; | ||
|
||
public ParamValueList(Param param, String[] valueList) { | ||
super(param, joinValues(valueList)); | ||
assert param.getType().isArray(); | ||
|
||
this.valueStrings = valueList; | ||
this.values = new ParamValue[valueList.length]; | ||
Type elemType = new Type(param.getType().getPrimitive(), param.getType().getDim() - 1); | ||
Param elemParam = new Param(param.getName(), elemType, param.getIndex()); | ||
for (int i = 0; i < values.length; ++i) { | ||
this.values[i] = new ParamValue(elemParam, valueList[i]); | ||
} | ||
} | ||
|
||
private static String joinValues(String[] valueList) { | ||
StringBuilder buf = new StringBuilder(); | ||
buf.append("{ "); | ||
String sep = ""; | ||
for (String s : valueList) { | ||
buf.append(sep); | ||
sep = ", "; | ||
buf.append(s); | ||
} | ||
buf.append(" }"); | ||
return buf.toString(); | ||
} | ||
|
||
public ParamValue[] getValueList() { | ||
return values; | ||
} | ||
|
||
@Override | ||
public String[] getStrings() { | ||
return valueStrings; | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package greed.template; | ||
|
||
import com.floreysoft.jmte.Renderer; | ||
import greed.code.LanguageManager; | ||
import greed.model.Language; | ||
import greed.model.ParamValue; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Greed is good! Cheers! | ||
*/ | ||
public class TemplateEngineFactory { | ||
private static TemplateEngine bare = new TemplateEngine(); | ||
|
||
public static TemplateEngine getBareEngine() { | ||
return bare; | ||
} | ||
|
||
public static TemplateEngine newLanguageEngine(Language language) { | ||
TemplateEngine engine = new TemplateEngine(); | ||
LanguageManager.getInstance().registerRenderer(language, engine.getEngine()); | ||
return engine; | ||
} | ||
|
||
public static TemplateEngine newDataEngine() { | ||
TemplateEngine engine = new TemplateEngine(); | ||
engine.getEngine().registerRenderer(ParamValue.class, new Renderer<ParamValue>() { | ||
@Override | ||
public String render(ParamValue paramValue, Locale locale) { | ||
return paramValue.getValue(); | ||
} | ||
}); | ||
return engine; | ||
} | ||
|
||
public static TemplateEngine newSpecialEngine(String name) { | ||
if ("data".equals(name)) | ||
return newDataEngine(); | ||
throw new IllegalArgumentException("No engine named " + name); | ||
} | ||
} |
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
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
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
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
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
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
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
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
Oops, something went wrong.
what are theses for?OK, I got it.