Added ChannelFactory and ProductFactory make methods
This commit is contained in:
parent
a6d4a423e0
commit
bce2b74ef2
@ -2,15 +2,41 @@ package cz.cvut.fel.sit.omo.foodchain.factory;
|
|||||||
|
|
||||||
|
|
||||||
import cz.cvut.fel.sit.omo.foodchain.channel.*;
|
import cz.cvut.fel.sit.omo.foodchain.channel.*;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
||||||
|
|
||||||
public class ChannelFactory
|
public class ChannelFactory
|
||||||
{
|
{
|
||||||
public enum ChannelType
|
private enum ChannelType
|
||||||
{
|
{
|
||||||
Fruit, Vegetable, Meat, Other;
|
Fruit, Vegetable, Meat, Other;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChannelBase makeChannel(ChannelType typeOfChannel)
|
/**
|
||||||
|
* Creates channel based on channel type (Fruit, Vegetable, Meat, Other)
|
||||||
|
* @param input data from channel is created
|
||||||
|
* @return created Channel (FruitChannel, VegetableChannel, MeatChannel, OtherChannel)
|
||||||
|
*/
|
||||||
|
public ChannelBase makeChannel(ParserResultElement input)
|
||||||
|
{
|
||||||
|
ChannelBase c = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ChannelType channelType = ChannelType.valueOf(input.getAttribute("channel_type"));
|
||||||
|
c = makeChannelFromChannelType(channelType);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException e)
|
||||||
|
{
|
||||||
|
System.err.println("! Wrong type of enum in ChannelFactory: " + e);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.err.println("! Fatal error in ChannelFactory: " + e);
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChannelBase makeChannelFromChannelType(ChannelType typeOfChannel)
|
||||||
{
|
{
|
||||||
switch (typeOfChannel)
|
switch (typeOfChannel)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,12 +1,37 @@
|
|||||||
package cz.cvut.fel.sit.omo.foodchain.factory;
|
package cz.cvut.fel.sit.omo.foodchain.factory;
|
||||||
|
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.parser.ParserResultElement;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
import cz.cvut.fel.sit.omo.foodchain.product.Product;
|
||||||
|
import cz.cvut.fel.sit.omo.foodchain.product.ProductState;
|
||||||
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
|
||||||
|
|
||||||
|
|
||||||
public class ProductFactory
|
public class ProductFactory
|
||||||
{
|
{
|
||||||
public Product makeProduct(String name, ProductType productType)
|
/**
|
||||||
|
* Creates Product based on input ParserResultElement
|
||||||
|
* @param input data from Product is created
|
||||||
|
* @return created Product
|
||||||
|
*/
|
||||||
|
public Product makeProduct(ParserResultElement input)
|
||||||
{
|
{
|
||||||
return new Product(name, productType);
|
Product p = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String name = input.getAttribute("name");
|
||||||
|
ProductType productType = ProductType.valueOf(input.getAttribute("product_type"));
|
||||||
|
ProductState productState = ProductState.valueOf(input.getAttribute("product_state"));
|
||||||
|
|
||||||
|
p = new Product(name, productType, productState);
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException e)
|
||||||
|
{
|
||||||
|
System.err.println("! Wrong type of enum in ProductFactory: " + e);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.err.println("! Fatal error in ProductFactory: " + e);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user