Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
scoreboard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
João Lino
scoreboard
Commits
cec5c367
Commit
cec5c367
authored
Aug 02, 2022
by
João Lino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove time dependency
parent
58811b0e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
27 deletions
+28
-27
src/main/java/org/example/scoreboard/api/IMatch.java
src/main/java/org/example/scoreboard/api/IMatch.java
+0
-2
src/main/java/org/example/scoreboard/generic/AbstractMatch.java
...in/java/org/example/scoreboard/generic/AbstractMatch.java
+1
-16
src/main/java/org/example/scoreboard/generic/AbstractScoreboard.java
...va/org/example/scoreboard/generic/AbstractScoreboard.java
+2
-1
src/test/java/org/example/scoreboard/reference/TestScoreboard.java
...java/org/example/scoreboard/reference/TestScoreboard.java
+25
-8
No files found.
src/main/java/org/example/scoreboard/api/IMatch.java
View file @
cec5c367
package
org.example.scoreboard.api
;
import
java.util.Date
;
import
java.util.UUID
;
public
interface
IMatch
{
...
...
@@ -13,5 +12,4 @@ public interface IMatch {
ITeam
getAwayTeam
();
IScore
getAwayTeamScore
();
void
setAwayTeamScore
(
IScore
awayTeamScore
);
Date
getStartDate
();
}
src/main/java/org/example/scoreboard/generic/AbstractMatch.java
View file @
cec5c367
...
...
@@ -4,7 +4,6 @@ import org.example.scoreboard.api.IMatch;
import
org.example.scoreboard.api.IScore
;
import
org.example.scoreboard.api.ITeam
;
import
java.util.Date
;
import
java.util.UUID
;
import
java.util.function.Supplier
;
...
...
@@ -14,7 +13,6 @@ public abstract class AbstractMatch implements IMatch, Comparable<IMatch> {
private
final
ITeam
awayTeam
;
private
IScore
homeTeamScore
;
private
IScore
awayTeamScore
;
private
final
Date
startDate
;
protected
AbstractMatch
(
Supplier
<
IScore
>
scoreSupplier
,
ITeam
homeTeam
,
ITeam
awayTeam
)
{
this
.
id
=
UUID
.
randomUUID
();
...
...
@@ -22,7 +20,6 @@ public abstract class AbstractMatch implements IMatch, Comparable<IMatch> {
this
.
awayTeam
=
awayTeam
;
this
.
homeTeamScore
=
scoreSupplier
.
get
();
this
.
awayTeamScore
=
scoreSupplier
.
get
();
this
.
startDate
=
new
Date
();
}
public
ITeam
getHomeTeam
()
{
...
...
@@ -53,10 +50,6 @@ public abstract class AbstractMatch implements IMatch, Comparable<IMatch> {
this
.
awayTeamScore
=
awayTeamScore
;
}
public
Date
getStartDate
()
{
return
startDate
;
}
@Override
public
String
toString
()
{
return
getHomeTeam
()
+
" "
+
getHomeTeamScore
()
+
" - "
+
getAwayTeam
()
+
" "
+
getAwayTeamScore
();
...
...
@@ -70,16 +63,8 @@ public abstract class AbstractMatch implements IMatch, Comparable<IMatch> {
return
-
1
;
}
else
if
(
totalScoreMatch1
<
totalScoreMatch2
)
{
return
1
;
}
else
{
Date
startMatch1
=
getStartDate
();
Date
startMatch2
=
otherMatch
.
getStartDate
();
if
(
startMatch1
.
after
(
startMatch2
))
{
return
-
1
;
}
else
if
(
startMatch1
.
before
(
startMatch2
))
{
return
1
;
}
}
return
0
;
return
-
1
;
// default return -1 to reverse the linked hash map insertion-order iterator on score collision
}
}
src/main/java/org/example/scoreboard/generic/AbstractScoreboard.java
View file @
cec5c367
...
...
@@ -8,6 +8,7 @@ import org.example.scoreboard.api.ITeam;
import
java.security.InvalidParameterException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.NoSuchElementException
;
import
java.util.UUID
;
import
java.util.function.BiFunction
;
...
...
@@ -19,7 +20,7 @@ public class AbstractScoreboard implements IScoreboard {
BiFunction
<
ITeam
,
ITeam
,
IMatch
>
matchSupplier
;
HashMap
<
UUID
,
ITeam
>
teamsOnTheBoard
=
new
HashMap
<>();
HashMap
<
UUID
,
IMatch
>
ongoingMatches
=
new
HashMap
<>();
LinkedHashMap
<
UUID
,
IMatch
>
ongoingMatches
=
new
Linked
HashMap
<>();
private
AbstractScoreboard
(){}
public
AbstractScoreboard
(
BiFunction
<
ITeam
,
ITeam
,
IMatch
>
matchSupplier
)
{
...
...
src/test/java/org/example/scoreboard/reference/TestScoreboard.java
View file @
cec5c367
...
...
@@ -10,7 +10,6 @@ import java.util.*;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
static
java
.
lang
.
Thread
.
sleep
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
mockito
.
Mockito
.*;
...
...
@@ -123,24 +122,42 @@ public class TestScoreboard {
}
}
// should
return ordered matches_whenSummaryIsR
equested
// should
present matches ordered from newest to oldest when summary is r
equested
@Test
public
void
shouldReturnOrderedMatches_whenSummaryIsRequested
()
throws
InterruptedException
{
public
void
shouldPresentFromNewestToOldest_whenSummaryIsRequestedAndAllGamesWithTheSameScore
()
{
IMatch
match1
=
scoreboard
.
startMatch
(
Mexico
,
Canada
);
match1
=
scoreboard
.
updateScore
(
match1
,
new
Score
(
5
),
new
Score
(
5
));
IMatch
match2
=
scoreboard
.
startMatch
(
Spain
,
Brazil
);
match2
=
scoreboard
.
updateScore
(
match2
,
new
Score
(
5
),
new
Score
(
5
));
IMatch
match3
=
scoreboard
.
startMatch
(
Germany
,
France
);
match3
=
scoreboard
.
updateScore
(
match3
,
new
Score
(
5
),
new
Score
(
5
));
IMatch
match4
=
scoreboard
.
startMatch
(
Uruguay
,
Italy
);
match4
=
scoreboard
.
updateScore
(
match4
,
new
Score
(
5
),
new
Score
(
5
));
IMatch
match5
=
scoreboard
.
startMatch
(
Argentina
,
Australia
);
match5
=
scoreboard
.
updateScore
(
match5
,
new
Score
(
5
),
new
Score
(
5
));
ArrayList
<
IMatch
>
expectedResult
=
Stream
.
of
(
match5
,
match4
,
match3
,
match2
,
match1
).
collect
(
Collectors
.
toCollection
(
ArrayList:
:
new
));
ArrayList
<
IMatch
>
gameSummary
=
scoreboard
.
getGameSummary
();
if
(!
expectedResult
.
equals
(
gameSummary
))
{
gameSummary
.
forEach
(
System
.
out
::
println
);
fail
(
"failed to return expected ordered summary"
);
}
}
// should present matches ordered from highest combined score to lowest, newest to oldest on collision, when summary is requested
@Test
public
void
shouldOrderByScoreFromHighToLowedByNewToOldOnCollision_whenSummaryIsRequested
()
{
IMatch
match1
=
scoreboard
.
startMatch
(
Mexico
,
Canada
);
match1
=
scoreboard
.
updateScore
(
match1
,
new
Score
(
0
),
new
Score
(
5
));
sleep
(
1
);
IMatch
match2
=
scoreboard
.
startMatch
(
Spain
,
Brazil
);
match2
=
scoreboard
.
updateScore
(
match2
,
new
Score
(
10
),
new
Score
(
2
));
sleep
(
1
);
IMatch
match3
=
scoreboard
.
startMatch
(
Germany
,
France
);
match3
=
scoreboard
.
updateScore
(
match3
,
new
Score
(
2
),
new
Score
(
2
));
sleep
(
1
);
IMatch
match4
=
scoreboard
.
startMatch
(
Uruguay
,
Italy
);
match4
=
scoreboard
.
updateScore
(
match4
,
new
Score
(
6
),
new
Score
(
6
));
sleep
(
1
);
IMatch
match5
=
scoreboard
.
startMatch
(
Argentina
,
Australia
);
match5
=
scoreboard
.
updateScore
(
match5
,
new
Score
(
3
),
new
Score
(
1
));
sleep
(
1
);
ArrayList
<
IMatch
>
expectedResult
=
Stream
.
of
(
match4
,
match2
,
match1
,
match5
,
match3
).
collect
(
Collectors
.
toCollection
(
ArrayList:
:
new
));
ArrayList
<
IMatch
>
gameSummary
=
scoreboard
.
getGameSummary
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment