title: How to convert java 8 map, filter and streams to scala?
body: <p>I am very new to scala trying to understand by changing the equivalent java to scala so that I get better understanding. </p>
  
  <p>How to convert java 8 map, filter and streams to scala ? </p>
  
  <p>I have the following java 8 code which I am trying to convert to Scala :</p>
  
  <pre><code> public Set&lt;String&gt; getValidUsages(String itemId, long sNo, Date timeOfAccess) {                                                     
       Set&lt;String&gt; itemSet = Sets.newHashSet();                                                                                                   
       TestWindows testWindows = items.get(itemId).getTestWindows();                                                          
  
       final boolean isTV = existsEligibleTestWindow(testWindows.getTV(), timeOfAccess);                                       
       if (isTV) {                                                                                                                              
           itemSet.add(TV);                                                                                                              
       } else {                                                                                                                                    
           final boolean isCableUseable = existsEligibleTestWindow(testWindows.getCableUse(), timeOfAccess);                         
           final boolean isWifi = existsEligibleTestWindow(testWindows.getWifi(), timeOfAccess);                               
           if (isCableUseable || isWifi) {                                                                                                     
               itemSet.add(MOVIE);                                                                                                           
           }                                                                                                                                       
       }                                                                                                                                           
  
       if (testWindows.getUsageIds() != null) {                                                                                           
           itemSet.addAll(testWindows.getUsageIds()                                                                                      
                   .entrySet()                                                                                                                     
                   .stream()                                                                                                                       
                   .filter(entry -&gt; existsEligibleTestWindow(entry.getValue(), timeOfAccess))                                               
                   .map(Map.Entry::getKey)                                                                                                         
                   .collect(Collectors.toSet()));                                                                                                  
       }                                                                                                                                           
  
       return itemSet;                                                                                                                            
   }                                                                                                                                               
  
   private boolean existsEligibleTestWindow(List&lt;TestWindow&gt; windows, Date timeOfAccess) {                                           
       if (windows != null) {                                                                                                                      
           return windows.stream()                                                                                                                 
                   .filter(w -&gt; withinDateRange(timeOfAccess, w))                                                                                  
                   .findAny()                                                                                                                      
                   .isPresent();                                                                                                                   
       }                                                                                                                                           
       return false;                                                                                                                               
   }                                                                                                                                               
  
   private boolean withinDateRange(Date toCheck, TestWindow window) {                                                                       
       return toCheck.after(window.getStartTime()) &amp;&amp; toCheck.before(window.getEndTime());                                                         
   }  
  </code></pre>
  
  <p>I tried :</p>
  
  <pre><code> def withinDateRange(toCheck: Date, window: TestWindow): Boolean = {
      toCheck.after( window.getStartTime ) &amp;&amp; toCheck.before( window.getEndTime )
    }
  
  
    def getValidUsages(itemId: String, sNo: Long, timeOfAccess: Date): Set[String] = {
      var itemSet = Sets.newHashSet()
      val testWindows = items.value(itemId).getTestWindows
      val isTV = existsEligibleTestWindow(testWindows.get(0).getTV, timeOfAccess)
      if (isTV) {
        itemSet += TV
      } else {
        val isCableUseable = existsEligibleTestWindow(testWindows.get(0).getCableUse, timeOfAccess)
        val isWifi = existsEligibleTestWindow(testWindows.get(0).getWifi, timeOfAccess)
        if (isCableUseable || isWifi) {
          itemSet += MOVIE
        }
      }
      if (testWindows.get(0).getUsageIds != null) {
        itemSet.addAll(testWindows.get(0).getUsageIds.entrySet().stream()
          .filter((x) =&gt; existsEligibleTestWindow(x._2, timeOfAccess)).map(x =&gt; Map.Entry._1 )
          .collect(Collectors.toSet()))
      }
      itemSet
    }
  
  
     def existsEligibleConsumptionWindow(windows: List[ConsumptionWindow], timeOfAccess: Date): Boolean = {
  if (windows != null) {
    return windows.exists((x) =&gt; withinDateRange(timeOfAccess, x))
  }
  false
  }
  </code></pre>
  
  <p>But getting error while doing filter and stream. Can some one point to direct direction ? Any references ?  I am getting error on getValidUsages : </p>
  
  <pre><code> compile error “cannot resolve reference project with such signature
  </code></pre>