DataSeriesImpl implements DataSeries<E> { public void insertData(E e) { data.add(indexOf(e.getDate(), false), (DataPointImpl) e); } DataSeriesImpl(Period period); @Override Period getPeriod(); @Override DateTime getStart(); @Override DateTime getEnd(); @SuppressWarnings("unchecked") @Override E getFirst(); @SuppressWarnings("unchecked") @Override E getLast(); @Override int size(); @SuppressWarnings("unchecked") @Override E get(int index); @SuppressWarnings("unchecked") @Override E forDate(DateTime date); @Override int closestIndexOf(Time time, int idxLower, int idxUpper, boolean compareAtRes); @Override int indexOf(DateTime date, boolean exactOnly); int indexOf(DateTime date, int high, int low, boolean exactOnly); @SuppressWarnings("unchecked") @Override Iterator<E> iterator(); @Override @SuppressWarnings("unchecked") Iterator<E> reverseIterator(); @Override @SuppressWarnings("unchecked") E[] toArray(); void insertData(E e); @Override boolean add(E e); @Override void add(int index, E e); @Override E set(int index, E e); @Override @SuppressWarnings("unchecked") E remove(int index); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override T[] toArray(T[] a); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @SuppressWarnings("unchecked") @Override boolean addAll(Collection<? extends E> c); @SuppressWarnings("unchecked") @Override boolean addAll(int index, Collection<? extends E> c); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override void clear(); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); @SuppressWarnings("unchecked") @Override ListIterator<E> listIterator(); @SuppressWarnings("unchecked") @Override ListIterator<E> listIterator(int index); @SuppressWarnings("unchecked") @Override List<E> subList(int fromIndex, int toIndex);  }
@Test public void testInsertData() { final DateTime dt = new DateTime(2013, 12, 10, 9, 0, 0, 0); final DateTime dt2 = new DateTime(2013, 12, 10, 9, 0, 0, 3); final DateTime dt3 = new DateTime(2013, 12, 10, 9, 0, 0, 5); final DateTime dt4 = new DateTime(2013, 12, 10, 9, 0, 0, 7); final DateTime dt5 = new DateTime(2013, 12, 10, 9, 0, 0, 9); final DateTime dt6 = new DateTime(2013, 12, 10, 9, 0, 0, 11); final DateTime dt7 = new DateTime(2013, 12, 10, 9, 0, 0, 13); final DateTime dt8 = new DateTime(2013, 12, 10, 9, 0, 0, 15); final DateTime dt9 = new DateTime(2013, 12, 10, 9, 0, 1, 0); final DateTime dt10 = new DateTime(2013, 12, 10, 9, 0, 1, 2); final DateTime dt11 = new DateTime(2013, 12, 10, 9, 0, 1, 4); final DateTime dt12 = new DateTime(2013, 12, 10, 9, 0, 1, 6); final DateTime dt13 = new DateTime(2013, 12, 10, 9, 0, 2, 0); final DateTime dt14 = new DateTime(2013, 12, 10, 9, 0, 2, 2); final DateTime dt15 = new DateTime(2013, 12, 10, 9, 0, 2, 4); final DateTime dt16 = new DateTime(2013, 12, 10, 12, 0, 0, 147); final DateTime t = new DateTime(2013, 12, 10, 11, 59, 58, 1); final Period p = new Period(PeriodType.TICK, 1); final DataSeriesImpl<DataPointImpl> ds = new DataSeriesImpl<DataPointImpl>(p); ds.insertData(new BarImpl(null, dt, p, null, null, null, null, null, null)); assertEquals(1, ds.size()); assertEquals(0, ds.indexOf(dt, false)); ds.insertData(new BarImpl(null, dt2, p, null, null, null, null, null, null)); assertEquals(2, ds.size()); assertEquals(1, ds.indexOf(dt2, false)); ds.insertData(new BarImpl(null, dt3, p, null, null, null, null, null, null)); assertEquals(3, ds.size()); assertEquals(2, ds.indexOf(dt3, false)); ds.insertData(new BarImpl(null, dt4, p, null, null, null, null, null, null)); assertEquals(4, ds.size()); assertEquals(3, ds.indexOf(dt4, false)); ds.insertData(new BarImpl(null, dt5, p, null, null, null, null, null, null)); assertEquals(5, ds.size()); assertEquals(4, ds.indexOf(dt5, false)); ds.insertData(new BarImpl(null, dt6, p, null, null, null, null, null, null)); assertEquals(6, ds.size()); assertEquals(5, ds.indexOf(dt6, false)); ds.insertData(new BarImpl(null, dt7, p, null, null, null, null, null, null)); assertEquals(7, ds.size()); assertEquals(6, ds.indexOf(dt7, false)); ds.insertData(new BarImpl(null, dt8, p, null, null, null, null, null, null)); assertEquals(8, ds.size()); assertEquals(7, ds.indexOf(dt8, false)); ds.insertData(new BarImpl(null, dt9, p, null, null, null, null, null, null)); assertEquals(9, ds.size()); assertEquals(8, ds.indexOf(dt9, false)); ds.insertData(new BarImpl(null, dt10, p, null, null, null, null, null, null)); assertEquals(10, ds.size()); assertEquals(9, ds.indexOf(dt10, false)); ds.insertData(new BarImpl(null, dt11, p, null, null, null, null, null, null)); assertEquals(11, ds.size()); assertEquals(10, ds.indexOf(dt11, false)); ds.insertData(new BarImpl(null, dt12, p, null, null, null, null, null, null)); assertEquals(12, ds.size()); assertEquals(11, ds.indexOf(dt12, false)); ds.insertData(new BarImpl(null, dt13, p, null, null, null, null, null, null)); assertEquals(13, ds.size()); assertEquals(12, ds.indexOf(dt13, false)); ds.insertData(new BarImpl(null, dt14, p, null, null, null, null, null, null)); assertEquals(14, ds.size()); assertEquals(13, ds.indexOf(dt14, false)); ds.insertData(new BarImpl(null, dt15, p, null, null, null, null, null, null)); assertEquals(15, ds.size()); assertEquals(14, ds.indexOf(dt15, false)); ds.insertData(new BarImpl(null, dt16, p, null, null, null, null, null, null)); assertEquals(16, ds.size()); assertEquals(15, ds.indexOf(dt16, false)); ds.insertData(new BarImpl(null, t, p, null, null, null, null, null, null)); assertEquals(17, ds.size()); assertEquals(15, ds.indexOf(t, false)); assertEquals(16, ds.indexOf(dt16, false)); System.out.println(dt); }