@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); }
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); }
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); } }
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); }
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(); }
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();  }