/**
* @author Hammed Abiola
*@date 24/02/2012
*/
/**
* General csv collection to be subclassed by all Collections
* (EventsCollection, SettingsCollection, TasksCollection etc)
*/
package calendar;
import java.util.ArrayList;
import javax.naming.directory.InvalidAttributesException;
public abstract class Collection<CSVSTR extends CsvStructure> {
protected ArrayList<CSVSTR> m_data;
/*
*This method adds valid entries to the CSV
*/
public void Add(CSVSTR elem) {
m_data.add(elem);
}
/*
*This method removes invalid entries
*/
public void Remove(int idx) throws InvalidAttributesException {
if(idx < 0 || idx >= m_data.size()) {
throw new InvalidAttributesException("Can't remove this element!");
}
m_data.remove(idx);
}
/*
*This converts the arraylist string to CSV format
*/
public String ToCSV() {
String csv = "";
for(int i = 0; i < m_data.size(); i++) {
if(i > 0) {
csv += System.getProperty("line.separator");
}
csv += m_data.get(i).ToCSV();
}
return csv;
}
public int size() {
return m_data.size();
}
public CSVSTR get(int i) {
return m_data.get(i);
}
}