Class: Lutaml::UmlRepository::ClassLookupIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/uml_repository/class_lookup_index.rb

Overview

O(1) lookup index for UML classes by various identifiers.

Replaces O(n) linear scans that were repeated across multiple transformer and serializer classes.

Examples:

index = ClassLookupIndex.new(repository.classes_index)
index.by_xmi_id("EAID_123...")
index.by_object_id(42)

Instance Method Summary collapse

Constructor Details

#initialize(classes) ⇒ ClassLookupIndex

Returns a new instance of ClassLookupIndex.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lutaml/uml_repository/class_lookup_index.rb', line 15

def initialize(classes)
  @by_xmi_id = {}
  @by_object_id = {}

  classes.each do |klass|
    @by_xmi_id[klass.xmi_id] = klass if klass.xmi_id
    if klass.respond_to?(:ea_object_id) && klass.ea_object_id
      @by_object_id[klass.ea_object_id] = klass
    end
  end
end

Instance Method Details

#by_object_id(object_id) ⇒ Lutaml::Uml::Class?

Parameters:

  • object_id (String, Integer)

Returns:



35
36
37
# File 'lib/lutaml/uml_repository/class_lookup_index.rb', line 35

def by_object_id(object_id)
  @by_object_id[object_id]
end

#by_xmi_id(xmi_id) ⇒ Lutaml::Uml::Class?

Parameters:

  • xmi_id (String)

Returns:



29
30
31
# File 'lib/lutaml/uml_repository/class_lookup_index.rb', line 29

def by_xmi_id(xmi_id)
  @by_xmi_id[xmi_id]
end