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

31
LINES

< > BotCompany Repo | #1030800 // _csetField backup

JavaX fragment (include)

1  
// returns true if change
2  
sbool _csetField(Concept c, S field, O value) ctex {
3  
  Field f = setOpt_findField(c.getClass(), field);
4  
  //print("cset: " + c.id + " " + field + " " + struct(value) + " " + f);
5  
  if (value instanceof RC) value = c._concepts.getConcept((RC) value);
6  
  value = deref(value);
7  
  
8  
  if (value instanceof S && l((S) value) >= concepts_internStringsLongerThan) value = intern((S) value);
9  
  
10  
  if (f == null) {
11  
    // TODO: keep ref if it exists
12  
    c.fieldValues = syncMapPut2_createLinkedHashMap(c.fieldValues, assertIdentifier(field), value instanceof Concept ? c.new Ref((Concept) value) : value);
13  
    c.change();
14  
  } else if (isSubtypeOf(f.getType(), Concept.Ref.class)) {
15  
    // Concept.Ref magic
16  
    ((Concept.Ref) f.get(c)).set((Concept) derefRef(value));
17  
    c.change(); true;
18  
  } else if (isSubtypeOf(f.getType(), Concept.RefL.class)) {
19  
    // Concept.RefL magic
20  
    ((Concept.RefL) f.get(c)).replaceWithList(lmap derefRef((L) value));
21  
    c.change(); true;
22  
  } else {
23  
    O old = f.get(c);
24  
    if (neq(value, old)) {
25  
      f.set(c, value);
26  
      if (!isTransient(f)) c.change(); 
27  
      true;
28  
    }
29  
  }
30  
  false;
31  
}

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: 164 / 199
Referenced in: [show references]