package se.chalmers.dat255.grupp12; import java.util.List; import java.sql.SQLException; import java.util.ArrayList; /** * Created with IntelliJ IDEA. * User: Patrik * Date: 10/10/13 * Time: 3:09 PM * To change this template use File | Settings | File Templates. */ public class ClientChangeList { private List<Modification.Change> idChanges = new ArrayList<Modification.Change>(); private List<TaskList> userLists = new ArrayList<TaskList>(); public ClientChangeList(){} /** * Adds a Change to to the list of idChanges * @param oldValue - The old id * @param newValue - The new id */ public void addIdChange(int oldValue, int newValue) { Modification.Change change = new Modification.Change("listIdChange", Integer.toString(oldValue), Integer.toString(newValue)); idChanges.add(change); } /** * Create a list containing all the lists a user has access to * * @param user - The user */ public void setUserLists(User user) { try { userLists = Database.getInstance().getLists(user); } catch (SQLException e) { e.printStackTrace(); } catch (DataNotFoundException e) { e.printStackTrace(); } } /** * Checks if the id of a modification differs from the new id * and in that case returns the new id * * @param oldId - The old id of the modification * @return - The new id if its different from the current one, otherwise the old id */ public int getNewId(int oldId) { for(Modification.Change change : idChanges) { if(Integer.parseInt(change.getFrom()) == oldId) { return Integer.parseInt(change.getTo()); } } return oldId; } }