nkpart (owner)

Revisions

gist: 230619 Download_button fork
public
Public Clone URL: git://gist.github.com/230619.git
Embed All Files: show embed
Java #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    private static F<JSONObject, Option<JSONObject>> obj(final String param) {
        return x(param, JSONObject.class);
    }
 
    private static F<JSONObject, Option<String>> str(final String param) {
        return x(param, String.class);
    }
 
 
    private static F<JSONObject, Option<JSONArray>> arr(final String param) {
        return x(param, JSONArray.class);
    }
 
 
    private static <T> F<JSONObject, Option<T>> x(final String param, final Class<T> cls) {
        return new F<JSONObject, Option<T>>() {
            public Option<T> f(final JSONObject jsonObject) {
                final Object o = jsonObject.get(param);
                if (o != null && cls.isAssignableFrom(o.getClass())) {
                    return Option.some((T) o);
                } else {
                    return Option.none();
                }
            }
        };
    }