1 | static <A> A optParam(ThreadLocal<A> tl, A defaultValue) { |
2 | ret optPar(tl, defaultValue); |
3 | } |
4 | |
5 | static <A> A optParam(ThreadLocal<A> tl) { |
6 | ret optPar(tl); |
7 | } |
8 | |
9 | static O mapMethodLike optParam(S name, Map params) { |
10 | ret mapGet(params, name); |
11 | } |
12 | |
13 | // now also takes a map as single array entry |
14 | static <A> A optParam(O[] opt, S name, A defaultValue) { |
15 | int n = l(opt); |
16 | if (n == 1 && opt[0] instanceof Map) { |
17 | Map map = cast opt[0]; |
18 | ret map.containsKey(name) ? (A) map.get(name) : defaultValue; |
19 | } |
20 | if (!even(l(opt))) fail("Odd parameter length"); |
21 | for (int i = 0; i < l(opt); i += 2) |
22 | if (eq(opt[i], name)) |
23 | ret (A) opt[i+1]; |
24 | ret defaultValue; |
25 | } |
26 | |
27 | sO optParam(O[] opt, S name) { |
28 | ret optParam(opt, name, null); |
29 | } |
30 | |
31 | sO mapMethodLike optParam(S name, O[] params) { |
32 | ret optParam(params, name); |
33 | } |
Began life as a copy of #1006679
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1007397 |
Snippet name: | optParam - synonym of optPar - get optional parameter from ThreadLocal |
Eternal ID of this version: | #1007397/12 |
Text MD5: | 0a7e54de17f1d576e3ec13303b1eee2d |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-01-14 19:36:13 |
Source code size: | 842 bytes / 33 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 649 / 695 |
Version history: | 11 change(s) |
Referenced in: | [show references] |