1 | package edu.ucsb.cs156.happiercows.entities; | |
2 | ||
3 | import com.fasterxml.jackson.annotation.JsonIgnore; | |
4 | import edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategies; | |
5 | import lombok.AllArgsConstructor; | |
6 | import lombok.Builder; | |
7 | import lombok.Data; | |
8 | import lombok.NoArgsConstructor; | |
9 | ||
10 | import javax.persistence.*; | |
11 | import java.time.LocalDateTime; | |
12 | import java.util.List; | |
13 | ||
14 | ||
15 | ||
16 | @Data | |
17 | @AllArgsConstructor | |
18 | @NoArgsConstructor | |
19 | @Builder | |
20 | @Entity(name = "commons") | |
21 | public class Commons { | |
22 | @Id | |
23 | @GeneratedValue(strategy = GenerationType.IDENTITY) | |
24 | private long id; | |
25 | ||
26 | private String name; | |
27 | private double cowPrice; | |
28 | private double milkPrice; | |
29 | private double startingBalance; | |
30 | private LocalDateTime startingDate; | |
31 | private LocalDateTime lastDate; | |
32 | private boolean showLeaderboard; | |
33 | | |
34 | private int capacityPerUser; | |
35 | private int carryingCapacity; | |
36 | private double degradationRate; | |
37 | ||
38 | // these defaults match old behavior | |
39 | @Enumerated(EnumType.STRING) | |
40 | @Builder.Default | |
41 | private CowHealthUpdateStrategies belowCapacityHealthUpdateStrategy = CowHealthUpdateStrategies.DEFAULT_BELOW_CAPACITY; | |
42 | @Enumerated(EnumType.STRING) | |
43 | @Builder.Default | |
44 | private CowHealthUpdateStrategies aboveCapacityHealthUpdateStrategy = CowHealthUpdateStrategies.DEFAULT_ABOVE_CAPACITY; | |
45 | ||
46 | ||
47 | @OneToMany(mappedBy = "commons", cascade = CascadeType.REMOVE) | |
48 | @JsonIgnore | |
49 | private List<UserCommons> joinedUsers; | |
50 | ||
51 | public boolean gameInProgress() { | |
52 | LocalDateTime today = LocalDateTime.now(); | |
53 |
2
1. gameInProgress : negated conditional → KILLED 2. gameInProgress : negated conditional → KILLED |
if (startingDate.isBefore(today) && lastDate.isAfter(today)) { |
54 |
1
1. gameInProgress : replaced boolean return with false for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED |
return true; |
55 | } | |
56 |
1
1. gameInProgress : replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED |
return false; |
57 | } | |
58 | } | |
Mutations | ||
53 |
1.1 2.2 |
|
54 |
1.1 |
|
56 |
1.1 |