| 1 | package edu.ucsb.cs156.happiercows.entities; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.annotation.JsonIgnore; | |
| 4 | import com.fasterxml.jackson.annotation.JsonInclude; | |
| 5 | ||
| 6 | import edu.ucsb.cs156.happiercows.repositories.CommonsRepository; | |
| 7 | import edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategies; | |
| 8 | import lombok.AllArgsConstructor; | |
| 9 | import lombok.Builder; | |
| 10 | import lombok.Data; | |
| 11 | import lombok.NoArgsConstructor; | |
| 12 | ||
| 13 | import javax.persistence.*; | |
| 14 | import java.time.LocalDateTime; | |
| 15 | import java.util.List; | |
| 16 | ||
| 17 | @Data | |
| 18 | @AllArgsConstructor | |
| 19 | @NoArgsConstructor | |
| 20 | @Builder | |
| 21 | @Entity(name = "commons") | |
| 22 | public class Commons { | |
| 23 | @Id | |
| 24 | @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| 25 | private long id; | |
| 26 | ||
| 27 | private String name; | |
| 28 | private double cowPrice; | |
| 29 | private double milkPrice; | |
| 30 | private double startingBalance; | |
| 31 | private LocalDateTime startingDate; | |
| 32 | private LocalDateTime lastdayDate; | |
| 33 | private boolean showLeaderboard; | |
| 34 | private double degradationRate; | |
| 35 | private int carryingCapacity; | |
| 36 | private int capacityPerUser; | |
| 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 | public boolean gameInProgress() { | |
| 47 |
3
1. gameInProgress : negated conditional → KILLED 2. gameInProgress : negated conditional → KILLED 3. gameInProgress : replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED |
return (startingDate.isBefore(LocalDateTime.now()) && lastdayDate.isAfter(LocalDateTime.now())); |
| 48 | } | |
| 49 | ||
| 50 | public static int computeEffectiveCapacity(Commons commons, CommonsRepository commonsRepository) { | |
| 51 |
2
1. computeEffectiveCapacity : Replaced integer multiplication with division → KILLED 2. computeEffectiveCapacity : replaced int return with 0 for edu/ucsb/cs156/happiercows/entities/Commons::computeEffectiveCapacity → KILLED |
return Math.max(commons.getCapacityPerUser() * commonsRepository.getNumUsers(commons.getId()).orElse(0), commons.getCarryingCapacity()); |
| 52 | } | |
| 53 | ||
| 54 | @OneToMany(mappedBy = "commons", cascade = CascadeType.REMOVE) | |
| 55 | @JsonIgnore | |
| 56 | private List<UserCommons> joinedUsers; | |
| 57 | ||
| 58 | } | |
Mutations | ||
| 47 |
1.1 2.2 3.3 |
|
| 51 |
1.1 2.2 |