ActionBufferList.java |
/* Copyright (C) 2009 CSE,IIT Bombay http://www.cse.iitb.ac.in This file is part of the ConStore open source storage facility for concept-nets. ConStore is free software and distributed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License; you can copy, distribute and transmit the work with the work attribution in the manner specified by the author or licensor. You may not use this work for commercial purposes and may not alter, transform, or build upon this work. Please refer the legal code of the license, available at http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode ConStore is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ package iitb.con.ds; import java.util.ArrayList; import java.util.List; /** * ActionBufferList is state buffer for performing actions to the database. * The buffer holds the objects along with its action information. * * @author Prathab K * */ public class ActionBufferList<T> { /** Size of the add action list size */ private int addListSize; /** Size of the update action list size */ private int updateListSize; /** Size of the update action list size */ private int metaUpdateListSize; /** Size of the remove action list size */ private int removeListSize; /** Add action list */ private List<T> addList; /** Update action list */ private List<T> updateList; /** Meta item Update action list */ private List<T> metaUpdateList; /** Remove action list */ private List<T> removeList; public static enum Action {ADD, UPDATE, REMOVE, UPDATE_META }; /** * Initializes the action buffers */ public ActionBufferList(){ addList = new ArrayList<T>(); updateList = new ArrayList<T>(); removeList = new ArrayList<T>(); metaUpdateList = new ArrayList<T>(); } /** Adds the object to the respective action buffer * * @param o object to be added to buffer * @param size object size * @param action action on the object * @return <tt>true</tt> on success */ public boolean add(Object o, int size , Action action) { switch(action) { case ADD: addListSize += size; return addList.add((T)o); case UPDATE: updateListSize += size; return updateList.add((T)o); case UPDATE_META: metaUpdateListSize += size; return metaUpdateList.add((T)o); case REMOVE: removeListSize += size; return removeList.add((T)o); } return false; } /** * Clears the action buffers and resets the size to zero */ public void clear(){ addListSize = 0; addList.clear(); updateListSize = 0; updateList.clear(); metaUpdateListSize = 0; metaUpdateList.clear(); removeListSize = 0; removeList.clear(); } /** * Returns the add action list * @return objects with add action as List */ public List<T> getAddList() { return addList; } /** * Returns the update action list * @return objects with update action as List */ public List<T> getUpdateList() { return updateList; } /** * Returns the meta update action list * @return objects with update action as List */ public List<T> getMetaUpdateList() { return metaUpdateList; } /** * Returns the update action list * @return objects with update action as List */ public List<T> getRemoveList() { return removeList; } }