Class: Coopy::Merger

Inherits:
Object
  • Object
show all
Defined in:
lib/lib/coopy/merger.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, local, remote, flags) ⇒ Merger

Returns a new instance of Merger.



7
8
9
10
11
12
# File 'lib/lib/coopy/merger.rb', line 7

def initialize(parent,local,remote,flags)
  @parent = parent
  @local = local
  @remote = remote
  @flags = flags
end

Instance Attribute Details

#column_mix_localObject

Returns the value of attribute column_mix_local.



26
27
28
# File 'lib/lib/coopy/merger.rb', line 26

def column_mix_local
  @column_mix_local
end

#column_mix_remoteObject

Returns the value of attribute column_mix_remote.



27
28
29
# File 'lib/lib/coopy/merger.rb', line 27

def column_mix_remote
  @column_mix_remote
end

#column_orderObject

Returns the value of attribute column_order.



22
23
24
# File 'lib/lib/coopy/merger.rb', line 22

def column_order
  @column_order
end

#column_unitsObject

Returns the value of attribute column_units.



23
24
25
# File 'lib/lib/coopy/merger.rb', line 23

def column_units
  @column_units
end

#conflict_infosObject

Returns the value of attribute conflict_infos.



29
30
31
# File 'lib/lib/coopy/merger.rb', line 29

def conflict_infos
  @conflict_infos
end

#conflictsObject

Returns the value of attribute conflicts.



28
29
30
# File 'lib/lib/coopy/merger.rb', line 28

def conflicts
  @conflicts
end

#flagsObject

Returns the value of attribute flags.



19
20
21
# File 'lib/lib/coopy/merger.rb', line 19

def flags
  @flags
end

#localObject

Returns the value of attribute local.



17
18
19
# File 'lib/lib/coopy/merger.rb', line 17

def local
  @local
end

#orderObject

Returns the value of attribute order.



20
21
22
# File 'lib/lib/coopy/merger.rb', line 20

def order
  @order
end

#parentObject

protected - in ruby this doesn’t play well with static/inline methods



16
17
18
# File 'lib/lib/coopy/merger.rb', line 16

def parent
  @parent
end

#remoteObject

Returns the value of attribute remote.



18
19
20
# File 'lib/lib/coopy/merger.rb', line 18

def remote
  @remote
end

#row_mix_localObject

Returns the value of attribute row_mix_local.



24
25
26
# File 'lib/lib/coopy/merger.rb', line 24

def row_mix_local
  @row_mix_local
end

#row_mix_remoteObject

Returns the value of attribute row_mix_remote.



25
26
27
# File 'lib/lib/coopy/merger.rb', line 25

def row_mix_remote
  @row_mix_remote
end

#unitsObject

Returns the value of attribute units.



21
22
23
# File 'lib/lib/coopy/merger.rb', line 21

def units
  @units
end

Class Method Details

.make_conflicted_cell(view, pcell, lcell, rcell) ⇒ Object



190
191
192
# File 'lib/lib/coopy/merger.rb', line 190

def Merger.make_conflicted_cell(view,pcell,lcell,rcell)
  view.to_datum("((( " + _hx_str(view.to_s(pcell)) + " ))) " + _hx_str(view.to_s(lcell)) + " /// " + _hx_str(view.to_s(rcell)))
end

Instance Method Details

#add_conflict_info(row, col, view, pcell, lcell, rcell) ⇒ Object

protected - in ruby this doesn’t play well with static/inline methods



186
187
188
# File 'lib/lib/coopy/merger.rb', line 186

def add_conflict_info(row,col,view,pcell,lcell,rcell)
  @conflict_infos.push(::Coopy::ConflictInfo.new(row,col,view.to_s(pcell),view.to_s(lcell),view.to_s(rcell)))
end

#applyObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/lib/coopy/merger.rb', line 100

