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

62
LINES

< > BotCompany Repo | #1024457 // ConceptFieldIndexCI - backup before MultiSetMap

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

Libraryless. Click here for Pure Java version (12615L/85K).

sclass ConceptFieldIndexCI<A extends Concept> implements IConceptIndex, IFieldIndex<A, S>, IConceptCounter {
  Class<A> cc;
  S field;
  new HashMap<A, S> objectToValue;
  MultiMap<S, A> valueToObject = ciMultiMap();
  
  *() {}
  *(Class<A> cc, S field) { this(db_mainConcepts(), cc, field); }
  *(Concepts concepts, Class<A> *cc, S *field) {
    concepts.addConceptIndex(this);
    for (A c : list(concepts, cc))
      updateImpl(c);
    concepts.addCIFieldIndex(cc, field, this);
  }
  
  public void update(Concept c) {
    if (!isInstance(cc, c)) ret;
    updateImpl(c);
  }
  
  synchronized void updateImpl(Concept c) {
    S newValue = cast cget(c, field);
    S 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;
    S value = cast cget(c, field);
    objectToValue.remove(c);
    valueToObject.remove(value, (A) c);
  }
  
  synchronized A get(S value) {
    ret valueToObject.getFirst(value);
  }
  
  public synchronized L<A> getAll(S value) {
    ret valueToObject.get(value);
  }
  
  public Class<? extends Concept> conceptClass() { ret cc; }
  public int countConcepts() { ret l(objectToValue); }
  
  // Note: NOT SORTED
  public Collection<Concept> allConcepts() { ret (Collection) keys(objectToValue); }
  
  public synchronized LS allValues() { ret cloneKeys_noSync(valueToObject.data); }
  
  public synchronized MultiSet<S> allValues_multiSet() {
    ret multiMapToMultiSet(valueToObject);
  }
  
  // SORTED
  IterableIterator<A> objectIterator() {
    ret navigableMultiMapValuesIterator(valueToObject);
  }
}

Author comment

Began life as a copy of #1014416

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: #1024457
Snippet name: ConceptFieldIndexCI - backup before MultiSetMap
Eternal ID of this version: #1024457/1
Text MD5: 5aa44d3899059a57a7cf87a37973f24c
Transpilation MD5: 3b8f70d250d848cf99322cf644e37c63
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:10:24
Source code size: 1850 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 227 / 328
Referenced in: [show references]