I have a data generation project and I need to match the data generated to another variable.
eg. Man utd - liverpool returns Premier League barca - real madrid returns La Liga
I need to use a switch case method generateLeague which should act on String match variable from class MatchEvent. The coding I have done does not seem to catch either the MatchEvent match value generated and does not return a string as String leagueName = generateLeague does not receive a String. It says that generateLeague (String) in BetEvent cannot be applied.
This is the MatchEvent class with data generation (This does work).
/**
* Mock a transaction for testing purposes
*/
public MatchEvent generateEvent() {
try {
DataFactory df = new DataFactory();
// BetEvent
int betID = df.getNumberBetween(220000000, Integer.MAX_VALUE);
float odds = df.getNumberBetween((int) 1.05, 30);
// Selections
String selectionID = UUID.randomUUID().toString();
// Market
// Event
String eventID = UUID.randomUUID().toString();
String match = df.getItem(StaticTestData.match, 80, "Liverpool vs Manchester Utd"); // should match league and categoryID
//SubCategory
// category
final int categoryID = 1; // LeagueID by number eg. 1 is for LaLiga, should match MatchLeague and Match
final String categoryName = "Football";
// Subcategory
String subCategoryID = UUID.randomUUID().toString();
String leagueName = generateLeague(); // should match Match and category ID
final String parentSubCategory = null;
// market
final String name = null;
float matchOdds = df.getNumberBetween((int) 1.05, 30); // since focusing on prematch should keep maxNo 20?
//betEvent
float stake = df.getNumberBetween(0, 1200);
boolean mobile = Math.random() < 0.5;
final String providerName = "EPBetsSportsbook";
float totalOdds = matchOdds;
float totalStake = stake;
String nation = df.getItem(StaticTestData.countryCodes); // should make it as realistic as possible
final String currency = "EUR";
Date date = new Date();
java.text.DateFormat formatter = new java.text.SimpleDateFormat("MM-dd-yyyy");
String calendarDate = formatter.format(date);
return new MatchEvent(betID, odds, selectionID, eventID, match, categoryID, categoryName, subCategoryID,
leagueName, parentSubCategory, name, matchOdds, stake, mobile, providerName,
totalOdds, totalStake, nation, date, currency, calendarDate);
} catch (Exception e) {
// For demo purposes, we are not going to log errors/send to a kafka stream
throw e;
}
}
And this is the generateLeague method using Switch case statements.
public static String generateLeague(String match) {
String club = null;
String league;
if (match.toLowerCase().contains(" ")) {
club = match.substring(0, match.indexOf(" "));
}
switch (club) {
case "arsenal":
case "bournemouth":
case "burnley":
case "chelsea":
case "crystal":
case "everton":
case "hull":
case "leicester":
case "liverpool":
case "manchester":
case "middlesborough":
case "southampton":
case "stoke":
case "sunderland":
case "swansea":
case "tottenham":
case "watford":
case "west":
league = "Premier League";
break;
case "atletico":
case "barcelona":
case "real":
league = "La Liga";
break;
default: league = "";
}
return league;
}
I would appreciate and thank you in advance for any guidance.
generateEventmethod to reproduce your issue) and make sure thatclubreally is one of these cases (use a debugger). You may also want to read: minimal reproducible example.Stringargument ingenerateLeague(String match)