Added project, added some classes and interfaces

This commit is contained in:
Nikita Iryupin 2020-11-21 11:59:32 +01:00
parent 2924024ae4
commit 1d04bb6dc7
16 changed files with 194 additions and 0 deletions

BIN
EAR diagrams/FoodChain.ldb Normal file

Binary file not shown.

2
FoodChain.iml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

16
pom.xml Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.cvut.fel.sit.omo.foodchain</groupId>
<artifactId>FoodChain</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.target>12</maven.compiler.target>
<maven.compiler.source>12</maven.compiler.source>
</properties>
</project>

View File

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

View File

@ -0,0 +1,49 @@
package cz.cvut.fel.sit.omo.foodchain.factory;
public class FactoryManager {
public NodeFactory getNodeFactoryInstance(){
try {
return Singleton.getInstance(NodeFactory.class);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
return null;
}
public ChannelFactory getChannelFactoryInstance(){
try {
return Singleton.getInstance(ChannelFactory.class);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
return null;
}
public ScenarioFactory getScenarioFactoryInstance(){
try {
return Singleton.getInstance(ScenarioFactory.class);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
return null;
}
public ProductFactory getProductFactoryInstance(){
try {
return Singleton.getInstance(ProductFactory.class);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
return null;
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,24 @@
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

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

View File

@ -0,0 +1,25 @@
package cz.cvut.fel.sit.omo.foodchain.node;
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 acceptRequirement(Requirement requirement);
void subscribeToChannel(ChannelInterface channel);
void unsubscribeFromChannel(ChannelInterface channel);
void doAction(Action action, Product product);
void doAction(Action action);
void storeProduct(Product product);
void storeProducts(List<Product> 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 SellerNodeBase implements NodeInterface {
}

View File

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

View File

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

View File

@ -0,0 +1,13 @@
package cz.cvut.fel.sit.omo.foodchain.pool;
import java.util.Collection;
public interface PoolInterface<T> {
Collection<T> findAll();
void add(T element);
void remove(T element);
void clear();
boolean contains(T element);
}

View File

@ -0,0 +1,31 @@
package cz.cvut.fel.sit.omo.foodchain.pool;
import java.util.*;
public abstract class PoolListBase<T> implements PoolInterface<T> {
List<T> pool;
public PoolListBase() {
pool = new LinkedList<T>();
}
public Collection<T> findAll() {
return pool;
}
public void add(T element) {
pool.add(element);
}
public void remove(T element) {
pool.remove(element);
}
public void clear() {
pool.clear();
}
public boolean contains(T element) {
return pool.contains(element);
}
}