Browse Source

StringUtils

master
GAM 4 years ago
parent
commit
5630a05ef6
3 changed files with 30 additions and 17 deletions
  1. +21
    -0
      src/main/java/com/example/application/utils/StringUtils.java
  2. +2
    -6
      src/main/java/com/example/application/views/results/ResultsView.java
  3. +7
    -11
      src/main/java/com/example/application/views/table/TableView.java

+ 21
- 0
src/main/java/com/example/application/utils/StringUtils.java View File

@ -0,0 +1,21 @@
package com.example.application.utils;
public class StringUtils {
private StringUtils() {
}
public static String getResultString(Double first, Double second) {
String firstString = first.toString().replace(".0", "");
String secondString = second.toString().replace(".0", "");
String result = firstString + " : " + secondString;
if (result.equals("0 : 0")) {
return "- : -";
}
return result;
}
public static String getSignedString(Double aDouble) {
String string = aDouble.toString().replace(".0", "");
return aDouble > 0 ? "+" + string : string;
}
}

+ 2
- 6
src/main/java/com/example/application/views/results/ResultsView.java View File

@ -5,6 +5,7 @@ import com.example.application.data.entity.Player;
import com.example.application.data.service.MatchService;
import com.example.application.data.service.MatchdayService;
import com.example.application.data.service.SeasonService;
import com.example.application.utils.StringUtils;
import com.example.application.views.abstractnavigation.SeasonAndMatchdayNavigationView;
import com.example.application.views.main.MainView;
import com.vaadin.flow.component.*;
@ -22,8 +23,6 @@ import com.vaadin.flow.function.ValueProvider;
import com.vaadin.flow.router.*;
import org.springframework.beans.factory.annotation.Autowired;
import javax.swing.text.NumberFormatter;
@CssImport("./views/results/results-view.css")
@Route(value = "results", layout = MainView.class)
@PageTitle("Schachliga DACH - Results")
@ -134,10 +133,7 @@ public class ResultsView extends SeasonAndMatchdayNavigationView {
}
private String getResultString(CalculatedMatch match) {
String result = match.getScore1().toString().replace(".0", "")
+ " : "
+ match.getScore2().toString().replace(".0", "");
return result.equals("0 : 0") ? "- : -" : result;
return StringUtils.getResultString(match.getScore1(), match.getScore2());
}
/////////////


+ 7
- 11
src/main/java/com/example/application/views/table/TableView.java View File

@ -5,6 +5,7 @@ import com.example.application.data.entity.Player;
import com.example.application.data.service.MatchdayService;
import com.example.application.data.service.PlayerService;
import com.example.application.data.service.SeasonService;
import com.example.application.utils.StringUtils;
import com.example.application.views.abstractnavigation.SeasonAndMatchdayNavigationView;
import com.example.application.views.main.MainView;
import com.vaadin.flow.component.dependency.CssImport;
@ -116,21 +117,12 @@ public class TableView extends SeasonAndMatchdayNavigationView {
.setTextAlign(ColumnTextAlign.CENTER)
.setWidth("3em");
getGrid().addColumn((ValueProvider<PlayerForTable, String>) playerForTable -> {
//noinspection CodeBlock2Expr
return playerForTable.getGamePointsForSelf().toString().replace(".0", "") // TODO: make this reusable
+ " : "
+ playerForTable.getGamePointsForOpponents().toString().replace(".0", "");
})
getGrid().addColumn((ValueProvider<PlayerForTable, String>) this::getResultString)
.setHeader(headerGames)
.setTextAlign(ColumnTextAlign.CENTER)
.setWidth("6em");
getGrid().addColumn((ValueProvider<PlayerForTable, String>) playerForTable -> {
Double diff = playerForTable.getGamePointDiff();
String diffString = playerForTable.getGamePointDiff().toString().replace(".0", "");
return diff > 0 ? "+" + diffString : diffString;
})
getGrid().addColumn((ValueProvider<PlayerForTable, String>) player -> StringUtils.getSignedString(player.getGamePointDiff()))
.setHeader(headerDiff)
.setTextAlign(ColumnTextAlign.CENTER)
.setWidth("5em");
@ -140,6 +132,10 @@ public class TableView extends SeasonAndMatchdayNavigationView {
getGrid().addClassName("my_grid");
}
private String getResultString(PlayerForTable player) {
return StringUtils.getResultString(player.getGamePointsForSelf(), player.getGamePointsForOpponents());
}
/////////////
// CONTENT //
/////////////


Loading…
Cancel
Save