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

56
LINES

< > BotCompany Repo | #1026155 // ConceptFieldIndexDesc - backup before MultiSetMap

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

Libraryless. Click here for Pure Java version (13012L/87K).

sclass ConceptFieldIndexDesc<A extends Concept, Val> implements IConceptIndex, IFieldIndex<A, Val> {
  Class<A> cc;
  S field;
  new HashMap<A, Val> objectToValue;
  MultiMap<Val, A> valueToObject;
  
  *() { valueToObject = treeMultiMap(reverseOrder()); }
  *(Class<A> cc, S field) { this(mainConcepts, cc, field); }
  *(Concepts concepts, Class<A> *cc, S *field) {
    this();
    concepts.addConceptIndex(this);
    for (A c : list(concepts, cc))
      updateImpl(c);
    concepts.addFieldIndex(cc, field, this);
  }
  
  public void update(Concept c) {
    if (!isInstance(cc, c)) ret;
    updateImpl(c);
  }
  
  synchronized void updateImpl(Concept c) {
    Val newValue = cast cget(c, field);
    Val oldValue = objectToValue.get(c);
    if (newValue == null || newValue != oldValue) {
      valueToObject.remove(oldValue, (A) c);
      valueToObject.put(newValue, (A) c);
      objectToValue.put((A) c, newValue);
    }
  }
  
  public synchronized void remove(Concept c) {
    if (!isInstance(cc, c)) ret;
    Val value = cast cget(c, field);
    objectToValue.remove(c);
    valueToObject.remove(value, (A) c);
  }
  
  synchronized A get(Val value) {
    ret valueToObject.getFirst(value);
  }
  
  public synchronized L<A> getAll(Val value) {
    ret valueToObject.get(value);
  }
  
  public synchronized L<Val> allValues() { ret cloneKeys_noSync(valueToObject.data); }
  
  IterableIterator<A> objectIterator() {
    ret navigableMultiMapValuesIterator(valueToObject);
  }
  
  public synchronized MultiSet<Val> allValues_multiSet() {
    ret multiMapToMultiSet(valueToObject);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

-
Snippet ID: #1026155
Snippet name: ConceptFieldIndexDesc - backup before MultiSetMap
Eternal ID of this version: #1026155/1
Text MD5: 8ea85b576329ecc7e0bf77a7b856407f
Transpilation MD5: 3e5f49d95768da901cfb38bcae07593c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-27 13:24:50
Source code size: 1652 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 197 / 287
Referenced in: