Module: CaTissue::Position
Overview
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#==(other) ⇒ Boolean
Whether other is an instance of this position’s class with the same occupant and equal location.
-
#coordinate ⇒ Coordinate
The read-only coordinate with this AbstractPosition’s #row and #column.
-
#location ⇒ Location
The location of this Position.
- #location=(value) ⇒ Object
-
#to_a ⇒ (Integer, Integer)
This Position’s zero-based (#column, #row) tuple.
-
#unspecified? ⇒ Boolean
Whether either the column or the row is nil.
- #validate ⇒ Object
Instance Method Details
#<=>(other) ⇒ Object
15 16 17 18 |
# File 'lib/catissue/util/position.rb', line 15 def <=>(other) raise ArgumentError.new("Can't compare #{qp} to #{other.qp}") unless self.class === other equal?(other) ? 0 : location <=> other.location end |
#==(other) ⇒ Boolean
Returns whether other is an instance of this position’s class with the same occupant and equal location.
24 25 26 |
# File 'lib/catissue/util/position.rb', line 24 def ==(other) self.class === other and occupant == other.occupant and location == other.location end |
#coordinate ⇒ Coordinate
Returns the read-only coordinate with this AbstractPosition’s #row and #column.
29 30 31 |
# File 'lib/catissue/util/position.rb', line 29 def coordinate location.coordinate end |
#location ⇒ Location
Returns the location of this Position.
34 35 36 37 38 39 40 41 |
# File 'lib/catissue/util/position.rb', line 34 def location @location ||= Location.new # always ensure that the location is consistent with the Java state @location.holder = holder @location.row = row @location.column = column @location end |
#location=(value) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/catissue/util/position.rb', line 44 def location=(value) @location = value || Location.new self.holder = @location.holder self.row = @location.row self.column = @location.column end |
#to_a ⇒ (Integer, Integer)
Returns this Position’s zero-based (#column, #row) tuple.
57 58 59 |
# File 'lib/catissue/util/position.rb', line 57 def to_a [column, row] end |
#unspecified? ⇒ Boolean
Returns whether either the column or the row is nil.
52 53 54 |
# File 'lib/catissue/util/position.rb', line 52 def unspecified? column.nil? or row.nil? end |
#validate ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/catissue/util/position.rb', line 62 def validate super logger.debug { "Validating that #{holder} can hold #{occupant}..." } curr_occ = holder[column, row] if curr_occ.nil? then unless holder.can_hold_child?(occupant) then reason = holder.full? ? "it is full" : "the occupant type is not among the supported types #{holder.container_type.child_types.qp}" raise ValidationError.new("#{holder} cannot hold #{occupant} since #{reason}") end elsif curr_occ != occupant raise ValidationError.new("#{holder} cannot hold #{occupant} since the location #{[colum, row]} is already occupied by #{curr_occ}") end end |