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).

sclass GazellePost {
  long id;
  long created, modified, bumped; // timestamps
  GazelleUser creator;
  S text, title, type, botInfo;
  bool creating, hidden;
  L<Long> postRefs;
  LS postRefTags;
  O importedFrom;
  
  *() {}
  *(Map map) {
    id = toLong(map.get("id"));
    created = toLong(map.get("created"));
    modified = toLong(map.get("_modified"));
    bumped = toLong(map.get("bumped"));
    text = (S) map.get("text");
    title = (S) map.get("title");
    type = (S) map.get("type");
    botInfo = (S) map.get("botInfo");
    creating = isTrue(map.get("creating"));
    hidden = isTrue(map.get("hidden"));
    postRefs = allToLong((L) map.get("postRefs"));
    postRefTags = checkedListCast S(map.get("postRefTags"));
    long creatorID = toLong(map.get("creatorID"));
    S creatorName = cast map.get("creatorName");
    if (creatorID != 0 || nempty(creatorName)) {
      creator = new GazelleUser(creatorID, creatorName);
      creator.isMaster = isTrue(map.get("creatorIsMaster"));
    }
  }
  
  LPair<Long, S> taggedRefs() { ret zipTwoListsToPairs_lengthOfFirst(postRefs, postRefTags); }
  
  // extended to length
  LS postRefTags() {
    ret padList(postRefTags, l(postRefs));
  }
  
  long refWithTag(S tag) { ret unnull(first(refsWithTag(tag))); }
  
  long refWithTagOrFail(S tag) {
    long ref = refWithTag(tag);
    if (ref == 0) fail("Need " + quote(ref) + " reference");
    ret ref;
  }
  
  L<Long> refsWithTag(S tag) {
    ret pairsAWhereB(taggedRefs(), t -> eqic_unnull(t, tag));
  }
  
  long parentID() { ret refWithTag(""); }

  toString {
    S content = nempty(title) ? shorten(title) : escapeNewLines(shorten(text));
    ret content + " [by " + author() + "]";
  }

  S author() {  
    S author = or2(strOrNull(creator), "unknown");
    if (isBotPost()) author += "'s bot " + quote(botInfo);
    ret author;
  }
  
  bool isReply() { ret nempty(postRefs); }
  bool isBotPost() { ret nempty(botInfo); }
  bool isJavaXCode() { ret eqicOrSwicPlusSpace(type, "JavaX Code"); }
  bool isPythonCode() { ret eqicOrSwicPlusSpace(type, "Python Code") && !ewic(type, " Checker"); }
  bool isAutoBotMade() { ret swic(botInfo, "Auto-Bot "); }
  bool isMasterMade() { ret creator != null && creator.isMaster; }
  
  long modifiedOrBumped() { ret max(modified, bumped); }
  
  S text() { ret text; }
}

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: 267 / 619
Version history: 36 change(s)
Referenced in: #1029987 - GazelleUser
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)