Added more classes and interfaces

This commit is contained in:
Tomáš Musil 2020-11-21 12:57:55 +01:00
parent 1d04bb6dc7
commit 021c194839
47 changed files with 402 additions and 50 deletions

Binary file not shown.

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain;
public class FoodChain {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.channel;
public interface Channel {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.channel;
public abstract class ChannelBase implements Channel {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.channel;
public class FruitChannel extends ChannelBase {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.channel;
public class MeetChannel extends ChannelBase {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.channel;
public class VegetableChannel extends ChannelBase {
}

View File

@ -1,46 +1,52 @@
package cz.cvut.fel.sit.omo.foodchain.factory;
import cz.cvut.fel.sit.omo.foodchain.pool.PoolDatabase;
import cz.cvut.fel.sit.omo.foodchain.util.Singleton;
import java.lang.reflect.InvocationTargetException;
public class FactoryManager {
public NodeFactory getNodeFactoryInstance(){
public NodeFactory getNodeFactoryInstance() {
try {
return Singleton.getInstance(NodeFactory.class);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
public ChannelFactory getChannelFactoryInstance(){
public ChannelFactory getChannelFactoryInstance() {
try {
return Singleton.getInstance(ChannelFactory.class);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
public ScenarioFactory getScenarioFactoryInstance(){
public ScenarioFactory getScenarioFactoryInstance() {
try {
return Singleton.getInstance(ScenarioFactory.class);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
public ProductFactory getProductFactoryInstance(){
public ProductFactory getProductFactoryInstance() {
try {
return Singleton.getInstance(ProductFactory.class);
} catch (IllegalAccessException e) {
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
}
return null;
}
public PoolDatabase getPoolDatabaseInstance() {
try {
return Singleton.getInstance(PoolDatabase.class);
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return null;

View File

@ -1,24 +0,0 @@
package cz.cvut.fel.sit.omo.foodchain.factory;
import java.util.HashMap;
import java.util.Map;
public class Singleton {
private static final Singleton instance = new Singleton();
@SuppressWarnings("rawtypes")
private final Map<Class, Object> mapHolder = new HashMap<Class, Object>();
private Singleton() {
}
public static <T> T getInstance(Class<T> tClass) throws IllegalAccessException, InstantiationException {
if (!instance.mapHolder.containsKey(tClass)) {
T obj = tClass.newInstance();
instance.mapHolder.put(tClass, obj);
}
return (T) instance.mapHolder.get(tClass);
}
}

View File

@ -1,4 +1,15 @@
package cz.cvut.fel.sit.omo.foodchain.node;
public class BuyerNodeBase implements NodeInterface {
import cz.cvut.fel.sit.omo.foodchain.product.Product;
public class BuyerNodeBase extends NodeBase implements BuyerNodeInterface {
@Override
public void sellProduct(Product product) {
}
@Override
public void addMargin(Product product) {
}
}

View File

@ -0,0 +1,10 @@
package cz.cvut.fel.sit.omo.foodchain.node;
import cz.cvut.fel.sit.omo.foodchain.product.Product;
public interface BuyerNodeInterface {
void sellProduct(Product product);
void addMargin(Product product);
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.node;
public class Customer extends BuyerNodeBase {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.node;
public class Distributor extends RetailerNodeBase {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.node;
public class Farmer extends SellerNodeBase {
}

View File

@ -0,0 +1,88 @@
package cz.cvut.fel.sit.omo.foodchain.node;
import cz.cvut.fel.sit.omo.foodchain.channel.Channel;
import cz.cvut.fel.sit.omo.foodchain.operation.Action;
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
import cz.cvut.fel.sit.omo.foodchain.product.Product;
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
import cz.cvut.fel.sit.omo.foodchain.signature.Signature;
import java.awt.*;
public class NodeBase implements NodeInterface {
@Override
public void sendTransaction(Product product, NodeInterface node) {
}
@Override
public void receiveTransaction(Transaction transaction) {
}
@Override
public void refuseTransaction(Transaction transaction) {
}
@Override
public Transaction readNextTransaction(Channel channel) {
return null;
}
@Override
public Requirement readNextRequirement(Channel channel) {
return null;
}
@Override
public void acceptRequirement(Requirement requirement) {
}
@Override
public void subscribeToChannel(Channel channel) {
}
@Override
public void unsubscribeFromChannel(Channel channel) {
}
@Override
public void doAction(Action action, Product product) {
}
@Override
public void doAction(Action action) {
}
@Override
public void storeProduct(Product product) {
}
@Override
public void storeProducts(List products) {
}
@Override
public Product getProductFromStorage(String name, ProductType type) {
return null;
}
@Override
public Signature generateSignature(Transaction transaction) {
return null;
}
@Override
public boolean validateSignature(Signature signature) {
return false;
}
}

View File

@ -1,25 +1,43 @@
package cz.cvut.fel.sit.omo.foodchain.node;
import cz.cvut.fel.sit.omo.foodchain.channel.Channel;
import cz.cvut.fel.sit.omo.foodchain.operation.Action;
import cz.cvut.fel.sit.omo.foodchain.operation.Transaction;
import cz.cvut.fel.sit.omo.foodchain.product.Product;
import cz.cvut.fel.sit.omo.foodchain.product.ProductType;
import cz.cvut.fel.sit.omo.foodchain.requirement.Requirement;
import cz.cvut.fel.sit.omo.foodchain.signature.Signature;
import java.awt.*;
public interface NodeInterface {
void sendTransaction(Product product, NodeInterface node);
void receiveTransaction(Transaction transaction);
void refuseTransaction(Transaction transaction);
Transaction readNextTransaction(ChannelInterface channel);
Requirement readNextRequirement(ChannelInterface channel);
void receiveTransaction(Transaction transaction);
void refuseTransaction(Transaction transaction);
Transaction readNextTransaction(Channel channel);
Requirement readNextRequirement(Channel channel);
void acceptRequirement(Requirement requirement);
void subscribeToChannel(ChannelInterface channel);
void unsubscribeFromChannel(ChannelInterface channel);
void subscribeToChannel(Channel channel);
void unsubscribeFromChannel(Channel channel);
void doAction(Action action, Product product);
void doAction(Action action);
void storeProduct(Product product);
void storeProducts(List<Product> products);
void storeProducts(List products);
Product getProductFromStorage(String name, ProductType type);
Signature generateSignature(Transaction transaction);
boolean validateSignature(Signature signature);
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.node;
public class Processor extends RetailerNodeBase {
}

View File

@ -0,0 +1,20 @@
package cz.cvut.fel.sit.omo.foodchain.node;
import cz.cvut.fel.sit.omo.foodchain.product.Product;
public class RetailerNodeBase extends NodeBase implements BuyerNodeInterface, SellerNodeInterface {
@Override
public void sellProduct(Product product) {
}
@Override
public void addMargin(Product product) {
}
@Override
public void buyProduct(Product product) {
}
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.node;
public class Seller extends RetailerNodeBase {
}

View File

@ -1,4 +1,10 @@
package cz.cvut.fel.sit.omo.foodchain.node;
public class SellerNodeBase implements NodeInterface {
import cz.cvut.fel.sit.omo.foodchain.product.Product;
public class SellerNodeBase extends NodeBase implements SellerNodeInterface {
@Override
public void buyProduct(Product product) {
}
}

View File

@ -0,0 +1,8 @@
package cz.cvut.fel.sit.omo.foodchain.node;
import cz.cvut.fel.sit.omo.foodchain.product.Product;
public interface SellerNodeInterface {
void buyProduct(Product product);
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.operation;
public class Action extends OperationBase {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.operation;
public class FinancialTransaction extends Transaction {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.operation;
public class OperationBase {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.operation;
public interface OperationInterface {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.operation;
public enum ProductOperationType {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.operation;
public class ProductTransaction extends Transaction {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.operation;
public abstract class Transaction extends OperationBase {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.operation;
public enum TransactionType {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.parser;
public class ConfigurationParser {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.parser;
public class ConsoleParser {
}

View File

@ -0,0 +1,6 @@
package cz.cvut.fel.sit.omo.foodchain.pool;
import cz.cvut.fel.sit.omo.foodchain.channel.Channel;
public class ChannelPool extends PoolListBase<Channel> {
}

View File

@ -1,4 +1,44 @@
package cz.cvut.fel.sit.omo.foodchain.pool;
import cz.cvut.fel.sit.omo.foodchain.util.Singleton;
import java.lang.reflect.InvocationTargetException;
public class PoolDatabase {
public ChannelPool getChannelPoolInstance() {
try {
return Singleton.getInstance(ChannelPool.class);
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
public NodePool getNodePoolInstance() {
try {
return Singleton.getInstance(NodePool.class);
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
public ProductPool getProductPoolInstance() {
try {
return Singleton.getInstance(ProductPool.class);
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
public ScenarioPool getScenarioPoolInstance() {
try {
return Singleton.getInstance(ScenarioPool.class);
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -6,8 +6,10 @@ public interface PoolInterface<T> {
Collection<T> findAll();
void add(T element);
void remove(T element);
void clear();
boolean contains(T element);
}

View File

@ -1,6 +1,8 @@
package cz.cvut.fel.sit.omo.foodchain.pool;
import java.util.*;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
public abstract class PoolListBase<T> implements PoolInterface<T> {
List<T> pool;

View File

@ -0,0 +1,6 @@
package cz.cvut.fel.sit.omo.foodchain.pool;
import cz.cvut.fel.sit.omo.foodchain.product.Product;
public class ProductPool extends PoolListBase<Product> {
}

View File

@ -0,0 +1,6 @@
package cz.cvut.fel.sit.omo.foodchain.pool;
import cz.cvut.fel.sit.omo.foodchain.scenario.Scenario;
public class ScenarioPool extends PoolListBase<Scenario> {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.product;
public class Product {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.product;
public class ProductState {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.product;
public enum ProductType {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.reporting;
public class ReportTextFileVisitor {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.reporting;
public class ReportingManager {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.requirement;
public class Requirement {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.scenario;
public class Scenario {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.signature;
public class Signature {
}

View File

@ -0,0 +1,4 @@
package cz.cvut.fel.sit.omo.foodchain.signature;
public class SignatureManager {
}

View File

@ -0,0 +1,27 @@
package cz.cvut.fel.sit.omo.foodchain.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
public class Singleton {
private static final Singleton instance = new Singleton();
@SuppressWarnings("rawtypes")
private final Map<Class, Object> mapHolder = new HashMap<Class, Object>();
private Singleton() {
}
public static <T> T getInstance(Class<T> tClass) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
if (!instance.mapHolder.containsKey(tClass)) {
Constructor<T> cons = tClass.getConstructor();
Object object = cons.newInstance();
instance.mapHolder.put(tClass, object);
}
return (T) instance.mapHolder.get(tClass);
}
}