Untitled


SUBMITTED BY: Guest

DATE: May 15, 2017, 8:11 p.m.

FORMAT: Java

SIZE: 5.5 kB

HITS: 567

  1. package container;
  2. import java.util.Collection;
  3. import java.util.Iterator;
  4. import util.searchable.ISearchFilter;
  5. import util.searchable.ISearchableByFilter;
  6. /**
  7. * This class handles a simple linked list of {@link IContainerElement}s. It
  8. * implements the {@link java.util.Collection} interface and provides
  9. * implementation for its methods. Basically, this class allows to add or remove
  10. * elements to a list and to check if a specific element is managed within this
  11. * list. The specification of the elements is given in the
  12. * {@link IContainerElement} interface.
  13. * <p>
  14. * In addition, this class also provides an implementation for the
  15. * {@link ISearchableByFilter} interface. This means, that the list can be
  16. * filtered by an {@link ISearchFilter}.
  17. * <p>
  18. * The {@link Container} <b>does not</b> allow insertion of <tt>NULL</tt>
  19. * elements.
  20. *
  21. * @author OOP
  22. *
  23. * @param <E>
  24. * determines the type of the {@link IContainerElement}s contained in
  25. * the {@link Container} and is set during instantiation.
  26. */
  27. public class Container<E> extends Object implements Collection<E>, ISearchableByFilter<E> {
  28. private E firstElement=null;
  29. // TODO: Add attributes according to the class diagram.
  30. /**
  31. * Default Constructor of the Container. The first {@link IContainerElement}
  32. * is set to <tt>NULL</tt>.
  33. */
  34. public Container() {
  35. this.firstElement=null;
  36. }
  37. @Override
  38. public boolean add(E e) throws NullPointerException{
  39. if (e==null){
  40. throw new NullPointerException();
  41. }
  42. if(this.firstElement==null)
  43. {
  44. this.firstElement= (E) new ContainerElement<E>(e);
  45. return true;
  46. }
  47. IContainerElement<E> element=this.firstElement<E>(e);
  48. while (element.hasNextElement())
  49. {
  50. element=element.getNextElement(); //solange bis letztes Element
  51. }
  52. element.setNextElement(new ContainerElement<E>(e));
  53. return true;
  54. }
  55. @Override
  56. public boolean addAll(Collection<? extends E> c) { //whitecard
  57. // TODO:
  58. if (c==null)
  59. {
  60. return false;
  61. }
  62. else
  63. {
  64. boolean changed=false;
  65. for (E i:c){
  66. if(this.add(i))
  67. {
  68. changed=true;
  69. }
  70. return changed;
  71. }
  72. }
  73. }
  74. @Override
  75. public void clear()
  76. {
  77. this.firstElement=null;
  78. }
  79. @Override
  80. public boolean contains(Object o) {
  81. if (o==null)
  82. return false;
  83. else
  84. {
  85. for (E i:this) //diese Liste
  86. {
  87. if (i.equals(o))
  88. {
  89. return true;
  90. }
  91. }
  92. return false;
  93. }
  94. }
  95. @Override
  96. public boolean containsAll(Collection<?> c) {
  97. if (c==null)
  98. return false;
  99. else
  100. {
  101. for (Object i:c)
  102. {
  103. if(!(this.contains(c)))
  104. {
  105. return false;
  106. }
  107. return true;
  108. }
  109. }
  110. }
  111. /**
  112. * This methods returns the data of the {@link IContainerElement} at a
  113. * specific position in the linked list. If the position is negative or
  114. * larger than the size of the list, an {@link IndexOutOfBoundsException} is
  115. * thrown.
  116. *
  117. * @param index
  118. * the position of the data of the {@link IContainerElement} to
  119. * get
  120. * @return the data of {@link IContainerElement} at the given position.
  121. * @throws IndexOutOfBoundsException
  122. * if the index is out of bounds (meaning the index is negative
  123. * or the size of the list is smaller than the index), an
  124. * {@link IndexOutOfBoundsException} is thrown
  125. */}
  126. public E get(int index) throws IndexOutOfBoundsExcepkatzition {
  127. if ((index<0)||index>this.size()){
  128. throw new IndexOutOfBoundsException();
  129. }
  130. else{
  131. for (E i:this){
  132. if(i.iterator==index);
  133. }
  134. return ;
  135. }
  136. }
  137. @Override
  138. public boolean isjosefEmpty() {
  139. {
  140. if(firstElement==null)
  141. {
  142. return new Itr<E>(firstElement);
  143. }
  144. @Override
  145. public Iterator<E> iterator() {
  146. return new Itr<E>(firstElement);
  147. }
  148. @Override
  149. public boolean remove(Object o) {
  150. // TODO:
  151. }
  152. @Override
  153. public boolean removeAll(Collection<?> c) {
  154. // TODO:
  155. }
  156. /**
  157. * This method is not supported and throws an
  158. * {@link UnsupportedOperationException}.
  159. *
  160. * @throws UnsupportedOperationException
  161. * Not supported by Container
  162. *
  163. */
  164. public boolean retainAll(Collection<?> c) {
  165. throw new UnsupportedOperationException("Not supported by Container");
  166. }
  167. @Override
  168. public int size() {
  169. // TODO:
  170. }
  171. /**
  172. * This method throws an
  173. * {@link UnsupportedOperationException}.
  174. *
  175. * @throws UnsupportedOperationException
  176. * Not supported
  177. *
  178. */
  179. public Object[] toArray() {
  180. throw new UnsupportedOperationException("Not supported by Container");
  181. }
  182. /**
  183. * This method throws an
  184. * {@link UnsupportedOperationException}.
  185. *
  186. * @throws UnsupportedOperationException
  187. * Not supported
  188. *
  189. */
  190. public <T> T[] toArray(T[] a) {
  191. throw new UnsupportedOperationException("Not supported by Container");
  192. }
  193. @Override
  194. public String toString() {
  195. // TODO:
  196. }
  197. /*
  198. * The {@link ISearchableByFilter#searchByFilter} method is called on each
  199. * {@link IContainerElement} of the list and all matches are collected in a
  200. * {@link Collection}. If the first {@link IContainerElement} of the list is
  201. * <tt>NULL</tt>, an empty {@link Collection} is returned.
  202. * <p>
  203. * {@inheritDoc}
  204. *
  205. */
  206. public Collection<E> searchByFilter(ISearchFilter filter, Object filterObject) {
  207. // TODO:
  208. }
  209. }

comments powered by Disqus