1 package org.opendaylight.controller.md.sal.dom.xsql;
3 import java.io.Serializable;
4 import java.util.LinkedList;
9 public class XSQLBluePrintRelation implements Serializable {
10 private static final long serialVersionUID = 2L;
11 private XSQLBluePrintNode parent = null;
12 private String property = null;
13 private Class<?> childClass = null;
15 public XSQLBluePrintRelation(XSQLBluePrintNode _parent, String _property,
16 Class<?> _childClass) {
17 this.parent = _parent;
18 this.property = _property;
19 this.childClass = _childClass;
22 public Class<?> getNEClosestClass() {
23 Class<?> p = parent.getInterface();
24 return getNEClosestClass(p);
28 public static Class<?> getNEClosestClass(Class<?> p) {
29 while (!p.getInterfaces()[0]
30 .equals(Object.class/*XSQLBluePrint.STOP_INTERFACE*/)) {
31 p = p.getInterfaces()[0];
36 public XSQLBluePrintNode getParent() {
40 public String getProperty() {
44 public Class<?> getChildClass() {
45 return this.childClass;
48 public boolean equals(Object obj) {
49 XSQLBluePrintRelation other = (XSQLBluePrintRelation) obj;
50 if (other.parent != null && this.parent == null) {
53 if (other.parent == null && this.parent != null) {
57 if (other.parent == null && this.parent == null) {
58 return property.equals(other.property);
61 if (other.parent.toString().equals(this.parent.toString())) {
62 return property.equals(other.property);
68 public int hashCode() {
70 return parent.toString().hashCode() + property.hashCode();
72 return property.hashCode();
75 public String toString() {
77 return parent.toString() + ":" + property;
83 public List<?> execute(Object o) {
88 List<Object> result = new LinkedList<>();
89 if (o instanceof Set) {
90 for (Object oo : (Set<?>) o) {
91 addToResult(result, execute(oo));
93 } else if (o instanceof List) {
94 for (Object oo : (List<?>) o) {
95 addToResult(result, execute(oo));
97 } else if (o instanceof Map) {
98 for (Object oo : ((Map<?, ?>) o).values()) {
99 addToResult(result, execute(oo));
102 addToResult(result, XSQLCriteria.getValue(o, this.property));
107 private static void addToResult(List<Object> result, Object o) {
108 if (o instanceof Set) {
109 result.addAll((Set<?>)o);
110 } else if (o instanceof List) {
111 result.addAll((List<?>)o);
112 } else if (o instanceof Map) {
113 result.addAll(((Map<?, ?>)o).values());
114 } else if (o != null) {