Скачиваний:
69
Добавлен:
15.06.2014
Размер:
28.41 Кб
Скачать

class BaseProductContainer : BaseContainer {

//queue with list of BaseProduct elements

private:

LinkedList<BaseProduct> *baseproductcontainer;

public:

void setBaseProductContainer(BaseProductContainer container) {

baseproductcontainer = container.getAllListOfProducts();

}

//get the number of products

int getSize() {

return baseproductcontainer.size();

}

BaseProductContainer() {

baseproductcontainer = new LinkedList<BaseProduct>();

}

BaseProductContainer(BaseProductContainer container) {

for(Iterator<BaseProduct> iterator = container.getAllListOfProducts().iterator();iterator.hasNext();) {

BaseProduct baseproduct = (BaseProduct)iterator.next();

baseproductcontainer.add(baseproduct);

}

}

//method for adding element into BaseProductContainer

void addElement(BaseProduct product) {

baseproductcontainer.add(product);

}

//get element with deleting

BaseProduct getElementWithPopping() {

//check there if no elements in linked list

//if LinkedList is empty

if(baseproductcontainer.isEmpty())

//return empty BaseProduct that was created by base constructor

return BaseProduct();

return baseproductcontainer.pop();

}

//get all list of products

LinkedList<BaseProduct> getAllListOfProducts() {

return baseproductcontainer;

}

//method for showing all elements into console

void showInConsole() {

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct baseproduct = (BaseProduct)iterator.next();

baseproduct.showInConsole();

System.out.println();

}

}

//method for deleting all elements from BaseProduct object

void deleteAll() {

baseproductcontainer.removeAll(baseproductcontainer);

}

//method for sorting by name

void sortingByName() {

SortingByName *comp = new SortingByName();

Collections.sort(baseproductcontainer, comp);

delete comp;

}

//method for sorting by country

void sortingByCountry() {

SortingByCountry *comp = new SortingByCountry();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by type

void sortingByType() {

SortingByType *comp = new SortingByType();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by maker site

void sortingByMakerSite() {

SortingByMakerSite *comp = new SortingByMakerSite();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by number

void sortingByNumber() {

SortingByNumber *comp = new SortingByNumber();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by maker mail

void sortingByMakerMail() {

SortingByMakerMail comp = new SortingByMakerMail();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by price

void sortingByPrice() {

SortingByPrice *comp = new SortingByPrice();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by weight

void sortingByWeight() {

SortingByWeight *comp = new SortingByWeight();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by shelf life

void sortingByShelfLife() {

SortingByShelfLife *comp = new SortingByShelfLife();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by maker phone

void sortingByMakerPhone() {

SortingByMakerPhone *comp = new SortingByMakerPhone();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by maker address

void sortingByMakerAddress() {

SortingByMakerAddress *comp = new SortingByMakerAddress();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by department

void sortingByDepartment() {

SortingByDepartment *comp = new SortingByDepartment();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by maker

void sortingByMaker() {

SortingByMaker *comp = new SortingByMaker();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for sorting by arrival data

void sortingByArrivalDate() {

SortingByArrivalDate *comp = new SortingByArrivalDate();

Collections.sort(baseproductcontainer,comp);

delete comp;

}

//method for searching by name and deleting element

void searchAndDelete(String inp_name) {

int position = 0;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct baseproduct = (BaseProduct)iterator.next();

if(inp_name.equals(baseproduct.getBaseProductName())) {

baseproductcontainer.remove(position);

return;

}

position++;

}

}

void searchandEditNumber(String name,String number) {

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct baseproduct = (BaseProduct)iterator.next();

if(name.equals(baseproduct.getBaseProductName())) {

baseproduct.setBaseProductNumber(number);

break;

}

}

}

bool searchByName(String name) {

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct baseproduct = (BaseProduct)iterator.next();

if(name.equals(baseproduct.getBaseProductName()))

return true;

}

return false;

}

String searchAndGetNumber(String name) {

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct baseproduct = (BaseProduct)iterator.next();

if(name.equals(baseproduct.getBaseProductName()))

return baseproduct.getBaseProductNumber();

}

return ""; //empty string return but it can't to be

}

//SEARCHING METHODS

/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////

//search by name and

BaseProductContainer searchByProductName(String name) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(name.equals(product.getBaseProductName())) {

container.addElement(product);

}

}

return container;

}

//search by arrival date

BaseProductContainer searchByProductArrivalDate(String arrivaldate) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(arrivaldate.equals(product.getBaseProductArrivalDate())) {

container.addElement(product);

}

}

return container;

}

//search by maker

BaseProductContainer searchByProductMaker(String maker) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(maker.equals(product.getBaseProductMaker())) {

container.addElement(product);

}

}

return container;

}

//search by price

BaseProductContainer searchByProductPrice(String price) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(price.equals(product.getBaseProductPrice())) {

container.addElement(product);

}

}

return container;

}

