Java Code Examples for org.osgl.util.C#Map

The following examples show how to use org.osgl.util.C#Map . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfLoader.java    From actframework with Apache License 2.0 6 votes vote down vote up
private Map loadConfFromDir_(File confDir) {
    File[] confFiles = confDir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".properties") || name.endsWith(".conf");
        }
    });
    if (null == confFiles) {
        return C.Map();
    } else {
        Map map = new HashMap<>();
        int n = confFiles.length;
        for (int i = 0; i < n; ++i) {
            map.putAll(loadConfFromFile(confFiles[i]));
        }
        return map;
    }
}
 
Example 2
Source File: Gh79.java    From java-tool with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    Map<String, Integer> foo1 = C.Map("id", N.randInt());
    Map<String, Integer> foo2 = C.Map("id", N.randInt());
    List<Map<String, Integer>> fooList = C.list(foo1, foo2);
    Map<String, List<Map<String, Integer>>> fooMap = C.Map("abc", fooList);
    Map<String, Map<String, List<Map<String, Integer>>>> bar = C.Map("fooMap", fooMap);
    List<Map<String, Map<String, List<Map<String, Integer>>>>> barList = C.list(bar);
    Map<String, List<Map<String, Map<String, List<Map<String, Integer>>>>>> barMap = C.Map("xyz", barList);
    Map<String, Map<String, List<Map<String, Map<String, List<Map<String, Integer>>>>>>> beanData = C.Map("barMap", barMap);
    Bean bean = new Bean();
    $.map(beanData).to(bean);
    List<Bar> theBarList = bean.barMap.get("xyz");
    requireNotNull(theBarList);
    eq(1, theBarList.size());
    Bar theBar = theBarList.get(0);
    requireNotNull(theBar);
    List<Foo> theFooList = theBar.fooMap.get("abc");
    eq(2, theFooList.size());
    Foo theFoo1 = theFooList.get(0);
    eq(foo1.get("id"), theFoo1.id);
    Foo theFoo2 = theFooList.get(1);
    eq(foo2.get("id"), theFoo2.id);
}
 
Example 3
Source File: YamlLoader.java    From actframework with Apache License 2.0 5 votes vote down vote up
public Map<String, Object> loadFixture(String fixtureName, DaoLocator daoLocator) {
    boolean isJson = fixtureName.endsWith(".json");
    boolean isYaml = !isJson && (fixtureName.endsWith(".yaml") || fixtureName.endsWith(".yml"));
    E.unsupportedIfNot(isJson || isYaml, "fixture resource file type not supported: " + fixtureName);
    String content = getResourceAsString(fixtureName);
    if (null == content) {
        return C.Map();
    }
    return isJson ? parseJson(content, daoLocator) : parse(content, daoLocator);
}
 
Example 4
Source File: OldMappingTest.java    From java-tool with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopyMapToBean() {
    Map<String, Object> map = C.Map("id", "123", "name", 10);
    Bar bar = new Bar();
    $.map(map).to(bar);
    eq(123, bar.id);
    eq("10", bar.name);
}
 
Example 5
Source File: Gh202.java    From java-tool with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    Bean bean = new Bean();
    Map<String, Object> innerMap = C.Map("count", 1);
    bean.map = C.Map("foo", "bar", "inner", innerMap);
    bean.name = S.random();

    Bean target = $.deepCopy(bean).filter("map").to(Bean.class);
    Map<String, Object> innerMap2 = $.cast(target.map.get("inner"));
    notNull(innerMap2);
    eq(1, innerMap2.get("count"));
}
 
Example 6
Source File: GHIssue353.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Test
public void testPut() throws Exception {
    url("/gh/353").accept(H.Format.JSON).postJSON(user);
    String s = resp().body().string();
    User user2 = JSON.parseObject(s, User.class);
    assertNotNull(user2._id());
    checkRespCode();
    reset();
    Map<String, String> updates = C.Map("name", "Donald Mickey");
    url("/gh/353/" + user2.getIdAsStr()).accept(H.Format.JSON).postJSON(updates).put();
    s = resp().body().string();
    User user3 = JSON.parseObject(s, User.class);
    eq(user2.getId(), user3.getId());
    eq("Donald Mickey", user3.name);
}
 
Example 7
Source File: HelloCli.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Command("foobar")
@JsonView
public Map fooBar(@Required(group = "foobar") Integer bar) {
    return C.Map("foo", foo, "color", color, "bar", bar);
}
 
Example 8
Source File: LongTypeMapValBindingTest.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Long> nonEmptyMap() {
    return C.Map("a", Long.MAX_VALUE, "b", Long.MIN_VALUE, "c", 0L);
}
 
Example 9
Source File: StringTypeMapValBindingTest.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, String> nonEmptyMap() {
    return C.Map("a", "Abc", "b", "aBc", "c", "abC");
}
 
Example 10
Source File: ClassInfoRepository.java    From actframework with Apache License 2.0 4 votes vote down vote up
public Map<String, ClassNode> classes() {
    return C.Map(classes);
}
 
Example 11
Source File: DoubleTypeMapValBindingTest.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Double> nonEmptyMap() {
    return C.Map("a", Double.MAX_VALUE, "b", Double.MIN_VALUE, "c", 0.02d);
}
 
Example 12
Source File: ByteTypeMapValBindingTest.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Byte> nonEmptyMap() {
    return C.Map("a", 0, "b", 1, "c", 2);
}
 
Example 13
Source File: GH232.java    From actframework with Apache License 2.0 4 votes vote down vote up
@GetAction("map/{s}")
@ResponseStatus(STATUS_CREATED)
public Object testMap(String s) {
    return C.Map("s", s);
}
 
Example 14
Source File: ControllerPlugin.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
protected Map<Class<? extends Annotation>, H.Method> annotationMethodLookup() {
    return C.Map();
}
 
Example 15
Source File: Gh1078_Base.java    From actframework with Apache License 2.0 4 votes vote down vote up
@After
public void after() {
    throw new RenderJSON(C.Map("result", "intercepted"));
}
 
Example 16
Source File: Gh1253.java    From actframework with Apache License 2.0 4 votes vote down vote up
@GetAction
public C.Map<String, String> get() {
    return mapping;
}
 
Example 17
Source File: FloatTypeMapValBindingTest.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Float> nonEmptyMap() {
    return C.Map("a", Float.MAX_VALUE, "b", Float.MIN_VALUE, "c", 0.02f);
}
 
Example 18
Source File: ExtendedAppConfLoader.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Object> loadConfigurations() {
    return C.Map();
}
 
Example 19
Source File: Gh841.java    From actframework with Apache License 2.0 4 votes vote down vote up
@GetAction
public Map<String, String> test(boolean fail) {
    Controller.Util.unauthorizedIf(fail);
    return C.Map("token", "aaa");
}
 
Example 20
Source File: GHIssue301.java    From actframework with Apache License 2.0 4 votes vote down vote up
private void create(String name, int age) throws Exception {
    reset();
    Map<String, Object> payload = C.Map("name", name, "age", age);
    url("/gh/301").postJSON(payload);
    checkRespCode();
}