Forked from
Surya Bahadur Kathayat / idatt1002
25 commits behind, 19 commits ahead of the upstream repository.
ItemOverview.java 1.37 KiB
package no.ntnu.idatt1002.demo.data;
import java.util.ArrayList;
/**
* ItemOverview is a class for storing and getting
* information on items. Is also a
* superclass for Income- and Expense overview. TODO: Make income and expense overview
*/
public class ItemOverview {
ArrayList<Item> items;
/**
* An "empty" class constructor.
*/
public ItemOverview(){
this.items = new ArrayList<>(); //ArrayList for storing item´s
}
/**
* Class constructor that takes in an ArrayList of Item´s as argument
* @param items An ArrayList of the Item´s you want to overview
*/
public ItemOverview(ArrayList<Item> items){
this.items = items;
}
/**
* Get an ArrayList of every item.
* @return item ArrayList.
*/
public ArrayList<Item> getItems() {
return items;
}
/**
* Add an Item object to items.
* @param newItem The Item you want to add.
*/
public void addItem(Income newItem){
if(items.contains(newItem)){
throw new IllegalArgumentException("This item is already registered");
}
items.add(newItem);
}
/**
* Get the sum of all Item´s in items
* @return Sum of all Item´s
*/
public double getTotalSum(){
return items.stream().map(Item::getAmount).mapToDouble(Double::doubleValue).sum();
}
}