001package org.jdesktop.swingx.util; 002 003/** 004 * A simple separator for adding in between each element in a list. 005 * <p> 006 * <pre> 007 * for (String s : strings) { 008 * stringBuilder.append(separator.get().append(s); 009 * } 010 * </pre> 011 * 012 * @author Karl Schaefer 013 * @author Bruce Chapman (original idea) 014 * 015 * @param <T> 016 * the type of separator 017 */ 018public class Separator<T> { 019 private T next; 020 private T separator; 021 022 /** 023 * Constructs a separator with the specified initial value and remaining separator. 024 * 025 * @param initial 026 * the value to use for the first call 027 * @param separator 028 * the value to use after the first call 029 */ 030 public Separator(T initial, T separator) { 031 this.next = initial; 032 this.separator = separator; 033 } 034 035 /** 036 * Returns the current value of the separator. 037 * 038 * @return the separator value 039 */ 040 public T get() { 041 T result = next; 042 next = separator; 043 044 return result; 045 } 046}