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 | ||
12 | import java.time.LocalDateTime; | |
13 | import java.util.List; | |
14 | ||
15 | @Data | |
16 | @AllArgsConstructor | |
17 | @NoArgsConstructor | |
18 | @Builder | |
19 | @Entity(name = "commons") | |
20 | public class Commons { | |
21 | @Id | |
22 | @GeneratedValue(strategy = GenerationType.IDENTITY) | |
23 | private long id; | |
24 | ||
25 | private String name; | |
26 | private double cowPrice; | |
27 | private double milkPrice; | |
28 | private double startingBalance; | |
29 | private LocalDateTime startingDate; | |
30 | private LocalDateTime lastDate; | |
31 | private boolean showLeaderboard; | |
32 | | |
33 | private int capacityPerUser; | |
34 | private int carryingCapacity; | |
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 | ||
50 | // returns true if today's date is >= start date, and <= last day | |
51 | public boolean gameInProgress() { | |
52 | LocalDateTime todayDateTime = LocalDateTime.now(); | |
53 |
2
1. gameInProgress : negated conditional → KILLED 2. gameInProgress : negated conditional → KILLED |
boolean output = ( todayDateTime.isAfter(startingDate) && todayDateTime.isBefore(lastDate) ); |
54 |
2
1. gameInProgress : replaced boolean return with false for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED 2. gameInProgress : replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED |
return output; |
55 | ||
56 | } | |
57 | | |
58 | } | |
Mutations | ||
53 |
1.1 2.2 |
|
54 |
1.1 2.2 |