Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.Date;
- import java.util.List;
- import java.util.stream.Collectors;
- import java.util.stream.Stream;
- public class Kochan implements Serializable {
- //fields
- private List<Invoice> invoiceList;
- private long counter;
- private User supplier;
- //Constructor
- public Kochan(){
- }
- // public Kochan(List<Invoice> newInvoiceList, int newCounter, User newSupplier){
- // this.invoiceList = newInvoiceList;
- // this.counter = newCounter;
- // this.supplier = newSupplier;
- // }
- //Getters, setters
- public void addToInvoiceList(Invoice invoice){
- this.invoiceList.add(invoice);
- this.counter++; // ???? or standalone setter?
- }
- public List<Invoice> getInvoiceList(){
- return this.invoiceList;
- }
- public long getCounter(){
- return this.counter;
- }
- public void setSupplier(User user){
- this.supplier = user;
- }
- public User getSupplier(){
- return this.supplier;
- }
- //Methods
- //public getFromFile()
- public boolean getFromFile(){
- List<Invoice> result = new List<Invoice>();
- try (Stream<Invoice> lines = Files.lines(Paths.get("File.txt"))) {
- result.add(lines.collect(Collectors.toList()));
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- }
- return true;
- }
- //public sendToFIle()
- //search by specific date
- public List<Invoice> searchByDate(Date dateToSearch){
- List<Invoice> invoicesSameDate = new List<Invoice>();
- //Date of issue: simple date format
- for(Invoice invoice : this.invoiceList){
- if(invoice.dateOfIssue.compareTo(dateToSearch) == 0 ) invoicesSameDate.add(invoice);
- }
- return invoicesSameDate;
- }
- //overload search by range of dates
- public List<Invoice> searchByDate(Date startDate, Date endDate){
- List<Invoice> invoicesInRange = new List<Invoice>();
- for(Invoice invoice : this.invoiceList){
- if(!(invoice.dateOfIssue.before(startDate) && invoice.dateOfIssue.after(endDate))) invoicesInRange.add(invoice);
- }
- return invoicesInRange;
- }
- //search by items
- public List<Invoice> searchByItem(Goods goodsToSearch){
- // List<Invoice> searchedByItem = new List<Invoice>();
- // for(Invoice invoice : this.invoiceList){
- // for(Goods good : invoice.goods){
- // if(good.nameOfGood.equals(goodsToSearch)) searchedByItem.add(invoice);
- // }
- // }
- // return searchedByItem;
- List<Invoice> result = this.invoiceList.stream().filter(good -> good.nameOfGood.equals(goodsToSearch));
- return result;
- }
- //search by recipient?? search by name, idNumber, id?
- public List<Invoice> searchByRecipientName(String nameToSearch){
- List<Invoice> searchRecipientName = new List<Invoice>();
- for(Invoice invoice : this.invoiceList){
- if(invoice.User.recipient.name.equals(nameToSearch)) searchRecipientName.add(invoice);
- }
- return searchRecipientName;
- }
- //get next free number
- public long getNextFreeNumber(){
- return counter + 1;
- }
- }
Add Comment
Please, Sign In to add comment