Advertisement
crassus9999

Untitled

Apr 16th, 2014
47
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.  
  6. /**
  7.  *
  8.  * @author Lukas
  9.  */
  10. public class MapView<Input, Output> extends View<Output> {
  11.    
  12.     final Pr2List<Input> source;
  13.     final Function<Input, Output> function;
  14.  
  15.     public MapView(Pr2List<Input> source, Function<Input, Output> function) {
  16.         this.source = source;
  17.         this.function = function;
  18.     }
  19.  
  20.     @Override
  21.     public Output head() {
  22.         return function.apply(source.head());
  23.     }
  24.    
  25.     @Override
  26.     public Pr2List<Output> tail() {
  27.         return new MapView(source.tail(), function);
  28.     }
  29.    
  30.     @Override
  31.     public boolean isEmpty() {
  32.         return source.isEmpty();
  33.     }
  34.    
  35.     @Override
  36.     public int size() {
  37.         return source.size();
  38.     }
  39.    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement