/** * {@inheritDoc} */ public boolean isAfterLast() throws Exception { checkNotClosed( "isAfterLast()" ); return index == end; }
/** * {@inheritDoc} */ public void afterLast() throws Exception { checkNotClosed( "afterLast()" ); this.index = end; }
/** * {@inheritDoc} */ public void beforeFirst() throws Exception { checkNotClosed( "beforeFirst()" ); this.index = -1; }
/** * {@inheritDoc} */ public boolean isBeforeFirst() throws Exception { checkNotClosed( "isBeforeFirst()" ); return index == -1; }
/** * {@inheritDoc} */ public boolean isFirst() throws Exception { checkNotClosed( "isFirst()" ); return list.size() > 0 && index == start; }
/** * {@inheritDoc} */ public boolean isLast() throws Exception { checkNotClosed( "isLast()" ); return list.size() > 0 && index == end - 1; }
/** * {@inheritDoc} */ public boolean first() throws Exception { checkNotClosed( "first()" ); if ( list.size() > 0 ) { index = start; return true; } return false; }
/** * {@inheritDoc} */ public boolean last() throws Exception { checkNotClosed( "last()" ); if ( list.size() > 0 ) { index = end - 1; return true; } return false; }
/** * {@inheritDoc} */ public boolean previous() throws Exception { checkNotClosed( "previous()" ); // if parked at -1 we cannot go backwards if ( index == -1 ) { return false; } // if the index moved back is still greater than or eq to start then OK if ( index - 1 >= start ) { index--; return true; } // if the index currently less than or equal to start we need to park it at -1 and return false if ( index <= start ) { index = -1; return false; } if ( list.size() <= 0 ) { index = -1; } return false; }
/** * {@inheritDoc} */ public E get() throws Exception { checkNotClosed( "get()" ); if ( index < start || index >= end ) { throw new IOException( I18n.err( I18n.ERR_02009 ) ); } return list.get( index ); }
/** * {@inheritDoc} */ public boolean next() throws Exception { checkNotClosed( "next()" ); // if parked at -1 we advance to the start index and return true if ( list.size() > 0 && index == -1 ) { index = start; return true; } // if the index plus one is less than the end then increment and return true if ( list.size() > 0 && index + 1 < end ) { index++; return true; } // if the index plus one is equal to the end then increment and return false if ( list.size() > 0 && index + 1 == end ) { index++; return false; } if ( list.size() <= 0 ) { index = end; } return false; }
/** * {@inheritDoc} */ public void after( E element ) throws Exception { checkNotClosed( "after()" ); if ( comparator == null ) { throw new IllegalStateException(); } // handle some special cases if ( list.size() == 0 ) { return; } else if ( list.size() == 1 ) { if ( comparator.compare( element, list.get( 0 ) ) >= 0 ) { afterLast(); } else { beforeFirst(); } } // TODO might want to add some code here to utilize the comparator throw new UnsupportedOperationException( I18n.err( I18n.ERR_02008 ) ); }
/** * @throws IllegalStateException if the underlying list is not sorted * and/or a comparator is not provided. */ public void before( E element ) throws Exception { checkNotClosed( "before()" ); if ( comparator == null ) { throw new IllegalStateException(); } // handle some special cases if ( list.size() == 0 ) { return; } else if ( list.size() == 1 ) { if ( comparator.compare( element, list.get( 0 ) ) <= 0 ) { beforeFirst(); } else { afterLast(); } } // TODO might want to add some code here to utilize the comparator throw new UnsupportedOperationException( I18n.err( I18n.ERR_02008 ) ); }