Advertisement
crassus9999

Untitled

Apr 15th, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package cz.cvut.k36.pr2.hw.hw06.impl;
  2.  
  3. import cz.cvut.k36.pr2.hw.hw06.Function;
  4. import cz.cvut.k36.pr2.hw.hw06.Pr2List;
  5. import cz.cvut.k36.pr2.hw.hw06.Predicate;
  6.  
  7. /**
  8.  *
  9.  * @author Lukas
  10.  */
  11. public class FilterView<T> extends View<T> {
  12.    
  13.     final Pr2List<T> source;
  14.     final Predicate<T> predicate;
  15.  
  16.     public FilterView(Pr2List<T> source, Predicate<T> predicate) {
  17.         this.source = source;
  18.         this.predicate = predicate;
  19.     }
  20.  
  21.     @Override
  22.     public T head() {
  23.         return predicate.apply(source.head());
  24.     }
  25.    
  26.     @Override
  27.     public Pr2List<T> tail() {
  28.         return new FilterView(source.tail(), predicate);
  29.     }
  30.    
  31.     @Override
  32.     public boolean isEmpty() {
  33.         return source.isEmpty();
  34.     }
  35.    
  36.     @Override
  37.     public int size() {
  38.         return this.size();
  39.     }
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement