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;
18 * To be removed in Nitrogen
21 public class XSQLBluePrintRelation implements Serializable {
22 private static final long serialVersionUID = 2L;
23 private XSQLBluePrintNode parent = null;
24 private String property = null;
25 private Class<?> childClass = null;
27 public XSQLBluePrintRelation(XSQLBluePrintNode _parent, String _property,
28 Class<?> _childClass) {
29 this.parent = _parent;
30 this.property = _property;
31 this.childClass = _childClass;
34 public Class<?> getNEClosestClass() {
35 Class<?> p = parent.getInterface();
36 return getNEClosestClass(p);
40 public static Class<?> getNEClosestClass(Class<?> p) {
41 while (!p.getInterfaces()[0]
42 .equals(Object.class/*XSQLBluePrint.STOP_INTERFACE*/)) {
43 p = p.getInterfaces()[0];
48 public XSQLBluePrintNode getParent() {
52 public String getProperty() {
56 public Class<?> getChildClass() {
57 return this.childClass;
60 public boolean equals(Object obj) {
61 XSQLBluePrintRelation other = (XSQLBluePrintRelation) obj;
62 if (other.parent != null && this.parent == null) {
65 if (other.parent == null && this.parent != null) {
69 if (other.parent == null && this.parent == null) {
70 return property.equals(other.property);
73 if (other.parent.toString().equals(this.parent.toString())) {
74 return property.equals(other.property);
80 public int hashCode() {
82 return parent.toString().hashCode() + property.hashCode();
84 return property.hashCode();
87 public String toString() {
89 return parent.toString() + ":" + property;
95 public List<?> execute(Object o) {
100 List<Object> result = new LinkedList<>();
101 if (o instanceof Set) {
102 for (Object oo : (Set<?>) o) {
103 addToResult(result, execute(oo));
105 } else if (o instanceof List) {
106 for (Object oo : (List<?>) o) {
107 addToResult(result, execute(oo));
109 } else if (o instanceof Map) {
110 for (Object oo : ((Map<?, ?>) o).values()) {
111 addToResult(result, execute(oo));
114 addToResult(result, XSQLCriteria.getValue(o, this.property));
119 private static void addToResult(List<Object> result, Object o) {
120 if (o instanceof Set) {
121 result.addAll((Set<?>)o);
122 } else if (o instanceof List) {
123 result.addAll((List<?>)o);
124 } else if (o instanceof Map) {
125 result.addAll(((Map<?, ?>)o).values());
126 } else if (o != null) {