2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.md.sal.dom.xsql;
11 import java.io.Serializable;
12 import java.util.LinkedList;
13 import java.util.List;
17 public class XSQLBluePrintRelation implements Serializable {
18 private static final long serialVersionUID = 2L;
19 private XSQLBluePrintNode parent = null;
20 private String property = null;
21 private Class<?> childClass = null;
23 public XSQLBluePrintRelation(XSQLBluePrintNode _parent, String _property,
24 Class<?> _childClass) {
25 this.parent = _parent;
26 this.property = _property;
27 this.childClass = _childClass;
30 public Class<?> getNEClosestClass() {
31 Class<?> p = parent.getInterface();
32 return getNEClosestClass(p);
36 public static Class<?> getNEClosestClass(Class<?> p) {
37 while (!p.getInterfaces()[0]
38 .equals(Object.class/*XSQLBluePrint.STOP_INTERFACE*/)) {
39 p = p.getInterfaces()[0];
44 public XSQLBluePrintNode getParent() {
48 public String getProperty() {
52 public Class<?> getChildClass() {
53 return this.childClass;
56 public boolean equals(Object obj) {
57 XSQLBluePrintRelation other = (XSQLBluePrintRelation) obj;
58 if (other.parent != null && this.parent == null) {
61 if (other.parent == null && this.parent != null) {
65 if (other.parent == null && this.parent == null) {
66 return property.equals(other.property);
69 if (other.parent.toString().equals(this.parent.toString())) {
70 return property.equals(other.property);
76 public int hashCode() {
78 return parent.toString().hashCode() + property.hashCode();
80 return property.hashCode();
83 public String toString() {
85 return parent.toString() + ":" + property;
91 public List<?> execute(Object o) {
96 List<Object> result = new LinkedList<>();
97 if (o instanceof Set) {
98 for (Object oo : (Set<?>) o) {
99 addToResult(result, execute(oo));
101 } else if (o instanceof List) {
102 for (Object oo : (List<?>) o) {
103 addToResult(result, execute(oo));
105 } else if (o instanceof Map) {
106 for (Object oo : ((Map<?, ?>) o).values()) {
107 addToResult(result, execute(oo));
110 addToResult(result, XSQLCriteria.getValue(o, this.property));
115 private static void addToResult(List<Object> result, Object o) {
116 if (o instanceof Set) {
117 result.addAll((Set<?>)o);
118 } else if (o instanceof List) {
119 result.addAll((List<?>)o);
120 } else if (o instanceof Map) {
121 result.addAll(((Map<?, ?>)o).values());
122 } else if (o != null) {