-package org.simantics.db.common.request;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.AdaptionException;\r
-import org.simantics.db.exception.ServiceException;\r
-import org.simantics.db.exception.ValidationException;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- * \r
- * @param <T> the adaption target interface\r
- */\r
-public class Adapt<T> extends ResourceRead<T> {\r
-\r
- final protected Class<T> target;\r
- final protected boolean allowNull;\r
- final protected boolean uniqueResult;\r
-\r
- public Adapt(Resource resource, Class<T> target) {\r
- this(resource, target, false, false);\r
- }\r
-\r
- public Adapt(Resource resource, Class<T> target, boolean allowNull) {\r
- this(resource, target, allowNull, false);\r
- }\r
-\r
- public Adapt(Resource resource, Class<T> target, boolean allowNull, boolean uniqueResult) {\r
- super(resource);\r
- assert target != null;\r
- this.target = target;\r
- this.allowNull = allowNull;\r
- this.uniqueResult = uniqueResult;\r
- }\r
-\r
- @Override\r
- public T perform(ReadGraph graph) throws AdaptionException, ValidationException, ServiceException {\r
- if (allowNull) {\r
- if (uniqueResult)\r
- return graph.getPossibleUniqueAdapter(resource, target);\r
- return graph.getPossibleAdapter(resource, target);\r
- }\r
- if (uniqueResult)\r
- return graph.adaptUnique(resource, target);\r
- return graph.adapt(resource, target);\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = super.hashCode();\r
- result = prime * result + (allowNull ? 1231 : 1237);\r
- result = prime * result + (target.hashCode());\r
- result = prime * result + (uniqueResult ? 1303 : 1319);\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj == null)\r
- return false;\r
- if (this == obj)\r
- return true;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- Adapt<?> other = (Adapt<?>) obj;\r
- if (!resource.equals(other.resource))\r
- return false;\r
- if (allowNull != other.allowNull)\r
- return false;\r
- if (!target.equals(other.target))\r
- return false;\r
- if (uniqueResult != other.uniqueResult)\r
- return false;\r
- return true;\r
- }\r
-\r
+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 <T> the adaption target interface
+ */
+public class Adapt<T> extends ResourceRead<T> {
+
+ final protected Class<T> target;
+ final protected boolean allowNull;
+ final protected boolean uniqueResult;
+
+ public Adapt(Resource resource, Class<T> target) {
+ this(resource, target, false, false);
+ }
+
+ public Adapt(Resource resource, Class<T> target, boolean allowNull) {
+ this(resource, target, allowNull, false);
+ }
+
+ public Adapt(Resource resource, Class<T> 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