X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural2%2Fsrc%2Forg%2Fsimantics%2Fstructural2%2Fvariables%2FPairConnectionDescriptor.java;h=ee0a7fa2c0b108c3124def4ec220722e42e7f4d9;hb=c433e87787fb162d3f5d966678aaedf491266080;hp=0273dbd7bed473adbeadf3c912351d3b6e62b3ac;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/PairConnectionDescriptor.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/PairConnectionDescriptor.java index 0273dbd7b..ee0a7fa2c 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/PairConnectionDescriptor.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/variables/PairConnectionDescriptor.java @@ -1,80 +1,80 @@ -package org.simantics.structural2.variables; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; -import org.simantics.db.common.request.UnaryRead; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.utils.datastructures.Pair; - -public class PairConnectionDescriptor extends AbstractVariableConnectionPointDescriptor { - - public Variable base; - public Pair pair; - - public PairConnectionDescriptor(Variable base, Pair pair) { - this.base = base; - this.pair = pair; - } - @Override - public int hashCode() { - return base.hashCode() + 31*pair.hashCode(); - } - @Override - public boolean equals(Object object) { - if (this == object) - return true; - else if (object == null) - return false; - else if (!(object instanceof PairConnectionDescriptor)) - return false; - PairConnectionDescriptor r = (PairConnectionDescriptor)object; - if(!r.pair.equals(pair)) return false; - if(!r.base.equals(base)) return false; - return true; - } - - static class ComputeVariable extends UnaryRead { - - public ComputeVariable(PairConnectionDescriptor desc) { - super(desc); - } - - @Override - public Variable perform(ReadGraph graph) throws DatabaseException { - return parameter.base.getChild(graph, parameter.pair.first).getProperty(graph, parameter.pair.second); - } - - } - @Override - public Variable getVariable(ReadGraph graph) throws DatabaseException { - return graph.syncRequest(new ComputeVariable(this), TransientCacheAsyncListener.instance()); - } - public String getURI(ReadGraph graph) throws DatabaseException { - return getVariable(graph).getURI(graph); - } - @Override - public Resource getConnectionPointResource(ReadGraph graph) throws DatabaseException { - return getVariable(graph).getPossiblePredicateResource(graph); - } - - @Override - public boolean isFlattenedFrom(ReadGraph graph, Variable possiblyStructuralCp) throws DatabaseException { - - Variable parent = possiblyStructuralCp.getParent(graph); - - String descURI = getURI(graph); - String parentURI = parent.getURI(graph); - if(descURI.startsWith(parentURI)) { - // Children are in substructure - if('/' == descURI.charAt(parentURI.length())) return true; - // Otherwise require exact match - return descURI.endsWith(possiblyStructuralCp.getName(graph)); - } else { - return false; - } - - } - +package org.simantics.structural2.variables; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; +import org.simantics.db.common.request.UnaryRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.utils.datastructures.Pair; + +public class PairConnectionDescriptor extends AbstractVariableConnectionPointDescriptor { + + public Variable base; + public Pair pair; + + public PairConnectionDescriptor(Variable base, Pair pair) { + this.base = base; + this.pair = pair; + } + @Override + public int hashCode() { + return base.hashCode() + 31*pair.hashCode(); + } + @Override + public boolean equals(Object object) { + if (this == object) + return true; + else if (object == null) + return false; + else if (!(object instanceof PairConnectionDescriptor)) + return false; + PairConnectionDescriptor r = (PairConnectionDescriptor)object; + if(!r.pair.equals(pair)) return false; + if(!r.base.equals(base)) return false; + return true; + } + + static class ComputeVariable extends UnaryRead { + + public ComputeVariable(PairConnectionDescriptor desc) { + super(desc); + } + + @Override + public Variable perform(ReadGraph graph) throws DatabaseException { + return parameter.base.getChild(graph, parameter.pair.first).getProperty(graph, parameter.pair.second); + } + + } + @Override + public Variable getVariable(ReadGraph graph) throws DatabaseException { + return graph.syncRequest(new ComputeVariable(this), TransientCacheAsyncListener.instance()); + } + public String getURI(ReadGraph graph) throws DatabaseException { + return getVariable(graph).getURI(graph); + } + @Override + public Resource getConnectionPointResource(ReadGraph graph) throws DatabaseException { + return getVariable(graph).getPossiblePredicateResource(graph); + } + + @Override + public boolean isFlattenedFrom(ReadGraph graph, Variable possiblyStructuralCp) throws DatabaseException { + + Variable parent = possiblyStructuralCp.getParent(graph); + + String descURI = getURI(graph); + String parentURI = parent.getURI(graph); + if(descURI.startsWith(parentURI)) { + // Children are in substructure + if('/' == descURI.charAt(parentURI.length())) return true; + // Otherwise require exact match + return descURI.endsWith(possiblyStructuralCp.getName(graph)); + } else { + return false; + } + + } + } \ No newline at end of file