def apply 
  @conflicts = 0
  @conflict_infos = Array.new
  ct = ::Coopy::Coopy.compare_tables3(@parent,@local,@remote)
  align = ct.align
  @order = align.to_order
  @units = @order.get_list
  @column_order = align.meta.to_order
  @column_units = @column_order.get_list
  allow_insert = @flags.allow_insert
  allow_delete = @flags.allow_delete
  allow_update = @flags.allow_update
  view = @parent.get_cell_view
  begin
    _g = 0
    _g1 = @units
    while(_g < _g1.length) 
      row = _g1[_g]
      _g+=1
      if row.l >= 0 && row.r >= 0 && row.p >= 0 
        _g2 = 0
        _g3 = @column_units
        while(_g2 < _g3.length) 
          col = _g3[_g2]
          _g2+=1
          if col.l >= 0 && col.r >= 0 && col.p >= 0 
            pcell = @parent.get_cell(col.p,row.p)
            rcell = @remote.get_cell(col.r,row.r)
            if !view.equals(pcell,rcell) 
              lcell = @local.get_cell(col.l,row.l)
              if view.equals(pcell,lcell) 
                @local.set_cell(col.l,row.l,rcell)
              else 
                @local.set_cell(col.l,row.l,::Coopy::Merger.make_conflicted_cell(view,pcell,lcell,rcell))
                @conflicts+=1
                self.add_conflict_info(row.l,col.l,view,pcell,lcell,rcell)
              end
            end
          end
        end
      end
    end
  end
  self.shuffle_columns
  self.shuffle_rows
  _it = ::Rb::RubyIterator.new(@column_mix_remote.keys)
  while(_it.has_next) do
    x = _it._next
    x2 = @column_mix_remote[x]
    begin
      _g4 = 0
      _g11 = @units
      while(_g4 < _g11.length) 
        unit = _g11[_g4]
        _g4+=1
        if unit.l >= 0 && unit.r >= 0 
          @local.set_cell(x2,@row_mix_local[unit.l],@remote.get_cell(x,unit.r))
        elsif unit.p < 0 && unit.r >= 0 
          @local.set_cell(x2,@row_mix_remote[unit.r],@remote.get_cell(x,unit.r))
        end
      end
    end
  end
  _it2 = ::Rb::RubyIterator.new(@row_mix_remote.keys)
  while(_it2.has_next) do
    y = _it2._next
    y2 = @row_mix_remote[y]
    begin
      _g5 = 0
      _g12 = @column_units
      while(_g5 < _g12.length) 
        unit1 = _g12[_g5]
        _g5+=1
        @local.set_cell(@column_mix_local[unit1.l],y2,@remote.get_cell(unit1.r,y)) if unit1.l >= 0 && unit1.r >= 0
      end
    end
  end
  @conflicts
end

#get_conflict_infosObject



180
181
182
# File 'lib/lib/coopy/merger.rb', line 180

def get_conflict_infos 
  @conflict_infos
end

#shuffle_columnsObject



82
83
84
85
86
87
88
# File 'lib/lib/coopy/merger.rb', line 82

def shuffle_columns 
  @column_mix_local = {}
  @column_mix_remote = {}
  fate = Array.new
  wfate = self.shuffle_dimension(@column_units,@local.get_width,fate,@column_mix_local,@column_mix_remote)
  @local.insert_or_delete_columns(fate,wfate)
end

#shuffle_dimension(dim_units, len, fate, cl, cr) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/lib/coopy/merger.rb', line 31

def shuffle_dimension(dim_units,len,fate,cl,cr)
  at = 0
  begin
    _g = 0
    while(_g < dim_units.length) 
      cunit = dim_units[_g]
      _g+=1
      if cunit.p < 0 
        if cunit.l < 0 
          if cunit.r >= 0 
            begin
              cr[cunit.r] = at
              at
            end
            at+=1
          end
        else 
          begin
            cl[cunit.l] = at
            at
          end
          at+=1
        end
      elsif cunit.l >= 0 
        if cunit.r < 0 
        else 
          begin
            cl[cunit.l] = at
            at
          end
          at+=1
        end
      end
    end
  end
  begin
    _g1 = 0
    while(_g1 < len) 
      x = _g1
      _g1+=1
      idx = cl[x]
      if idx == nil 
        fate.push(-1)
      else 
        fate.push(idx)
      end
    end
  end
  at
end

#shuffle_rowsObject



90
91
92
93
94
95
96
# File 'lib/lib/coopy/merger.rb', line 90

def shuffle_rows 
  @row_mix_local = {}
  @row_mix_remote = {}
  fate = Array.new
  hfate = self.shuffle_dimension(@units,@local.get_height,fate,@row_mix_local,@row_mix_remote)
  @local.insert_or_delete_rows(fate,hfate)
end