title: Returning a string value to a parameter with lambda in java
body: <p>I am doing a data generation project for football bettings and it works. To avoid using switch cases(as there is a huge amount of fixtures generated) I have used lambda expressions to simplify things. However I'm fairly new to Java and got stuck.</p>
  
  <p>I would like to match League names to league fixtures...</p>
  
  <p>eg. Liverpool - Man utd should return Premier League
  while
  Barcelona - Real Madrid should return La Liga</p>
  
  <pre><code>public static String english() {return "Premier League";}
  public static String spanish() {return "La Liga" ;}
  public static String french() {return "Ligue 1";}
  public static String german() {return "Bundesliga";}
  public static String italian() {return "Seria A";}
  </code></pre>
  
  <p>The values used for the lambda expressions are generated from here using fluttercode to generate fixtures.</p>
  
  <pre><code>String match = df.getItem(StaticTestData.match, 80, "Liverpool vs Manchester Utd")
  </code></pre>
  
  <p>I have used lambda expressions comparing part of string with .when()</p>
  
  <pre><code>DefineLeague.of(match)
                  .when("Arsenal", () -&gt; english()).when("Bournemouth", () -&gt;english()).when("Burnley", () -&gt; english())
                  .when("Chelsea", () -&gt; english()).when("Crystal Palace", () -&gt; english())
                  .when("Everton", () -&gt; english()).when("Hull City", () -&gt; english()).when("Leicester City", () -&gt; english())
                  .when("Liverpool", () -&gt; english()).when("Manchester City", () -&gt; english()).when("Manchester Utd", () -&gt; english())
                  .when("Middlesborough", () -&gt; english()).when("Southampton", () -&gt; english()).when("Stoke City", () -&gt; english())
                  .when("Sunderland", () -&gt; english()).when("Swansea", () -&gt; english()).when("Tottenham", () -&gt; english())
                  .when("Watford", () -&gt; english()).when("West Brom", () -&gt; english()).when("West Ham Utd", () -&gt; english());
  </code></pre>
  
  <p>And should return to </p>
  
  <pre><code>String leagueName = ;
  </code></pre>
  
  <p>The DefineLeague class is as follows:</p>
  
  <pre><code>package com.sportsRecommendationsData.data.dataGeneration;
  
  public class DefineLeague {
  
  private static final DefineLeague DEFINED_LEAGUE = new DefineLeague(null) {
      @Override
      public DefineLeague when(String subString, Runnable r) {
          return this;
      }
  
      @Override
      public void orElse(Runnable r) {
  
      }
  };
  
  private final String str;
  
  private DefineLeague(String str) {
      this.str = str;
  }
  
  public DefineLeague when(String subString, Runnable r) {
      if(str.contains(subString)) {
          r.run();
          return DEFINED_LEAGUE;
      }
      return this;
  }
  
  public void orElse(Runnable r) {
      r.run();
  }
  
  public static DefineLeague of(String str) {
      return new DefineLeague(str);
  }
  
  }
  </code></pre>
  
  <p>I would gladly appreciate any guidance on how to pass on the static values to parameter leagueName as I got stuck and I'm not sure I have done proper coding. Thanks in advance</p>