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

65
LINES

< > BotCompany Repo | #1009401 // PersistentLister

JavaX fragment (include)

// Should only have one per Concepts because of add logs
concept PersistentLister implements ILister {
  new HashMap<S, L> lists;
  new HashMap<S, Map> treeMaps;
  new HashMap<S, Map> hashMaps;
  new HashMap<S, Set> treeSets;
  new HashMap<S, IVar> vars;
  transient bool nonSaving;

  public L getList(S name) {
    ret getList(name, ll());
  }
  
  public synchronized L getList(S name, L defaultList) {
    L l = lists.get(name);
    if (l == null) {
      lists.put(name, l = listInConcept(this, cloneList(defaultList)));
      change();
    }
    ret l;
  }
  
  public synchronized IVar getVar(S name, O defaultValue) {
    IVar v = vars.get(name);
    if (v == null) {
      vars.put(name, v = varInConcept(this, new Var));
      change();
    }
    if (!v.has() && defaultValue != null)
      v.set(defaultValue);
    ret v;
  }
  
  public synchronized Map getTreeMap(S name) {
    Map m = treeMaps.get(name);
    if (m == null) {
      treeMaps.put(name, m = mapInConcept(this, new TreeMap));
      change();
    }
    if (getOpt_raw(m, 'm) == null)
     fail("map not sane: " + className(m) + " " + struct(m));
    ret m;
  }
  
  public synchronized Map getHashMap(S name) {
    Map m = hashMaps.get(name);
    if (m == null) {
      hashMaps.put(name, m = mapInConcept(this, new HashMap));
      change();
    }
    applyPersistentMapLogFile(_concepts.programID, name, m, !nonSaving);
    if (getOpt_raw(m, 'm) == null)
     fail("map not sane: " + className(m) + " " + struct(m));
    ret m;
  }
  
  public synchronized Set getTreeSet(S name) {
    Set m = treeSets.get(name);
    if (m == null) {
      treeSets.put(name, m = setInConcept(this, new TreeSet));
      change();
    }
    ret m;
  }  
}

Author comment

Began life as a copy of #1009399

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, imzmzdywqqli, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009401
Snippet name: PersistentLister
Eternal ID of this version: #1009401/28
Text MD5: e2b6c5366544438e02890d3fac3268d2
Author: stefan
Category: javax / lists
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-28 10:00:49
Source code size: 1780 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 458 / 1691
Version history: 27 change(s)
Referenced in: [show references]