X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Frequest%2FAdapt.java;fp=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Frequest%2FAdapt.java;h=488b6ac63b9f1c78f69cb944143d833fb175a944;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=3ca5a7362052b9a685d6968c93073c2af71ffe32;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/Adapt.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/Adapt.java index 3ca5a7362..488b6ac63 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/Adapt.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/Adapt.java @@ -1,78 +1,78 @@ -package org.simantics.db.common.request; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.AdaptionException; -import org.simantics.db.exception.ServiceException; -import org.simantics.db.exception.ValidationException; - -/** - * @author Tuukka Lehtonen - * - * @param the adaption target interface - */ -public class Adapt extends ResourceRead { - - final protected Class target; - final protected boolean allowNull; - final protected boolean uniqueResult; - - public Adapt(Resource resource, Class target) { - this(resource, target, false, false); - } - - public Adapt(Resource resource, Class target, boolean allowNull) { - this(resource, target, allowNull, false); - } - - public Adapt(Resource resource, Class target, boolean allowNull, boolean uniqueResult) { - super(resource); - assert target != null; - this.target = target; - this.allowNull = allowNull; - this.uniqueResult = uniqueResult; - } - - @Override - public T perform(ReadGraph graph) throws AdaptionException, ValidationException, ServiceException { - if (allowNull) { - if (uniqueResult) - return graph.getPossibleUniqueAdapter(resource, target); - return graph.getPossibleAdapter(resource, target); - } - if (uniqueResult) - return graph.adaptUnique(resource, target); - return graph.adapt(resource, target); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + (allowNull ? 1231 : 1237); - result = prime * result + (target.hashCode()); - result = prime * result + (uniqueResult ? 1303 : 1319); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) - return false; - if (this == obj) - return true; - if (getClass() != obj.getClass()) - return false; - Adapt other = (Adapt) obj; - if (!resource.equals(other.resource)) - return false; - if (allowNull != other.allowNull) - return false; - if (!target.equals(other.target)) - return false; - if (uniqueResult != other.uniqueResult) - return false; - return true; - } - +package org.simantics.db.common.request; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.AdaptionException; +import org.simantics.db.exception.ServiceException; +import org.simantics.db.exception.ValidationException; + +/** + * @author Tuukka Lehtonen + * + * @param the adaption target interface + */ +public class Adapt extends ResourceRead { + + final protected Class target; + final protected boolean allowNull; + final protected boolean uniqueResult; + + public Adapt(Resource resource, Class target) { + this(resource, target, false, false); + } + + public Adapt(Resource resource, Class target, boolean allowNull) { + this(resource, target, allowNull, false); + } + + public Adapt(Resource resource, Class target, boolean allowNull, boolean uniqueResult) { + super(resource); + assert target != null; + this.target = target; + this.allowNull = allowNull; + this.uniqueResult = uniqueResult; + } + + @Override + public T perform(ReadGraph graph) throws AdaptionException, ValidationException, ServiceException { + if (allowNull) { + if (uniqueResult) + return graph.getPossibleUniqueAdapter(resource, target); + return graph.getPossibleAdapter(resource, target); + } + if (uniqueResult) + return graph.adaptUnique(resource, target); + return graph.adapt(resource, target); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (allowNull ? 1231 : 1237); + result = prime * result + (target.hashCode()); + result = prime * result + (uniqueResult ? 1303 : 1319); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) + return false; + if (this == obj) + return true; + if (getClass() != obj.getClass()) + return false; + Adapt other = (Adapt) obj; + if (!resource.equals(other.resource)) + return false; + if (allowNull != other.allowNull) + return false; + if (!target.equals(other.target)) + return false; + if (uniqueResult != other.uniqueResult) + return false; + return true; + } + } \ No newline at end of file