Преглед на файлове

small changes for new Storing

Teh-Hai Julian Zheng преди 7 години
родител
ревизия
12cb250278

+ 25 - 0
src/Serializer/CpsObjectDeserializer.java

@@ -0,0 +1,25 @@
+package Serializer;
+
+import java.lang.reflect.Type;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+
+import classes.AbstractCpsObject;
+
+public class CpsObjectDeserializer implements JsonDeserializer<AbstractCpsObject>{
+
+	@Override
+	public AbstractCpsObject deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2){
+		// TODO Auto-generated method stub
+		try {
+			
+		} catch (Exception e) {
+			// TODO: handle exception
+		}
+		return null;
+	}
+
+}

+ 20 - 0
src/Serializer/CpsObjectSerializer.java

@@ -0,0 +1,20 @@
+package Serializer;
+
+import java.lang.reflect.Type;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+
+import classes.AbstractCpsObject;
+
+public class CpsObjectSerializer implements JsonSerializer<AbstractCpsObject>{
+
+	@Override
+	public JsonElement serialize(AbstractCpsObject arg0, Type arg1, JsonSerializationContext arg2) {
+		// TODO Auto-generated method stub
+		return new JsonPrimitive(arg0.getID());
+	}
+
+}

+ 31 - 24
src/classes/AbstractCpsObject.java

