Added nodes
This commit is contained in:
parent
12033e0f6e
commit
5169427a28
37
src/eu/lixko/ext/forraceexpander/Main.java
Normal file
37
src/eu/lixko/ext/forraceexpander/Main.java
Normal file
@ -0,0 +1,37 @@
|
||||
package eu.lixko.ext.forraceexpander;
|
||||
|
||||
import eu.lixko.ext.forraceexpander.components.Node;
|
||||
import eu.lixko.ext.forraceexpander.components.Parent;
|
||||
import eu.lixko.ext.forraceexpander.components.Property;
|
||||
import eu.lixko.ext.forraceexpander.exporter.TreeSerializerProvider;
|
||||
import eu.lixko.ext.forraceexpander.exporter.TreeTestSerializer;
|
||||
import eu.lixko.ext.forraceexpander.importer.OrderImporter;
|
||||
|
||||
public class Main {
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Parent main = new Parent("main");
|
||||
Parent child = new Parent("child1");
|
||||
child.addProperty("prop", "sumtext");
|
||||
|
||||
Property<String> prop = new Property<>("property1");
|
||||
prop.setData("ayy lmao");
|
||||
|
||||
child.addCloneChild(prop);
|
||||
|
||||
main.addCloneChild(child);
|
||||
|
||||
System.out.println(">>> " + main.getChildByNameFirst("child1"));
|
||||
|
||||
TreeSerializerProvider serializer = new TreeTestSerializer();
|
||||
System.out.println(serializer.serialize(main));
|
||||
|
||||
//OrderImporter orderImporter = new OrderImporter();
|
||||
//orderImporter.run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package eu.lixko.ext.forraceexpander.components;
|
||||
|
||||
public class Item extends SerializableComponent {
|
||||
|
||||
private long itemID = 0, productCode = 0, priceUnit = 0, priceTotal = 0, priceTotalWithTax = 0;
|
||||
private int qty = 0;
|
||||
private String name = "", ean = "";
|
||||
|
48
src/eu/lixko/ext/forraceexpander/components/Node.java
Normal file
48
src/eu/lixko/ext/forraceexpander/components/Node.java
Normal file
@ -0,0 +1,48 @@
|
||||
package eu.lixko.ext.forraceexpander.components;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Node {
|
||||
|
||||
public String type = "node";
|
||||
protected Node parent = null;
|
||||
protected String name = "";
|
||||
protected HashMap<String, String> properties = new HashMap<>();
|
||||
|
||||
public Node(Node parent, String name) {
|
||||
this.parent = parent;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Node(Node src) {
|
||||
this.parent = src.parent;
|
||||
this.name = src.name;
|
||||
this.properties = new HashMap<String, String>(src.properties);
|
||||
this.type = src.type;
|
||||
}
|
||||
|
||||
public Node(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Node getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getProperties() {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
public void addProperty(String name, String value) {
|
||||
properties.put(name, value);
|
||||
}
|
||||
|
||||
public String getProperty(String name) {
|
||||
return properties.get(name);
|
||||
}
|
||||
|
||||
}
|
55
src/eu/lixko/ext/forraceexpander/components/Parent.java
Normal file
55
src/eu/lixko/ext/forraceexpander/components/Parent.java
Normal file
@ -0,0 +1,55 @@
|
||||
package eu.lixko.ext.forraceexpander.components;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Parent extends Node {
|
||||
|
||||
private ArrayList<Node> children = new ArrayList<>();
|
||||
|
||||
public Parent(Parent src) {
|
||||
super(src);
|
||||
for(Node c : src.children) {
|
||||
this.children.add(new Node(c));
|
||||
}
|
||||
}
|
||||
|
||||
public Parent(String name) {
|
||||
super(name);
|
||||
this.type = "parent";
|
||||
}
|
||||
|
||||
public Parent(Parent parent, String name) {
|
||||
super(name);
|
||||
this.parent = parent;
|
||||
this.type = "parent";
|
||||
}
|
||||
|
||||
public ArrayList<Node> getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
public void addChild(Node child) {
|
||||
this.children.add(child);
|
||||
}
|
||||
|
||||
public void addCloneChild(Parent child) {
|
||||
Parent p = new Parent(child);
|
||||
p.parent = this;
|
||||
this.children.add(p);
|
||||
}
|
||||
|
||||
public void addCloneChild(Property<?> child) {
|
||||
Property<?> n = new Property<>(child);
|
||||
n.parent = this;
|
||||
this.children.add(n);
|
||||
}
|
||||
|
||||
public Node getChildByNameFirst(String name) {
|
||||
for(Node n : children) {
|
||||
if(n.getName() == name)
|
||||
return n;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
30
src/eu/lixko/ext/forraceexpander/components/Property.java
Normal file
30
src/eu/lixko/ext/forraceexpander/components/Property.java
Normal file
@ -0,0 +1,30 @@
|
||||
package eu.lixko.ext.forraceexpander.components;
|
||||
|
||||
public class Property<T> extends Node {
|
||||
|
||||
private T data;
|
||||
|
||||
public Property(Property<T> src) {
|
||||
super(src);
|
||||
this.data = src.data;
|
||||
}
|
||||
|
||||
public Property(String name) {
|
||||
super(name);
|
||||
this.type = "prop";
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package eu.lixko.ext.forraceexpander.exporter;
|
||||
|
||||
import eu.lixko.ext.forraceexpander.components.Node;
|
||||
|
||||
public interface TreeSerializerProvider {
|
||||
|
||||
public String serialize(Node n);
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package eu.lixko.ext.forraceexpander.exporter;
|
||||
|
||||
import eu.lixko.ext.forraceexpander.components.Node;
|
||||
import eu.lixko.ext.forraceexpander.components.Parent;
|
||||
import eu.lixko.ext.forraceexpander.components.Property;
|
||||
|
||||
public class TreeTestSerializer implements TreeSerializerProvider {
|
||||
|
||||
@Override
|
||||
public String serialize(Node n) {
|
||||
return serialize(n, 0);
|
||||
}
|
||||
|
||||
public String serialize(Node n, int level) {
|
||||
String res = "";
|
||||
for(int i = 0; i < level; i++)
|
||||
res += "\t";
|
||||
if(n instanceof Parent) {
|
||||
Parent p = (Parent) n;
|
||||
res += "P " + p.getName() + ": \n";
|
||||
for(Node c : p.getChildren()) {
|
||||
res += serialize(c, level + 1);
|
||||
}
|
||||
} else if(n instanceof Property) {
|
||||
Property<?> p = (Property<?>) n;
|
||||
res += "O " + p.getName() + " = " + p.getData();
|
||||
} else {
|
||||
System.out.println("EXC: " + n.getName() + " / " + n.type);
|
||||
System.out.println(n.getClass());
|
||||
System.out.println("> " + (Property.class.isAssignableFrom(n.getClass())));
|
||||
res += "else\n";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user