use of cn.hutool.core.lang.Dict in project hutool by looly.
the class WitEngine method createEngine.
/**
* 创建引擎
*
* @param config 模板配置
* @return {@link Engine}
*/
private static Engine createEngine(TemplateConfig config) {
final Props configProps = Engine.createConfigProps("");
Dict dict = null;
if (null != config) {
dict = Dict.create();
// 自定义编码
dict.set("DEFAULT_ENCODING", config.getCharset());
switch(config.getResourceMode()) {
case CLASSPATH:
configProps.set("pathLoader.root", config.getPath());
configProps.set("routeLoader.defaultLoader", "classpathLoader");
break;
case STRING:
configProps.set("routeLoader.defaultLoader", "stringLoader");
break;
case FILE:
configProps.set("pathLoader.root", config.getPath());
configProps.set("routeLoader.defaultLoader", "fileLoader");
break;
case WEB_ROOT:
final File root = FileUtil.file(FileUtil.getWebRoot(), config.getPath());
configProps.set("pathLoader.root", FileUtil.getAbsolutePath(root));
configProps.set("routeLoader.defaultLoader", "fileLoader");
break;
}
}
return Engine.create(configProps, dict);
}
use of cn.hutool.core.lang.Dict in project hutool by looly.
the class YamlUtilTest method dumpTest.
@Test
@Ignore
public void dumpTest() {
final Dict dict = Dict.create().set("name", "hutool").set("count", 1000);
YamlUtil.dump(dict, FileUtil.getWriter("d:/test/dump.yaml", CharsetUtil.CHARSET_UTF_8, false));
}
use of cn.hutool.core.lang.Dict in project hutool by looly.
the class ConsoleLog method log.
// ------------------------------------------------------------------------- Log
@Override
public void log(String fqcn, Level level, Throwable t, String format, Object... arguments) {
// fqcn 无效
if (false == isEnabled(level)) {
return;
}
final Dict dict = Dict.create().set("date", DateUtil.now()).set("level", level.toString()).set("name", this.name).set("msg", StrUtil.format(format, arguments));
final String logMsg = StrUtil.format(logFormat, dict);
// WARN以上级别打印至System.err
if (level.ordinal() >= Level.WARN.ordinal()) {
Console.error(t, logMsg);
} else {
Console.log(t, logMsg);
}
}
use of cn.hutool.core.lang.Dict in project hutool by looly.
the class CollUtilTest method getFieldValuesTest.
@Test
public void getFieldValuesTest() {
Dict v1 = Dict.create().set("id", 12).set("name", "张三").set("age", 23);
Dict v2 = Dict.create().set("age", 13).set("id", 15).set("name", "李四");
ArrayList<Dict> list = CollUtil.newArrayList(v1, v2);
List<Object> fieldValues = CollUtil.getFieldValues(list, "name");
Assert.assertEquals("张三", fieldValues.get(0));
Assert.assertEquals("李四", fieldValues.get(1));
}
use of cn.hutool.core.lang.Dict in project dynamic-threadpool by acmenlt.
the class DashboardServiceImpl method getTenantChart.
@Override
public TenantChart getTenantChart() {
List<Map<String, Object>> tenantChartList = Lists.newArrayList();
List<TenantInfo> tenantInfos = tenantInfoMapper.selectList(Wrappers.lambdaQuery(TenantInfo.class).eq(TenantInfo::getDelFlag, DelEnum.NORMAL));
for (TenantInfo tenant : tenantInfos) {
int tenantThreadPoolNum = 0;
LambdaQueryWrapper<ItemInfo> itemQueryWrapper = Wrappers.lambdaQuery(ItemInfo.class).eq(ItemInfo::getTenantId, tenant.getTenantId()).eq(ItemInfo::getDelFlag, DelEnum.NORMAL).select(ItemInfo::getItemId);
List<ItemInfo> itemInfos = itemInfoMapper.selectList(itemQueryWrapper);
for (ItemInfo item : itemInfos) {
LambdaQueryWrapper<ConfigAllInfo> threadPoolQueryWrapper = Wrappers.lambdaQuery(ConfigAllInfo.class).eq(ConfigInfoBase::getItemId, item.getItemId()).eq(ConfigAllInfo::getDelFlag, DelEnum.NORMAL);
Integer threadPoolCount = configInfoMapper.selectCount(threadPoolQueryWrapper);
tenantThreadPoolNum += threadPoolCount;
}
Dict dict = Dict.create().set("name", tenant.getTenantId()).set("value", tenantThreadPoolNum);
tenantChartList.add(dict);
}
List resultTenantChartList = tenantChartList.stream().sorted((one, two) -> (int) two.get("value") - (int) one.get("value")).limit(5).collect(Collectors.toList());
return new TenantChart(resultTenantChartList);
}
Aggregations