Search in sources :

Example 6 with Dict

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);
}
Also used : Dict(cn.hutool.core.lang.Dict) Props(org.febit.wit.util.Props) File(java.io.File)

Example 7 with 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));
}
Also used : Dict(cn.hutool.core.lang.Dict) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Dict

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);
    }
}
Also used : Dict(cn.hutool.core.lang.Dict)

Example 9 with Dict

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));
}
Also used : Dict(cn.hutool.core.lang.Dict) Test(org.junit.Test)

Example 10 with Dict

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);
}
Also used : Dict(cn.hutool.core.lang.Dict) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

Dict (cn.hutool.core.lang.Dict)33 Test (org.junit.Test)25 File (java.io.File)4 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 ArrayList (java.util.ArrayList)3 BaseTest (cn.e3mall.common.freemarker.BaseTest)2 JexlEngine (cn.hutool.extra.expression.engine.jexl.JexlEngine)2 JfireELEngine (cn.hutool.extra.expression.engine.jfireel.JfireELEngine)2 MvelEngine (cn.hutool.extra.expression.engine.mvel.MvelEngine)2 RhinoEngine (cn.hutool.extra.expression.engine.rhino.RhinoEngine)2 SpELEngine (cn.hutool.extra.expression.engine.spel.SpELEngine)2 Configuration (freemarker.template.Configuration)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringWriter (java.io.StringWriter)2 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2 Props (org.febit.wit.util.Props)2 Item (cn.e3mall.common.base.entity.Item)1