Skip to content

Commit

Permalink
Rounding Mode bug fix (#36)
Browse files Browse the repository at this point in the history
* Fixed rounding mode issue
  • Loading branch information
ldbonkowski authored Nov 6, 2023
1 parent eb8bdd2 commit d10f956
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/example/househomey/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public class HomeFragment extends Fragment {
private CollectionReference itemRef;
private ListView itemListView;
private PopupMenu filterView;

private ArrayList<Item> itemList = new ArrayList<>();
private ArrayList<Item> itemList;
private ArrayAdapter<Item> itemAdapter;

/**
Expand All @@ -46,6 +45,7 @@ public class HomeFragment extends Fragment {
*/
public HomeFragment(CollectionReference itemRef) {
this.itemRef = itemRef;
itemList = new ArrayList<>();
}

/**
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/example/househomey/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.firebase.Timestamp;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.Map;
import java.util.Objects;
Expand All @@ -15,7 +16,7 @@
* @see ItemAdapter
*/
public class Item {
public String id;
private String id;
private String description;
private Date acquisitionDate;
private String make = "";
Expand All @@ -35,7 +36,7 @@ public Item(String id, @NonNull Map<String, Object> data) {
this.id = Objects.requireNonNull(id);
this.description = (String) Objects.requireNonNull(data.get("description"));
this.acquisitionDate = ((Timestamp) Objects.requireNonNull(data.get("acquisitionDate"))).toDate();
this.cost = new BigDecimal((String) Objects.requireNonNull(data.get("cost"))).setScale(2);
this.cost = new BigDecimal((String) Objects.requireNonNull(data.get("cost"))).setScale(2, RoundingMode.HALF_UP);

// Optional fields
if (data.containsKey("make")) {
Expand All @@ -52,6 +53,14 @@ public Item(String id, @NonNull Map<String, Object> data) {
}
}

/**
* Getter for id
* @return The id of this item in firestore
*/
public String getId() {
return id;
}

/**
* Getter for acquisitionDate
* @return The acquisition date of this item
Expand Down
2 changes: 1 addition & 1 deletion app/src/test/java/com/example/househomey/ItemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void setUp() {
public void testRequiredConstructor() {
Item newItem = new Item(id, inputMap);

assertEquals(id, newItem.id);
assertEquals(id, newItem.getId());
assertEquals(inputMap.get("description"), newItem.getDescription());
assertEquals(((Timestamp)inputMap.get("acquisitionDate")).toDate(), newItem.getAcquisitionDate());
assertEquals(new BigDecimal((String) inputMap.get("cost")), newItem.getCost());
Expand Down

0 comments on commit d10f956

Please sign in to comment.