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

34
LINES

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

JavaX fragment (include)

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

static bool contains(O[] x, O o) {
  if (x != null)
    for (O a : x)
      if (eq(a, o))
        ret true;
  ret 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

Author comment

Began life as a copy of #1002148

download  show line numbers  debug dex   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, podlckwnjdmb, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, 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/4
Text MD5: ab01065338d56cdace0b48665d0327b2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-04 17:51:04
Source code size: 659 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 495 / 1252
Version history: 3 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1002990 & http://1002990.tinybrain.de