Skip to content

Commit 89e845e

Browse files
committed
Implemented duplicate method for all functions
1 parent 40fa438 commit 89e845e

18 files changed

Lines changed: 230 additions & 3 deletions

File tree

Source/Charts/src/ca/uqac/lif/spreadsheet/chart/DrawChart.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ public String toString()
119119
{
120120
return "Draw " + m_plot;
121121
}
122+
123+
@Override
124+
public DrawChart duplicate(boolean with_state)
125+
{
126+
DrawChart dp = new DrawChart(m_plot.duplicate());
127+
dp.m_format = m_format;
128+
dp.m_withTitle = m_withTitle;
129+
super.copyInto(dp, with_state);
130+
return dp;
131+
}
122132

123133
/**
124134
* A crawler that appends a new part node to each leaf of an explanation

Source/Core/src/ca/uqac/lif/spreadsheet/functions/ApplyFormula.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ public ApplyFormula(CellFormula ... formulas)
136136
public ApplyFormula(int in_arity, List<CellFormula> formulas)
137137
{
138138
super(in_arity, 1);
139-
m_formulas = sort(formulas);
139+
List<CellFormula> forms = new ArrayList<CellFormula>(formulas.size());
140+
forms.addAll(formulas);
141+
m_formulas = sort(forms);
140142
m_computedCells = new HashSet<Cell>();
141143
for (CellFormula cf : formulas)
142144
{
@@ -297,6 +299,14 @@ protected Object[] getValue(Object... inputs) throws InvalidNumberOfArgumentsExc
297299
return super.getExplanation(part, factory);
298300
}
299301

302+
@Override
303+
public ApplyFormula duplicate(boolean with_state)
304+
{
305+
ApplyFormula af = new ApplyFormula(getInputArity(), m_formulas);
306+
af.m_computedCells.addAll(m_computedCells);
307+
return af;
308+
}
309+
300310
@Override
301311
public String toString()
302312
{

Source/Core/src/ca/uqac/lif/spreadsheet/functions/BoxStats.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,12 @@ protected Object[] getValue(Object ... inputs) throws InvalidNumberOfArgumentsEx
189189
}
190190
return new Object[] {new_table};
191191
}
192+
193+
@Override
194+
public BoxStats duplicate(boolean with_state)
195+
{
196+
BoxStats o = new BoxStats();
197+
super.copyInto(o, with_state);
198+
return o;
199+
}
192200
}

Source/Core/src/ca/uqac/lif/spreadsheet/functions/ColumnSum.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,12 @@ protected Object[] getValue(Object... inputs) throws InvalidNumberOfArgumentsExc
6767
}
6868
return new Object[] {out};
6969
}
70+
71+
@Override
72+
public ColumnSum duplicate(boolean with_state)
73+
{
74+
ColumnSum cs = new ColumnSum();
75+
super.copyInto(cs, with_state);
76+
return cs;
77+
}
7078
}

Source/Core/src/ca/uqac/lif/spreadsheet/functions/ExpandAsColumns.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,16 @@ public String toString()
226226
}
227227
return "Expand " + m_headerColumn + " as " + m_valueColumn;
228228
}
229+
230+
@Override
231+
public ExpandAsColumns duplicate(boolean with_state)
232+
{
233+
ExpandAsColumns eac = new ExpandAsColumns(null, null);
234+
eac.m_headerCaption = m_headerCaption;
235+
eac.m_headerColumn = m_headerColumn;
236+
eac.m_valueCaption = m_valueCaption;
237+
eac.m_valueColumn = m_valueColumn;
238+
super.copyInto(eac, with_state);
239+
return eac;
240+
}
229241
}

Source/Core/src/ca/uqac/lif/spreadsheet/functions/GetFrequencies.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package ca.uqac.lif.spreadsheet.functions;
1919

2020
import java.util.ArrayList;
21+
import java.util.Arrays;
2122
import java.util.List;
2223

2324
import ca.uqac.lif.dag.LabelledNode;
@@ -293,6 +294,18 @@ public String toString()
293294
return "Get frequencies";
294295
}
295296

297+
@Override
298+
public GetFrequencies duplicate(boolean with_state)
299+
{
300+
GetFrequencies gf = new GetFrequencies(m_minX, m_maxX, m_numBucketsX, m_minY, m_maxY, m_numBucketsY, m_defaultIncrement);
301+
super.copyInto(gf, with_state);
302+
if (with_state)
303+
{
304+
gf.m_pairs = Arrays.copyOf(m_pairs, m_pairs.length);
305+
}
306+
return gf;
307+
}
308+
296309
/**
297310
* Attempts to extract a pair of numbers from an object.
298311
* @param o The object

Source/Core/src/ca/uqac/lif/spreadsheet/functions/Merge.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ public Merge excludeFirst()
134134
{
135135
return (Merge) super.excludeFirst();
136136
}
137+
138+
@Override
139+
public String toString()
140+
{
141+
return "Merge";
142+
}
143+
144+
@Override
145+
public Merge duplicate(boolean with_state)
146+
{
147+
Merge m = new Merge(m_keyColumns);
148+
super.copyInto(m, with_state);
149+
return m;
150+
}
137151

138152
@Override
139153
protected Object[] getValue(Object... inputs) throws InvalidNumberOfArgumentsException

Source/Core/src/ca/uqac/lif/spreadsheet/functions/ReadSpreadsheet.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,16 @@ public String toString()
9898
{
9999
return "Read spreadsheet";
100100
}
101+
102+
@Override
103+
public ReadSpreadsheet duplicate(boolean with_state)
104+
{
105+
ReadSpreadsheet rs = new ReadSpreadsheet();
106+
copyInto(rs, with_state);
107+
if (with_state)
108+
{
109+
rs.m_mapping.putAll(m_mapping);
110+
}
111+
return rs;
112+
}
101113
}

Source/Core/src/ca/uqac/lif/spreadsheet/functions/RenameColumn.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,18 @@ protected Object[] getValue(Object... inputs) throws InvalidNumberOfArgumentsExc
6161
new_s.set(index, 0, m_to);
6262
return new Object[] {new_s};
6363
}
64+
65+
@Override
66+
public String toString()
67+
{
68+
return "Rename " + m_from + " to " + m_to;
69+
}
70+
71+
@Override
72+
public RenameColumn duplicate(boolean with_state)
73+
{
74+
RenameColumn r = new RenameColumn(m_from, m_to);
75+
super.copyInto(r, with_state);
76+
return r;
77+
}
6478
}

Source/Core/src/ca/uqac/lif/spreadsheet/functions/Sort.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ protected Object[] getValue(Object... inputs) throws InvalidNumberOfArgumentsExc
136136
return new Object[] {out};
137137
}
138138

139+
@Override
140+
public String toString()
141+
{
142+
return "Sort";
143+
}
144+
145+
@Override
146+
public Sort duplicate(boolean with_state)
147+
{
148+
Sort s = new Sort();
149+
copyInto(s, with_state);
150+
s.m_conditions.addAll(m_conditions);
151+
s.m_excludeFirst = m_excludeFirst;
152+
return s;
153+
}
154+
139155
/**
140156
* Specification of a column index to be sorted, associated with the
141157
* direction (ascending or descending) for that sort.

0 commit comments

Comments
 (0)