X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FProxyChildVariable.java;h=6ee8a53845fb0f97351183e6ffa3a145f937c1ff;hb=3c2807a26920491016a1887d2c1a95609c082a19;hp=ade81ce5a39b941402db49242e39acd69c6337d2;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyChildVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyChildVariable.java index ade81ce5a..6ee8a5384 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyChildVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyChildVariable.java @@ -1,120 +1,120 @@ -package org.simantics.db.layer0.variable; - -import java.util.ArrayList; -import java.util.Collection; - -import org.simantics.db.ReadGraph; -import org.simantics.db.exception.DatabaseException; - -public class ProxyChildVariable extends AbstractChildVariable { - - public static final String CONTEXT_BEGIN = ">>>"; - public static final String CONTEXT_END = "<<<"; - - // This is the variable that shall be returned to - protected final Variable base; - // Actual parent of this variable - protected final Variable parent; - // This is the accumulated context variable that is queries for children - protected final Variable other; - protected final String name; - - public ProxyChildVariable(Variable base, Variable parent, Variable other, String name) { - assert(base != null); - assert(parent != null); - assert(other != null); - assert(name != null); - this.base = base; - this.parent = parent; - this.other = other; - this.name = name; - } - - public Variable other() { - return other; - } - - public Variable base() { - return base; - } - - @Override - public String getName(ReadGraph graph) throws DatabaseException { - return name; - } - @Override - public Variable getParent(ReadGraph graph) throws DatabaseException { - return parent; - } - - public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { - Variable otherChild = other.getPossibleChild(graph, name); - if(otherChild == null) return null; - return create(base, this, otherChild, name); - } - - public Collection getChildren(ReadGraph graph) throws DatabaseException { - - ArrayList result = new ArrayList(); - Collection otherChildren = other.browseChildren(graph); - for(Variable o : otherChildren) { - result.add(create(base, this, o, o.getName(graph))); - } - return result; - - } - - public Variable getPossibleProperty(ReadGraph graph, String name) throws DatabaseException { - Variable otherChild = other.getPossibleProperty(graph, name); - if(otherChild == null) return null; - return create(base, this, otherChild, name); - } - - public Variable create(Variable base, Variable parent, Variable other, String name) { - return new ProxyChildVariable(base, parent, other, name); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (base != null ? base.hashCode() : 0); - result = prime * result + (parent != null ? parent.hashCode() : 0); - result = prime * result + (other != null ? other.hashCode() : 0); - result = prime * result + (name != null ? name.hashCode() : 0); - return result; - } - - @Override - public boolean equals(Object obj) { - - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - - ProxyChildVariable proxy = (ProxyChildVariable) obj; - - if(base != null) { - if(!base.equals(proxy.base)) return false; - } else if (proxy.base != null) return false; - - if(parent != null) { - if(!parent.equals(proxy.parent)) return false; - } else if (proxy.parent != null) return false; - - if(other != null) { - if(!other.equals(proxy.other)) return false; - } else if (proxy.other != null) return false; - - if(name != null) { - if(!name.equals(proxy.name)) return false; - } else if (proxy.name != null) return false; - - return true; - - } - -} +package org.simantics.db.layer0.variable; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; + +public class ProxyChildVariable extends AbstractChildVariable { + + public static final String CONTEXT_BEGIN = ">>>"; + public static final String CONTEXT_END = "<<<"; + + // This is the variable that shall be returned to + protected final Variable base; + // Actual parent of this variable + protected final Variable parent; + // This is the accumulated context variable that is queries for children + protected final Variable other; + protected final String name; + + public ProxyChildVariable(Variable base, Variable parent, Variable other, String name) { + assert(base != null); + assert(parent != null); + assert(other != null); + assert(name != null); + this.base = base; + this.parent = parent; + this.other = other; + this.name = name; + } + + public Variable other() { + return other; + } + + public Variable base() { + return base; + } + + @Override + public String getName(ReadGraph graph) throws DatabaseException { + return name; + } + @Override + public Variable getParent(ReadGraph graph) throws DatabaseException { + return parent; + } + + public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { + Variable otherChild = other.getPossibleChild(graph, name); + if(otherChild == null) return null; + return create(base, this, otherChild, name); + } + + public Collection getChildren(ReadGraph graph) throws DatabaseException { + + ArrayList result = new ArrayList(); + Collection otherChildren = other.browseChildren(graph); + for(Variable o : otherChildren) { + result.add(create(base, this, o, o.getName(graph))); + } + return result; + + } + + public Variable getPossibleProperty(ReadGraph graph, String name) throws DatabaseException { + Variable otherChild = other.getPossibleProperty(graph, name); + if(otherChild == null) return null; + return create(base, this, otherChild, name); + } + + public Variable create(Variable base, Variable parent, Variable other, String name) { + return new ProxyChildVariable(base, parent, other, name); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (base != null ? base.hashCode() : 0); + result = prime * result + (parent != null ? parent.hashCode() : 0); + result = prime * result + (other != null ? other.hashCode() : 0); + result = prime * result + (name != null ? name.hashCode() : 0); + return result; + } + + @Override + public boolean equals(Object obj) { + + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + + ProxyChildVariable proxy = (ProxyChildVariable) obj; + + if(base != null) { + if(!base.equals(proxy.base)) return false; + } else if (proxy.base != null) return false; + + if(parent != null) { + if(!parent.equals(proxy.parent)) return false; + } else if (proxy.parent != null) return false; + + if(other != null) { + if(!other.equals(proxy.other)) return false; + } else if (proxy.other != null) return false; + + if(name != null) { + if(!name.equals(proxy.name)) return false; + } else if (proxy.name != null) return false; + + return true; + + } + +}