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

34
LINES

< > BotCompany Repo | #1009257 - cset - set fields in Concept object (with notification of DB)

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

Libraryless. Click here for Pure Java version (12159L/82K).

// returns number of changes
static int cset(Concept c, O... values) ctex {
  if (c == null) ret 0;
  int changes = 0;
  values = expandParams(c.getClass(), values);
  warnIfOddCount(values);
  for (int i = 0; i+1 < l(values); i += 2) {
    S field = (S) values[i];
    O value = values[i+1];
    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) f.get(c)).set((Concept) derefRef(value));
      c.change(); ++changes;
    } else {
      O old = f.get(c);
      if (neq(value, old)) {
        f.set(c, value);
        if ((f.getModifiers() & java.lang.reflect.Modifier.TRANSIENT) == 0) c.change(); 
        ++changes;
      }
    }
  }
  ret changes;
}

download  show line numbers  debug dex   

Travelled to 9 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1009257
Snippet name: cset - set fields in Concept object (with notification of DB)
Eternal ID of this version: #1009257/9
Text MD5: 9ed1e34ec1b4282a5c4b83c95320054e
Transpilation MD5: 022e4c763a16ae13b660a742c6cb7f3f
Author: stefan
Category: javax / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-13 12:50:02
Source code size: 1292 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 350 / 409
Version history: 8 change(s)
Referenced in: [show references]