/** * Returns the current item, then shifts the list index. * @return current item */ public Object getNext() { Object o = getCurrent(); shift(); return o; }
/** * Returns a string representation of the current item or * <code>null</code> if the current item is null. <b>If {@link * #auto} is true, this will shift after returning the current * item</b>. * @return string representation of the current item */ public String toString() { Object o = list[index]; if (auto) { shift(); } if (o == null) { return null; } return o.toString(); } }
/** * Returns a new Alternator for the specified list with the specified * automatic shifting preference. * * @param auto See {@link Alternator#setAuto(boolean auto)}. * @param list The list of elements to alternate. * @return alternator */ public Alternator make(boolean auto, Object... list) { if (list == null || list.length == 0) { return null; } else if (list.length == 1 && list[0] instanceof Collection && ((Collection)list[0]).isEmpty()) { return null; } return new Alternator(auto, list); }