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

46
LINES

< > BotCompany Repo | #1002990 // contains - like Collection.contains, but allows a null collection and arrays. also for strings

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

Transpiled version (78L) is out of date.

sbool contains(Collection c, O o) {
  ret c != null && c.contains(o);
}

sbool contains(Iterable it, O a) {
  if (it != null)
    for (O o : it)
      if (eq(a, o))
        true;
  false;
}

static bool contains(O[] x, O o) {
  if (x != null)
    for (O a : x)
      if (eq(a, o))
        true;
  false;
}

static bool contains(S s, char c) {
  ret s != null && s.indexOf(c) >= 0;
}

static bool contains(S s, S b) {
  ret s != null && s.indexOf(b) >= 0;
}

static bool contains(BitSet bs, int i) {
  ret bs != null && bs.get(i);
}

ifclass Producer
static <A> bool contains(Producer<A> p, A a) {
  if (p != null && a != null) while true {
    A x = p.next();
    if (x == null) break;
    if (eq(x, a)) true;
  }
  false;
}
endif

ifclass Rect
sbool contains(Rect r, Pt p) { ret rectContains(r, p); }
endif

Author comment

Began life as a copy of #1002148

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1002990
Snippet name: contains - like Collection.contains, but allows a null collection and arrays. also for strings
Eternal ID of this version: #1002990/12
Text MD5: db3968ea2d42c016ad55261ff7be5e81
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-25 20:00:04
Source code size: 852 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 733 / 1575
Version history: 11 change(s)
Referenced in: [show references]