Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

80
LINES

< > BotCompany Repo | #1001518 // l function (synonym of length), length of arrays, strings, lists, size of maps

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (103L/1K).

1  
static int l(Object[] a) { return a == null ? 0 : a.length; }
2  
static int l(bool[] a) { return a == null ? 0 : a.length; }
3  
static int l(byte[] a) { return a == null ? 0 : a.length; }
4  
static int l(short[] a) { return a == null ? 0 : a.length; }
5  
static int l(long[] a) { return a == null ? 0 : a.length; }
6  
static int l(int[] a) { return a == null ? 0 : a.length; }
7  
static int l(float[] a) { return a == null ? 0 : a.length; }
8  
static int l(double[] a) { return a == null ? 0 : a.length; }
9  
static int l(char[] a) { return a == null ? 0 : a.length; }
10  
static int l(Collection c) { return c == null ? 0 : c.size(); }
11  
ifndef l_noIterators
12  
static int l(Iterator i) { return iteratorCount_int_close(i); } // consumes the iterator && closes it if possible
13  
endifndef
14  
static int l(Map m) { return m == null ? 0 : m.size(); }
15  
static int l(CharSequence s) { return s == null ? 0 : s.length(); }
16  
static long l(File f) { ret f == null ? 0 : f.length(); }
17  
18  
ifdef l_withReflection
19  
20  
static int l(Object o) {
21  
  ret o == null ? 0
22  
    : o instanceof S ? l((S) o)
23  
    : o instanceof Map ? l((Map) o)
24  
    : o instanceof Collection ? l((Collection) o)
25  
    : o instanceof O[] ? l((O[]) o)
26  
    : o instanceof bool[] ? l((bool[]) o)
27  
    : o instanceof byte[] ? l((byte[]) o)
28  
    : o instanceof char[] ? l((char[]) o)
29  
    : o instanceof short[] ? l((short[]) o)
30  
    : o instanceof int[] ? l((int[]) o)
31  
    : o instanceof float[] ? l((float[]) o)
32  
    : o instanceof double[] ? l((double[]) o)
33  
    : o instanceof long[] ? l((long[]) o)
34  
    : (Int) call(o, 'size);
35  
}
36  
endifdef
37  
38  
ifclass IMultiSet
39  
  static int l(IMultiSet ms) { ret ms == null ? 0 : ms.size(); }
40  
endif
41  
42  
ifclass IMultiMap
43  
  static int l(IMultiMap mm) { ret mm == null ? 0 : mm.size(); }
44  
endif
45  
46  
ifclass Lisp
47  
  static int l(Lisp l) { ret l == null ? 0 : l.size(); }
48  
endif
49  
50  
ifclass IntRange
51  
  static int l(IntRange r) { ret r == null ? 0 : r.length(); }
52  
endif
53  
54  
ifclass LongRange
55  
  static long l(LongRange r) { ret r == null ? 0 : r.length(); }
56  
endif
57  
58  
ifclass DoubleRange
59  
  static double l(DoubleRange r) { ret r == null ? 0 : r.length(); }
60  
endif
61  
62  
ifclass IntBuffer
63  
  static int l(IntBuffer b) { ret b == null ? 0 : b.size(); }
64  
endif
65  
66  
ifclass LongBuffer
67  
  static int l(LongBuffer b) { ret b == null ? 0 : b.size(); }
68  
endif
69  
70  
ifclass ShortBuffer
71  
  static int l(ShortBuffer b) { ret b == null ? 0 : b.size(); }
72  
endif
73  
74  
ifclass HalfLongs
75  
  static int l(HalfLongs l) { ret l == null ? 0 : l.size(); }
76  
endif
77  
78  
ifclass IntSize
79  
  static int l(IntSize o) { ret o == null ? 0 : o.size(); }
80  
endif

Author comment

Began life as a copy of #1001516

download  show line numbers  debug dex  old transpilations   

Travelled to 25 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, ekrmjmnbrukm, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lnbujpyubztb, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, wnsclhtenguj, wtqryiryparv, xrpafgyirdlv, yanjaxplzisb

No comments. add comment

Snippet ID: #1001518
Snippet name: l function (synonym of length), length of arrays, strings, lists, size of maps
Eternal ID of this version: #1001518/38
Text MD5: eaab1da476db68d5a8d186486ff77dde
Transpilation MD5: 26c2e3c16acfeec06513409b4620a756
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-02-13 23:12:25
Source code size: 2589 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 1354 / 10315
Version history: 37 change(s)
Referenced in: [show references]