Class: CaTissue::StorageContainer

Inherits:
Object
  • Object
show all
Includes:
StorageTypeHolder
Defined in:
lib/catissue/domain/storage_container.rb

Overview

The caTissue StorageContainer domain class wrapper.

Instance Method Summary collapse

Methods included from StorageTypeHolder

#add_child_type, #child_container_types, #child_specimen_array_types, #child_specimen_classes, #child_storage_types, #child_types

Constructor Details

#initializeStorageContainer

Returns a new instance of StorageContainer.



49
50
51
52
53
54
55
# File 'lib/catissue/domain/storage_container.rb', line 49

def initialize
  super
  # @quirk JRuby specimen_positions is not recognized until respond_to? is called
  respond_to?(:specimen_positions)
  # work around caTissue Bug #64
  self.specimen_positions ||= Java::JavaUtil::LinkedHashSet.new
end

Instance Method Details

#add(storable, *coordinate) ⇒ StorageContainer Also known as: <<

Adds the given storable to this container. If the storable has a current position, then the storable is moved from that position to this container. The new position is given by the given coordinate, if given to this method.

The default coordinate is the first available slot within this Container. If this container cannot hold the storable type, then the storable is added to a subcontainer which can hold the storable type.

Examples:

rack << box #=> places the tissue box on the rack
freezer << box #=> places the tissue box on a rack in the freezer
freezer << specimen #=> places the specimen in the first available box in the freezer

Parameters:

  • the (Storable)

    item to add

  • the (Coordinate, <Integer>)

    storage location (default is first available location)

Returns:

Raises:

  • (IndexError)

    if this Container is full

  • (IndexError)

    if the row and column are given but exceed the Container bounds



83
84
85
86
87
# File 'lib/catissue/domain/storage_container.rb', line 83

def add(storable, *coordinate)
  return add_local(storable, *coordinate) unless coordinate.empty?
  add_to_existing_container(storable) or add_to_new_subcontainer(storable) or out_of_bounds(storable)
  self
end

#all_occupied_positionsObject

Corrects the caTissue occupied_positions method to include specimen_positions.



58
59
60
# File 'lib/catissue/domain/storage_container.rb', line 58

def all_occupied_positions
  subcontainer_positions.union(specimen_positions)
end

#can_hold_child?(storable) ⇒ Boolean

Overrides Container#can_hold_child? to detect account for the potential instance-specific CaTissue::StorageTypeHolder#child_types override allowed by caTissue.

Returns:

  • (Boolean)

    whether this container is not full and can hold the given item’s CaTissue::StorageType



125
126
127
128
# File 'lib/catissue/domain/storage_container.rb', line 125

def can_hold_child?(storable)
  st = storable.storable_type
  not full? and child_types.any? { |ct| Jinx::Resource.value_equal?(ct, st) }
end

#create_subcontainer(name, type) ⇒ Container

Returns a new container with the given name and type, located in this container.

Returns:

  • (Container)

    a new container with the given name and type, located in this container



110
111
112
113
114
115
116
117
# File 'lib/catissue/domain/storage_container.rb', line 110

def create_subcontainer(name, type)
  logger.debug { "Creating #{qp} subcontainer of type #{type} with name #{name}..." }
  ctr = type.new_container(:name => name, :site => site)
  self << ctr
  ctr.create
  logger.debug { "Made #{self} subcontainer #{ctr}." }
  ctr
end

#find_subcontainer(name, type) ⇒ Object

Finds the container with the given name, or creates a new container of the given type if necessary.

Parameters:

Returns:

  • a container with the given name



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/catissue/domain/storage_container.rb', line 97

def find_subcontainer(name, type)
  logger.debug { "Finding box with name #{name}..." }
  ctr = CaTissue::StorageContainer.new(:name => name)
  if ctr.find then
    logger.debug { "Container found: #{ctr}." }
  else
    logger.debug { "Container not found: #{name}." }
    create_subcontainer(name, type)
  end
  box
end

#specimen_positionsJava::JavaUtil::Set

Initialize specimen_positions if necessary.

Returns:

  • (Java::JavaUtil::Set)

    the positions



15
16
17
# File 'lib/catissue/domain/storage_container.rb', line 15

def specimen_positions
  getSpecimenPositionCollection or (self.specimen_positions = Java::JavaUtil::LinkedHashSet.new)
end

#storage_type=(type) ⇒ Object

Copies the given container type child types to this container instance child types.

Parameters:



26
27
28
29
30
# File 'lib/catissue/domain/storage_container.rb', line 26

def storage_type=(type)
  setStorageType(type)
  copy_child_types(type) if type
  type
end