本文整理汇总了Java中org.trimou.util.ImmutableMap.of方法的典型用法代码示例。如果您正苦于以下问题:Java ImmutableMap.of方法的具体用法?Java ImmutableMap.of怎么用?Java ImmutableMap.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.trimou.util.ImmutableMap
的用法示例。
在下文中一共展示了ImmutableMap.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateArrayProperty
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
/**
* @param type
* @param property
*/
private void generateArrayProperty(ArrayTypeDeclaration property) {
String fieldName = Names.buildVariableName(property);
String itemTypeName = context.getApiModel().getItemType(property);
String typeVar = Annotations.findTypeVar(property);
String tsItemType;
if (typeVar != null) {
tsItemType = typeVar;
}
else {
tsItemType = itemTypeName;
}
MustacheEngine engine = context.getTemplateEngine().getEngine();
Map<String, String> contextObject = ImmutableMap.of("name", fieldName, "tsPropType",
tsItemType + "[]");
engine.getMustache("property").render(context.getOutput(), contextObject);
}
示例2: generateProperty
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
/**
* @param type
* @param property
*/
private void generateProperty(TypeDeclaration property) {
String fieldName = Names.buildVariableName(property);
String tsPropType;
String typeVar = Annotations.findTypeVar(property);
if (typeVar != null) {
tsPropType = typeVar;
}
else {
tsPropType = propertyTypeWithArgs(property);
}
MustacheEngine engine = context.getTemplateEngine().getEngine();
Map<String, String> contextObject = ImmutableMap.of("name", fieldName, "tsPropType",
tsPropType);
engine.getMustache("property").render(context.getOutput(), contextObject);
}
示例3: testHelper
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
@Test
public void testHelper() {
final MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.registerHelpers(HelpersBuilder.empty().addEval().build())
.build();
String[] array = { "alpha", "bravo", "charlie" };
List<String> list = ImmutableList.of("foo", "bar", "baz");
Map<String, Object> data = ImmutableMap
.of("array", array, "list", list);
assertEquals(
"foo:alpha,bar:bravo,baz:charlie",
engine.compileMustache(
"eval_helper1",
"{{#each list}}{{this}}:{{eval 'array' iter.position}}{{#if iter.hasNext}},{{/if}}{{/each}}")
.render(data));
}
示例4: testMultipleInheritance
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
@Test
public void testMultipleInheritance() {
MapTemplateLocator locator = new MapTemplateLocator(
ImmutableMap
.of("super",
"for {{$insert}}{{/insert}}",
"sub",
"And now {{<super}} {{$insert}}something {{$insert2}}{{/insert2}} different{{/insert}} {{/super}}.",
"subsub",
"{{<sub}} {{$insert2}}completely{{/insert2}} {{/sub}}"));
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.addTemplateLocator(locator).build();
Mustache sub = engine.getMustache("subsub");
assertEquals("And now for something completely different.",
sub.render(null));
}
示例5: testRecursiveInvocationLimitExceeded
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
@Test
public void testRecursiveInvocationLimitExceeded() {
MapTemplateLocator locator = new MapTemplateLocator(ImmutableMap.of(
"super", "/n{{<super}}{{/super}}"));
MustacheEngine engine = MustacheEngineBuilder
.newBuilder()
.addTemplateLocator(locator)
.setProperty(
EngineConfigurationKey.TEMPLATE_RECURSIVE_INVOCATION_LIMIT,
5).build();
try {
engine.getMustache("super").render(null);
fail("Limit exceeded and no exception thrown");
} catch (MustacheException e) {
if (!e.getCode()
.equals(MustacheProblem.RENDER_TEMPLATE_INVOCATION_RECURSIVE_LIMIT_EXCEEDED)) {
fail("Invalid problem");
}
System.out.println(e.getMessage());
// else {
// e.printStackTrace();
// }
}
}
示例6: buildEngine
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
@Before
public void buildEngine() {
textParam = null;
MapTemplateLocator locator = new MapTemplateLocator(ImmutableMap.of(
"partial", "{{! No content}}", "super",
"{{$extendMe}}Hello{{/extendMe}}"));
engine = MustacheEngineBuilder
.newBuilder()
.addGlobalData("foo", foo)
.addTemplateLocator(locator)
.setProperty(
EngineConfigurationKey.REMOVE_UNNECESSARY_SEGMENTS,
false).build();
}
示例7: testInterpolation
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
@Test
public void testInterpolation() {
int[] array = new int[] { 1, 2 };
Map<String, Object> data = ImmutableMap.of("hammer",
new Hammer(), "type", ArchiveType.class, "array", array);
assertEquals("Hello Edgar of age 10, persistent: false and !",
engine.compileMustache("reflection_resolver",
"Hello {{hammer.name}} of age {{hammer.age}}, persistent: {{hammer.persistent}} and {{hammer.invalidName}}!")
.render(data));
assertEquals(
"NAIL|jar", engine
.compileMustache("reflection_resolver_fields",
"{{hammer.nail}}|{{type.JAR.suffix}}")
.render(data));
assertEquals("jar,war,ear,",
engine.compileMustache("reflection_resolver_static_method",
"{{#type.values}}{{this.suffix}},{{/type.values}}")
.render(data));
assertEquals("" + array.length,
engine.compileMustache("reflection_resolver_array",
"{{array.length}}").render(data));
}
示例8: addTypeToImports
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
private Map<String, String> addTypeToImports(String typeName) {
String tsType = typeName;
while (tsType.endsWith("[]")) {
tsType = tsType.substring(0, tsType.length() - 2);
}
if (!Metatype.isBuiltIn(tsType)) {
String tsFile = Names.buildLowerKebabCaseName(tsType);
return ImmutableMap.of(tsType, tsFile);
}
return Collections.emptyMap();
}
示例9: visitStringType
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
@Override
public void visitStringType(StringTypeDeclaration type) {
String name = type.name();
List<EnumSymbol> enumValues = context.getApiModel().getEnumValues(type).stream()
.map(v -> new EnumSymbol(Names.buildConstantName(v.getName()), v.getName()))
.collect(toList());
Map<String, Object> contextObject = ImmutableMap.of("name", name, "enumValues", enumValues);
MustacheEngine engine = context.getTemplateEngine().getEngine();
engine.getMustache("enum").render(output, contextObject);
String moduleName = Names.buildLowerKebabCaseName(type.name());
writeToFile(output.toString(), moduleName);
}
示例10: startOutput
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
/**
* Starts a new output and generates a header comment.
*
* @return output
*/
public StringBuilder startOutput() {
StringBuilder builder = new StringBuilder();
this.output = builder;
Map<String, String> contextObject = ImmutableMap.of("version", Version.getRamlerVersion(),
"date", ZonedDateTime.now().truncatedTo(SECONDS).format(ISO_OFFSET_DATE_TIME));
getTemplateEngine().getEngine().getMustache("generated").render(output, contextObject);
return builder;
}
示例11: visitObjectTypeStart
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
@Override
public void visitObjectTypeStart(ObjectTypeDeclaration type) {
List<String> baseClasses = type.parentTypes().stream()
.filter(t -> !t.name().equals(Constants.OBJECT)).map(t -> this.typeWithArgs(type, t))
.collect(toList());
List<String> typeVars = Annotations.getStringAnnotations(type, TYPE_VARS);
Map<String, Object> contextObject = ImmutableMap.of("name", type.name(), "baseClasses",
baseClasses, "typeVars", typeVars);
MustacheEngine engine = context.getTemplateEngine().getEngine();
engine.getMustache("objectStart").render(context.getOutput(), contextObject);
}
示例12: builder
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
private Map<String, Object> builder(int n) {
return ImmutableMap.of(
"arity", n,
"arityPlus", n + 1,
"nextArg", letters(n + 1).skip(n).findFirst().get(),
"typeArgs", typeArgs(n),
"typeArgsMinus", typeArgs(n - 1)
);
}
示例13: fn
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
private Map<String, Object> fn(int n) {
return ImmutableMap.of(
"arity", n,
"typeArgs", typeArgs(n),
"jdkInterface", jdkInterface(n),
"parameters", parameters(n)
);
}
示例14: testInterpolation
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
@Test
public void testInterpolation() {
Calendar day = Calendar.getInstance();
day.set(Calendar.YEAR, 2013);
day.set(Calendar.MONTH, 0);
day.set(Calendar.DAY_OF_MONTH, 1);
day.set(Calendar.HOUR_OF_DAY, 13);
day.set(Calendar.MINUTE, 0);
day.set(Calendar.SECOND, 0);
day.set(Calendar.MILLISECOND, 0);
long milis = day.getTimeInMillis();
String expectedShort = "1/1/13 1:00 PM";
String expectedMedium = "Jan 1, 2013 1:00:00 PM";
String expectedCustom = "01-01-2013 13:00";
String expectedDate = "Jan 1, 2013";
Map<String, Object> data = ImmutableMap.of("calendar", day, "date", day.getTime(), "milis", milis);
assertEquals(Strings.repeat(expectedMedium, 3, "|"),
engine.compileMustache("date_time_medium",
"{{calendar.format}}|{{date.format}}|{{milis.format}}")
.render(data));
assertEquals(Strings.repeat(expectedShort, 3, "|"),
engine.compileMustache("date_time_short",
"{{calendar.formatShort}}|{{date.formatShort}}|{{milis.formatShort}}")
.render(data));
assertEquals(Strings.repeat(expectedCustom, 3, "|"),
engine.compileMustache("date_time_custom",
"{{calendar.formatCustom}}|{{date.formatCustom}}|{{milis.formatCustom}}")
.render(data));
assertEquals(Strings.repeat(expectedDate, 3, "|"),
engine.compileMustache("date_only",
"{{calendar.formatDate}}|{{date.formatDate}}|{{milis.formatDate}}")
.render(data));
}
示例15: testHelper
import org.trimou.util.ImmutableMap; //导入方法依赖的package包/类
@Test
public void testHelper() {
final MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.registerHelpers(HelpersBuilder.empty().addInvoke().build())
.build();
List<String> list = ImmutableList.of("foo", "bar", "baz");
Map<String, Object> data = ImmutableMap.of("string", "foo", "list",
list);
assertEquals("oo", engine
.compileMustache("invoke_01", "{{invoke 1 m='substring'}}")
.render("foo"));
assertEquals("bar",
engine.compileMustache("invoke_02", "{{invoke 1 m='get'}}")
.render(list));
assertEquals("FOOBARBAZ",
engine.compileMustache("invoke_03",
"{{#invoke 'list' m='get'}}{{#each this}}{{toUpperCase}}{{/each}}{{/invoke}}")
.render(data));
assertEquals("3", engine
.compileMustache("invoke_04", "{{invoke on=list m='size'}}")
.render(data));
assertEquals(
"false", engine
.compileMustache("invoke_05",
"{{invoke on=list method='isEmpty'}}")
.render(data));
assertEquals("boo",
engine.compileMustache("invoke_06",
"{{invoke 'f' 'b' on='foo' m='replace'}}")
.render(null));
assertEquals("2",
engine.compileMustache("invoke_07",
"{{#invoke ':' on='foo:bar' m='split'}}{{this.length}}{{/invoke}}")
.render(null));
}