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

75
LINES

< > BotCompany Repo | #1029984 // GazellePost

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

Libraryless. Click here for Pure Java version (3111L/18K).

1  
sclass GazellePost {
2  
  long id;
3  
  long created, modified, bumped; // timestamps
4  
  GazelleUser creator;
5  
  S text, title, type, botInfo;
6  
  bool creating, hidden;
7  
  L<Long> postRefs;
8  
  LS postRefTags;
9  
  O importedFrom;
10  
  
11  
  *() {}
12  
  *(Map map) {
13  
    id = toLong(map.get("id"));
14  
    created = toLong(map.get("created"));
15  
    modified = toLong(map.get("_modified"));
16  
    bumped = toLong(map.get("bumped"));
17  
    text = (S) map.get("text");
18  
    title = (S) map.get("title");
19  
    type = (S) map.get("type");
20  
    botInfo = (S) map.get("botInfo");
21  
    creating = isTrue(map.get("creating"));
22  
    hidden = isTrue(map.get("hidden"));
23  
    postRefs = allToLong((L) map.get("postRefs"));
24  
    postRefTags = checkedListCast S(map.get("postRefTags"));
25  
    long creatorID = toLong(map.get("creatorID"));
26  
    S creatorName = cast map.get("creatorName");
27  
    if (creatorID != 0 || nempty(creatorName)) {
28  
      creator = new GazelleUser(creatorID, creatorName);
29  
      creator.isMaster = isTrue(map.get("creatorIsMaster"));
30  
    }
31  
  }
32  
  
33  
  LPair<Long, S> taggedRefs() { ret zipTwoListsToPairs_lengthOfFirst(postRefs, postRefTags); }
34  
  
35  
  // extended to length
36  
  LS postRefTags() {
37  
    ret padList(postRefTags, l(postRefs));
38  
  }
39  
  
40  
  long refWithTag(S tag) { ret unnull(first(refsWithTag(tag))); }
41  
  
42  
  long refWithTagOrFail(S tag) {
43  
    long ref = refWithTag(tag);
44  
    if (ref == 0) fail("Need " + quote(ref) + " reference");
45  
    ret ref;
46  
  }
47  
  
48  
  L<Long> refsWithTag(S tag) {
49  
    ret pairsAWhereB(taggedRefs(), t -> eqic_unnull(t, tag));
50  
  }
51  
  
52  
  long parentID() { ret refWithTag(""); }
53  
54  
  toString {
55  
    S content = nempty(title) ? shorten(title) : escapeNewLines(shorten(text));
56  
    ret content + " [by " + author() + "]";
57  
  }
58  
59  
  S author() {  
60  
    S author = or2(strOrNull(creator), "unknown");
61  
    if (isBotPost()) author += "'s bot " + quote(botInfo);
62  
    ret author;
63  
  }
64  
  
65  
  bool isReply() { ret nempty(postRefs); }
66  
  bool isBotPost() { ret nempty(botInfo); }
67  
  bool isJavaXCode() { ret eqicOrSwicPlusSpace(type, "JavaX Code"); }
68  
  bool isPythonCode() { ret eqicOrSwicPlusSpace(type, "Python Code") && !ewic(type, " Checker"); }
69  
  bool isAutoBotMade() { ret swic(botInfo, "Auto-Bot "); }
70  
  bool isMasterMade() { ret creator != null && creator.isMaster; }
71  
  
72  
  long modifiedOrBumped() { ret max(modified, bumped); }
73  
  
74  
  S text() { ret text; }
75  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1029984
Snippet name: GazellePost
Eternal ID of this version: #1029984/37
Text MD5: 0b3a30aaa2cf904c6b2f1cf034ed5a72
Transpilation MD5: a6d1f901b91bfe320807537255eb89e3
Author: stefan
Category: javax / gazelle.rocks
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-01-05 00:00:55
Source code size: 2402 bytes / 75 lines
Pitched / IR pitched: No / No
Views / Downloads: 270 / 624
Version history: 36 change(s)
Referenced in: [show references]