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

31
LINES

< > BotCompany Repo | #1030800 // _csetField backup

JavaX fragment (include)

// returns true if change
sbool _csetField(Concept c, S field, O value) ctex {
  Field f = setOpt_findField(c.getClass(), field);
  //print("cset: " + c.id + " " + field + " " + struct(value) + " " + f);
  if (value instanceof RC) value = c._concepts.getConcept((RC) value);
  value = deref(value);
  
  if (value instanceof S && l((S) value) >= concepts_internStringsLongerThan) value = intern((S) value);
  
  if (f == null) {
    // TODO: keep ref if it exists
    c.fieldValues = syncMapPut2_createLinkedHashMap(c.fieldValues, assertIdentifier(field), value instanceof Concept ? c.new Ref((Concept) value) : value);
    c.change();
  } else if (isSubtypeOf(f.getType(), Concept.Ref.class)) {
    // Concept.Ref magic
    ((Concept.Ref) f.get(c)).set((Concept) derefRef(value));
    c.change(); true;
  } else if (isSubtypeOf(f.getType(), Concept.RefL.class)) {
    // Concept.RefL magic
    ((Concept.RefL) f.get(c)).replaceWithList(lmap derefRef((L) value));
    c.change(); true;
  } else {
    O old = f.get(c);
    if (neq(value, old)) {
      f.set(c, value);
      if (!isTransient(f)) c.change(); 
      true;
    }
  }
  false;
}

Author comment

Began life as a copy of #1026007

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1030800
Snippet name: _csetField backup
Eternal ID of this version: #1030800/1
Text MD5: 285d1836c76c34f0fd0185e144fedeaf
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-03-26 17:16:21
Source code size: 1171 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 162 / 196
Referenced in: [show references]