//search by type

BaseProductContainer searchByProductType(String type) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(type.equals(product.getBaseProductType())) {

container.addElement(product);

}

}

return container;

}

//search by shelf life

BaseProductContainer searchByProductShelfLife(String shelflife) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(shelflife.equals(product.getBaseProductShelfLife())) {

container.addElement(product);

}

}

return container;

}

//search by weight

BaseProductContainer searchByProductWeight(String weight) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(weight.equals(product.getBaseProductWeight())) {

container.addElement(product);

}

}

return container;

}

//search by number

BaseProductContainer searchByProductNumber(String number) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(number.equals(product.getBaseProductNumber())) {

container.addElement(product);

}

}

return container;

}

//search by country

BaseProductContainer searchByProductCountry(String country) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(country.equals(product.getBaseProductCountry())) {

container.addElement(product);

}

}

return container;

}

//search by maker address

BaseProductContainer searchByProductMakerAddress(String makeraddress) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(makeraddress.equals(product.getBaseProductMakerAddress())) {

container.addElement(product);

}

}

return container;

}

//search by maker site

BaseProductContainer searchByProductMakerSite(String makersite) {

BaseP

roductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(makersite.equals(product.getBaseProductMakerSite())) {

container.addElement(product);

}

}

return container;

}

//search by maker mail

BaseProductContainer searchByProductMakerMail(String makermail) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(makermail.equals(product.getBaseProductMakerMail())) {

container.addElement(product);

}

}

return container;

}

//search by maker phone

BaseProductContainer searchByProductMakerPhone(String makerphone) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(makerphone.equals(product.getBaseProductMakerPhone())) {

container.addElement(product);

}

}

return container;

}

//search by department

BaseProductContainer searchByProductDepartment(String department) {

BaseProductContainer container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(department.equals(product.getBaseProductDepartment())) {

container.addElement(product);

}

}

return container;

}

/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////

void filterByDepartment(String filter_by) {

LinkedList<BaseProduct> tmp_container;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(filter_by.equals(product.getBaseProductDepartment())) {

tmp_container.add(product);

}

}

baseproductcontainer = tmp_container;

}

String getOveralPrice() {

Double result = 0.0;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

result += Double.parseDouble(product.getBaseProductPrice());

}

return result.toString();

}

String getOveralNumberOfProducts() {

Integer result = 0;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

result += Integer.parseInt(product.getBaseProductNumber());

}

return result.toString();

}

String getOveralWeightOfProducts() {

Double result = 0.0;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

result += Integer.parseInt(product.getBaseProductWeight());

}

return result.toString();

}

String getAverageShelfLifeOfProducts() {

Double sum = 0.0;

Double result = 0.0;

int counter = 0;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

sum += Double.parseDouble(product.getBaseProductShelfLife());

counter++;

}

if(counter == 0)

return "No data";

if(counter == 1)

return sum.toString();

result = sum / (double)counter;

return result.toString();

}

LinkedList<String> getListOfProductNames() {

LinkedList<String> productNames;

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

productNames.add(product.getBaseProductName());

}

return productNames;

}

BaseProduct searchByNameAndGet(String name) {

for(Iterator<BaseProduct> iterator = baseproductcontainer.iterator();iterator.hasNext();) {

BaseProduct product = (BaseProduct)iterator.next();

if(name.equals(product.getBaseProductName()))

return product;

}

return new BaseProduct();

}

}

37