-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding Series.concat functionality to concatenate series
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
dflib/src/main/java/com/nhl/dflib/concat/SeriesConcat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.nhl.dflib.concat; | ||
|
||
import com.nhl.dflib.Series; | ||
import com.nhl.dflib.series.ArraySeries; | ||
|
||
public class SeriesConcat { | ||
|
||
public static <T> Series<T> concat(Series<? extends T>... concat) { | ||
|
||
int h = 0; | ||
int n = concat.length; | ||
for (Series<?> s : concat) { | ||
h += s.size(); | ||
} | ||
|
||
T[] data = (T[]) new Object[h]; | ||
for (int i = 0, ai = 0; i < n; i++) { | ||
int len = concat[i].size(); | ||
concat[i].copyTo(data, 0, ai, len); | ||
ai += len; | ||
} | ||
|
||
return new ArraySeries<>(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.nhl.dflib; | ||
|
||
import com.nhl.dflib.unit.SeriesAsserts; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Collection; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
@RunWith(Parameterized.class) | ||
public class Series_ConcatTest extends BaseSeriesTest { | ||
|
||
public Series_ConcatTest(SeriesTypes seriesType) { | ||
super(seriesType); | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> data() { | ||
return ALL_SERIES_TYPES; | ||
} | ||
|
||
@Test | ||
public void testConcat_None() { | ||
Series<String> s = createSeries("a", "b"); | ||
assertSame(s, s.concat()); | ||
} | ||
|
||
@Test | ||
public void testConcat_Self() { | ||
Series<String> s = createSeries("a", "b"); | ||
Series<String> c = s.concat(s); | ||
new SeriesAsserts(c).expectData("a", "b", "a", "b"); | ||
} | ||
|
||
@Test | ||
public void testConcat() { | ||
Series<String> s1 = createSeries("m", "n"); | ||
Series<String> s2 = createSeries("a", "b"); | ||
Series<String> s3 = createSeries("d", "c"); | ||
|
||
Series<String> c = s1.concat(s2, s3); | ||
new SeriesAsserts(c).expectData("m", "n", "a", "b", "d", "c"); | ||
} | ||
} | ||
|