EldiraSesto

Container

May 13th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. package container;
  2.  
  3. //import java.util.ArrayList;
  4. import java.util.Collection;
  5. import java.util.Iterator;
  6.  
  7. import util.searchable.ISearchFilter;
  8. import util.searchable.ISearchableByFilter;
  9.  
  10. public class Container<E> {
  11.    
  12.     public IContainerElement<E> head;
  13.    
  14.    
  15.     //constructor
  16.     public Container() {
  17.         this.head=null;
  18.     }
  19.    
  20.    
  21.     public boolean add (E e) throws NullPointerException {
  22.         if(e==null) {
  23.             throw new NullPointerException("You cant enter null");
  24.         }
  25.        
  26.        
  27.         ContainerElement<E> node = new ContainerElement<E>(e);
  28.         if(head==null) {
  29.             head=node;
  30.         }
  31.         else {
  32.             ContainerElement<E> n = (ContainerElement<E>) head;
  33.             while(n.hasNextElement()) {
  34.                 n=(ContainerElement<E>) n.getNextElement();
  35.             }
  36.             n.next=node;
  37.         }
  38.        
  39.         return true;
  40.     }
  41.     //probna funkcija
  42.     public void show() {
  43.        
  44.         IContainerElement<E> node = head;
  45.         while(node.hasNextElement()) {
  46.             System.out.println(node.getData());
  47.             node=node.getNextElement();    
  48.             }
  49.         System.out.println(node.getData());
  50.     }
  51.    
  52.    
  53.     public boolean addAll(Collection<? extends E> c) {
  54.         for(E e : c) {
  55.             ContainerElement<E> node = new ContainerElement<E>(e);
  56.            
  57.            
  58.         }
  59.        
  60.        
  61.         return true;
  62.     }
  63.    
  64.    
  65.     public void clear() {
  66.         ContainerElement<E> node = new ContainerElement<E>();
  67.        
  68.        
  69.     }
  70.    
  71.    
  72.    
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment