1 | package edu.ucsb.cs156.happiercows.entities; | |
2 | ||
3 | import com.fasterxml.jackson.annotation.JsonIgnore; | |
4 | import com.fasterxml.jackson.annotation.JsonInclude; | |
5 | import com.fasterxml.jackson.annotation.JsonGetter; | |
6 | import edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategies; | |
7 | import lombok.AllArgsConstructor; | |
8 | import lombok.Builder; | |
9 | import lombok.Data; | |
10 | import lombok.NoArgsConstructor; | |
11 | ||
12 | import javax.persistence.*; | |
13 | import java.time.LocalDateTime; | |
14 | import java.util.List; | |
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 boolean showLeaderboard; | |
32 | ||
33 | private int carryingCapacity; | |
34 | private int capacityPerUser; | |
35 | private double degradationRate; | |
36 | ||
37 | // these defaults match old behavior | |
38 | @Enumerated(EnumType.STRING) | |
39 | @Builder.Default | |
40 | private CowHealthUpdateStrategies belowCapacityHealthUpdateStrategy = CowHealthUpdateStrategies.DEFAULT_BELOW_CAPACITY; | |
41 | @Enumerated(EnumType.STRING) | |
42 | @Builder.Default | |
43 | private CowHealthUpdateStrategies aboveCapacityHealthUpdateStrategy = CowHealthUpdateStrategies.DEFAULT_ABOVE_CAPACITY; | |
44 | ||
45 | ||
46 | @OneToMany(mappedBy = "commons", cascade = CascadeType.REMOVE) | |
47 | @JsonIgnore | |
48 | private List<UserCommons> joinedUsers; | |
49 | @JsonIgnore | |
50 | private int numUsers; | |
51 | ||
52 | @JsonGetter("effectiveCapacity") | |
53 | public int getEffectiveCapacity() { | |
54 |
2
1. getEffectiveCapacity : Replaced integer multiplication with division → KILLED 2. getEffectiveCapacity : replaced int return with 0 for edu/ucsb/cs156/happiercows/entities/Commons::getEffectiveCapacity → KILLED |
return Math.max(capacityPerUser * numUsers, carryingCapacity); |
55 | } | |
56 | } | |
Mutations | ||
54 |
1.1 2.2 |