@@ -15,29 +15,35 @@ import com.google.gson.annotations.Expose;
  */
 public abstract class AbstractCpsObject {
 	/* Type of the Object. */
-	@Expose String objName;
+	@Expose
+	String objName;
 	/* Name given by the user. */
-	@Expose String name;
+	@Expose
+	String name;
 	/* ID of the Obj. */
-	@Expose int id;
+	@Expose
+	int id;
 	/* Path of the image for the Obj. */
-	@Expose String image;
+	@Expose
+	String image;
 	/* Array of neighbors */
 	ArrayList<CpsEdge> connections;
 	/* Position with a X and Y value */
-	@Expose Position position;
+	@Expose
+	Position position;
 	/*
 	 * Energy input and output of each object in the grid Where the Object is
 	 * Stored
 	 */
-	@Expose String sav;
+	@Expose
+	String sav;
 	/* borderColor the user sets */
 	Color borderColor = Color.WHITE;
 	/* a Tag that can be used */
 	ArrayList<Integer> tags;
 	/* a Tag that can be used */
 	ArrayList<Integer> pseudoTags;
-	
+
 	/**
 	 * Constructor for a CpsObejct with an unique ID.
 	 * 
@@ -246,7 +252,7 @@ public abstract class AbstractCpsObject {
 	 * Set the Border Color of this CpsObject.
 	 * 
 	 * @param c
-	 *          the BorderColor
+	 *            the BorderColor
 	 */
 	public void setBorderColor(Color c) {
 		this.borderColor = c;
@@ -259,13 +265,13 @@ public abstract class AbstractCpsObject {
 	 *            for internal purpose
 	 */
 	public void addTag(int tag) {
-		if(!(tags.contains(tag))){
+		if (!(tags.contains(tag))) {
 			this.tags.add(tag);
 		}
 	}
-	
-	public void addAllTags(ArrayList<Integer> tags){
-		for(Integer tag: tags){
+
+	public void addAllTags(ArrayList<Integer> tags) {
+		for (Integer tag : tags) {
 			addTag(tag);
 		}
 	}
@@ -304,9 +310,9 @@ public abstract class AbstractCpsObject {
 	 *            for internal purpose
 	 */
 	public void setPseudoTags(ArrayList<Integer> tags) {
-		this.pseudoTags= tags;
+		this.pseudoTags = tags;
 	}
-	
+
 	/**
 	 * Get the pseudo tags.
 	 * 
@@ -315,37 +321,38 @@ public abstract class AbstractCpsObject {
 	public ArrayList<Integer> getPseudoTags() {
 		return this.pseudoTags;
 	}
-	
+
 	/**
 	 * add a pseudo tag.
 	 * 
 	 * @return ArrayList
 	 */
 	public void addPseudoTag(int tag) {
-		if(!pseudoTags.contains(tag)){
+		if (!pseudoTags.contains(tag)) {
 			pseudoTags.add(tag);
 		}
 	}
-	
+
 	/**
 	 * adds all given pseudotags to the tags
+	 * 
 	 * @param pseudoTags
 	 */
-	public void addAllPseudoTags(ArrayList<Integer> pseudoTags){
-		for(Integer tag: pseudoTags){
+	public void addAllPseudoTags(ArrayList<Integer> pseudoTags) {
+		for (Integer tag : pseudoTags) {
 			addPseudoTag(tag);
 		}
 	}
-	
+
 	/**
 	 * adds All pseudoTags to tags without duplicates
 	 */
-	public void recalculateTags(){
-		for(Integer tag: pseudoTags){
-			if(!tags.contains(tag)){
+	public void recalculateTags() {
+		for (Integer tag : pseudoTags) {
+			if (!tags.contains(tag)) {
 				tags.add(tag);
 			}
 		}
 	}
-	
+
 }

+ 8 - 0
src/classes/CpsEdge.java

@@ -2,6 +2,8 @@ package classes;
 
 import java.util.ArrayList;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * The class "CpsEdge" represents the connections on the GUI. Each connection
  * contains a max. capacity, a flow, a status (isWorking), tags (for internal
@@ -14,8 +16,10 @@ public class CpsEdge {
 
 	// Max. capacity of the Edge, if flow is greater than the status --> is
 	// Working would be false
+	@Expose
 	float maxCapacity;
 	// Current flow of electricity (through the edge)
+	@Expose
 	float flow;
 	/*
 	 * Represents the actual status of the Edge (true = flows electricity; false
@@ -23,20 +27,24 @@ public class CpsEdge {
 	 * it breaks --> stay ruin no matter the actual scenario The only way to
 	 * repair it is through manual change (setStateEdge)
 	 */
+	@Expose
 	boolean isWorking;
 	
 	/*
 	 * Is true when a Connection to an Group Object, is connected inside the Group. 
 	 * Is false when not
 	 */
+	@Expose
 	boolean isConnected;
 	// for internal use --> flow of electricity (simulation state)
 	ArrayList<Integer> tags;
 	// for internal use --> flow of electricity (simulation state)
 	ArrayList<Integer> pseudoTags;
 	// Source
+	@Expose
 	AbstractCpsObject a;
 	// Destination
+	@Expose
 	AbstractCpsObject b;
 
 	/**

+ 11 - 0
src/classes/HolonElement.java

@@ -3,6 +3,8 @@ package classes;
 import java.awt.Point;
 import java.util.LinkedList;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * The class "HolonElement" represents any possible element that can be added to
  * a CpsObject (such as TV (consumer) or any energy source/producer).
@@ -13,22 +15,31 @@ import java.util.LinkedList;
 public class HolonElement {
 
 	/* Name of the gadget */
+	@Expose
 	private String eleName;
 	/* Quantity */
+	@Expose
 	private int amount;
 	/* Energy per gadget */
+	@Expose
 	private float energy;
 	/* If the gadget is working xor not (true xor false) */
+	@Expose
 	private boolean active;
+	@Expose
 	/* Total Energy */
 	private float totalEnergy;
 	/* +: for Consumers and -: Producers */
+	@Expose
 	private char sign;
 	/* Place where the Object is Stored */
+	@Expose
 	private String sav;
 	/* Object where the Element is Stored */
+	@Expose
 	private String obj;
 	/* Unique Id of the Element */
+	@Expose
 	private int id; 
 	/*
 	 * Energy at each point of the graph with 100 predefined points. At the

+ 5 - 0
src/classes/HolonSwitch.java

@@ -3,6 +3,8 @@ package classes;
 import java.awt.Point;
 import java.util.LinkedList;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * The class HolonSwitch represents a Switch, which can be turned on and off.
  * 
@@ -23,17 +25,20 @@ public class HolonSwitch extends AbstractCpsObject {
 	 * manual state True, if this wire is working (capable of carrying
 	 * electricity), else false
 	 */
+	@Expose
 	boolean manualActive;
 
 	/*
 	 * active state True, if this wire is working (capable of carrying
 	 * electricity), else false
 	 */
+	@Expose
 	boolean autoActive;
 
 	/*
 	 * true if switch has to be used manually
 	 */
+	@Expose
 	boolean manualMode;
 
 	/*

+ 3 - 0
src/classes/IdCounter.java

@@ -1,11 +1,14 @@
 package classes;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * ID-Counter for all Cps Objects.
  * 
  * @author Gruppe14
  */
 public class IdCounter {
+	@Expose
 	private static int counter = 1;
 
 	/**

+ 3 - 0
src/classes/IdCounterElem.java

@@ -1,11 +1,14 @@
 package classes;
 
+import com.google.gson.annotations.Expose;
+
 /**
  * ID-Counter for all Holon Elements.
  * 
  * @author Gruppe14
  */
 public class IdCounterElem {
+	@Expose
 	private static int counter = 1;
 
 	/**