PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/acide/src/acide/configuration/utils/ObjectList.java

http://acide-0-8-release-2010-2011.googlecode.com/
Java | 193 lines | 62 code | 22 blank | 109 comment | 4 complexity | e0a67ee7767efa30ada91c8cf4ce1bdc MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, CPL-1.0
  1. /*
  2. * ACIDE - A Configurable IDE
  3. * Official web site: http://acide.sourceforge.net
  4. *
  5. * Copyright (C) 2007-2011
  6. * Authors:
  7. * - Fernando Sáenz Pérez (Team Director).
  8. * - Version from 0.1 to 0.6:
  9. * - Diego Cardiel Freire.
  10. * - Juan José Ortiz Sánchez.
  11. * - Delfín Rupérez Ca?as.
  12. * - Version 0.7:
  13. * - Miguel Martín Lázaro.
  14. * - Version 0.8:
  15. * - Javier Salcedo Gómez.
  16. *
  17. * This program is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. */
  30. package acide.configuration.utils;
  31. import java.io.Serializable;
  32. import java.util.ArrayList;
  33. import acide.log.AcideLog;
  34. /**
  35. * ACIDE - A Configurable IDE serializable object list of the lexicon of the
  36. * application.
  37. *
  38. * @project ACIDE - A Configurable IDE (c).
  39. * @version 0.8.
  40. */
  41. public class ObjectList implements Serializable {
  42. /**
  43. * ACIDE - A Configurable IDE serializable object list serial version UID.
  44. */
  45. private static final long serialVersionUID = 1L;
  46. /**
  47. * ACIDE - A Configurable IDE object array list.
  48. */
  49. private ArrayList<Object> _list;
  50. /**
  51. * Creates a new ACIDE - A Configurable IDE serializable object list.
  52. */
  53. public ObjectList() {
  54. super();
  55. // Creates the list of objects
  56. _list = new ArrayList<Object>();
  57. }
  58. /**
  59. * Returns the is empty flag.
  60. *
  61. * @return The is empty flag.
  62. */
  63. public boolean isEmpty() {
  64. return _list.isEmpty();
  65. }
  66. /**
  67. * Insert an object into the object array list at the position given as a
  68. * parameter.
  69. *
  70. * @param index
  71. * index to insert.
  72. * @param object
  73. * object to insert.
  74. */
  75. public void insert(int index, Object object) {
  76. try {
  77. if (_list.get(index) != null)
  78. _list.set(index, object);
  79. } catch (IndexOutOfBoundsException exception) {
  80. try {
  81. _list.add(index, object);
  82. } catch (IndexOutOfBoundsException exception2) {
  83. // Updates the log
  84. AcideLog.getLog().error(exception2.getMessage());
  85. exception2.printStackTrace();
  86. }
  87. }
  88. }
  89. /**
  90. * Returns the object from the object array list at the index given as a
  91. * parameter.
  92. *
  93. * @param index
  94. * index to get.
  95. *
  96. * @return the object from the object array list at the index given as a
  97. * parameter.
  98. */
  99. public Object getObjectAt(int index) {
  100. try {
  101. return (Object) _list.get(index);
  102. } catch (IndexOutOfBoundsException exception) {
  103. // Updates the log
  104. AcideLog.getLog().error(exception.getMessage());
  105. exception.printStackTrace();
  106. return null;
  107. }
  108. }
  109. /**
  110. * Removes an element at the index of the object array list given as a
  111. * parameter.
  112. *
  113. * @param index
  114. * index to remove.
  115. */
  116. public void removeAt(int index) {
  117. try {
  118. // Removes the object from the list specified by the index
  119. _list.remove(index);
  120. _list.trimToSize();
  121. } catch (IndexOutOfBoundsException exception) {
  122. // Updates the log
  123. AcideLog.getLog().error(exception.getMessage());
  124. exception.printStackTrace();
  125. }
  126. }
  127. /**
  128. * Returns the object array list size.
  129. *
  130. * @return the object array list size.
  131. */
  132. public int size() {
  133. return _list.size();
  134. }
  135. /**
  136. * Clears the object array list.
  137. */
  138. public void clear() {
  139. _list.clear();
  140. }
  141. /**
  142. * Adds an object to the list.
  143. *
  144. * @param object
  145. * new object to add.
  146. */
  147. public void insert(Object object) {
  148. _list.add(object);
  149. }
  150. /**
  151. * Sets a new value to the object in the index specified.
  152. *
  153. * @param index
  154. * index to set.
  155. * @param object
  156. * new value to set.
  157. */
  158. public void setValueAt(int index, String object) {
  159. _list.set(index, object);
  160. }
  161. /**
  162. * Sets a new value to the object given as a parameter.
  163. *
  164. * @param object
  165. * new value to set.
  166. */
  167. public void setValue(Object object) {
  168. if (_list.indexOf(object) != -1)
  169. _list.set(_list.indexOf(object), object);
  170. }
  171. }