SeriesTruncator { public static <T> SeriesTruncator<T> create(Series<T> series, int maxSize) { if (maxSize < 0) { maxSize = 0; } int h = series.size(); if (h <= maxSize) { return new SeriesTruncator<>(series, false, h, 0); } int head = maxSize / 2 + maxSize % 2; int tail = maxSize - head; return new SeriesTruncator<>(series, true, head, tail); } private  SeriesTruncator(Series<T> series, boolean truncated, int head, int tail); static SeriesTruncator<T> create(Series<T> series, int maxSize); Series<T> head(); Series<T> tail(); boolean isTruncated(); int size();  }
@Test public void testCreate_Odd() { Series<Integer> s = new IntSequenceSeries(0, 10); SeriesTruncator<Integer> tr = SeriesTruncator.create(s, 5); assertSame(s, tr.series); assertTrue(tr.truncated); assertEquals(3, tr.head); assertEquals(2, tr.tail); }
@Test public void testCreate_Even() { Series<Integer> s = new IntSequenceSeries(0, 10); SeriesTruncator<Integer> tr = SeriesTruncator.create(s, 6); assertSame(s, tr.series); assertTrue(tr.truncated); assertEquals(3, tr.head); assertEquals(3, tr.tail); }
@Test public void testCreate_Two() { Series<Integer> s = new IntSequenceSeries(0, 10); SeriesTruncator<Integer> tr = SeriesTruncator.create(s, 2); assertSame(s, tr.series); assertTrue(tr.truncated); assertEquals(1, tr.head); assertEquals(1, tr.tail); }
@Test public void testCreate_One() { Series<Integer> s = new IntSequenceSeries(0, 10); SeriesTruncator<Integer> tr = SeriesTruncator.create(s, 1); assertSame(s, tr.series); assertTrue(tr.truncated); assertEquals(1, tr.head); assertEquals(0, tr.tail); }
@Test public void testCreate_Zero() { Series<Integer> s = new IntSequenceSeries(0, 10); SeriesTruncator<Integer> tr = SeriesTruncator.create(s, 0); assertSame(s, tr.series); assertTrue(tr.truncated); assertEquals(0, tr.head); assertEquals(0, tr.tail); }