| 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 jakarta.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 | @Builder.Default | |
| 35 | private boolean showChat = true; | |
| 36 | | |
| 37 | private int capacityPerUser; | |
| 38 | private int carryingCapacity; | |
| 39 | private double degradationRate; | |
| 40 | ||
| 41 | // these defaults match old behavior | |
| 42 | @Enumerated(EnumType.STRING) | |
| 43 | @Builder.Default | |
| 44 | private CowHealthUpdateStrategies belowCapacityHealthUpdateStrategy = CowHealthUpdateStrategies.DEFAULT_BELOW_CAPACITY; | |
| 45 | @Enumerated(EnumType.STRING) | |
| 46 | @Builder.Default | |
| 47 | private CowHealthUpdateStrategies aboveCapacityHealthUpdateStrategy = CowHealthUpdateStrategies.DEFAULT_ABOVE_CAPACITY; | |
| 48 | ||
| 49 | ||
| 50 | @OneToMany(mappedBy = "commons", cascade = CascadeType.REMOVE) | |
| 51 | @JsonIgnore | |
| 52 | private List<UserCommons> joinedUsers; | |
| 53 | ||
| 54 | public boolean gameInProgress() { | |
| 55 | LocalDateTime today = LocalDateTime.now(); | |
| 56 |
2
1. gameInProgress : negated conditional → KILLED 2. gameInProgress : negated conditional → KILLED |
if (startingDate.isBefore(today) && lastDate.isAfter(today)) { |
| 57 |
1
1. gameInProgress : replaced boolean return with false for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED |
return true; |
| 58 | } | |
| 59 |
1
1. gameInProgress : replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED |
return false; |
| 60 | } | |
| 61 | } | |
Mutations | ||
| 56 |
1.1 2.2 |
|
| 57 |
1.1 |
|
| 59 |
1.1 |