]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/ResourceImpl.java
Disabled BOOKKEEPING flag for normal use
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / ResourceImpl.java
index 77764a323693caded1207522242831e13800e8cc..3406d670031590beb58dfee439326cb2fb738e0c 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.impl;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.impl.support.ResourceSupport;\r
-import org.simantics.db.service.ClusterUID;\r
-\r
-final public class ResourceImpl implements Resource {\r
-\r
-    final public ResourceSupport support;\r
-    final public int id;\r
-\r
-    public ResourceImpl(final ResourceSupport support, final int id) {\r
-        assert(id != 0);\r
-        this.support = support;\r
-        this.id = id;\r
-    }\r
-\r
-    @Override\r
-    final public long getResourceId() {\r
-        return support.getRandomAccessId(id);\r
-    }\r
-\r
-    @Override\r
-    public boolean isPersistent() {\r
-        return id > 0;\r
-    }\r
-    \r
-    @Override\r
-    public Resource get() {\r
-        return this;\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        return id;\r
-    }\r
-\r
-    @Override\r
-    public int getThreadHash() {\r
-        return id >>> 16;\r
-    }\r
-    \r
-    @Override\r
-    public boolean equals(Object object) {\r
-        if (this == object)\r
-            return true;\r
-        else if (object == null)\r
-            return false;\r
-        else if (!(object instanceof ResourceImpl))\r
-            return false;\r
-        ResourceImpl r = (ResourceImpl)object;\r
-        return r.id == id;\r
-    }\r
-    \r
-    @Override\r
-    public boolean equalsResource(Resource other) {\r
-        ResourceImpl r = (ResourceImpl)other;\r
-        return r.id == id;\r
-    }\r
-\r
-    @Override\r
-    public int compareTo(Resource o) {\r
-        if(this==o)\r
-            return 0;\r
-        if(o instanceof ResourceImpl)\r
-            return id - ((ResourceImpl)o).id;\r
-        else\r
-            return 1;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        StringBuilder sb = new StringBuilder(32);\r
-        try {\r
-            long rid = getResourceId();\r
-            if(DebugPolicy.VERBOSE) {\r
-                sb.append("[id=");\r
-                sb.append(id);\r
-                sb.append(" - rid=");\r
-                sb.append(rid);\r
-                sb.append(" i=");\r
-                short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id);\r
-                sb.append(ri);\r
-                int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id);\r
-                sb.append(" c=");\r
-                sb.append(ck);\r
-                sb.append("]");\r
-            } else {\r
-                sb.append("[id=$");\r
-                sb.append(rid);\r
-                sb.append("]");\r
-            }\r
-        } catch (Exception e) {\r
-            sb.append("[internal id=");\r
-            sb.append(id);\r
-            sb.append(", persistent resource id failed]");\r
-        }\r
-        return sb.toString();\r
-    }\r
-    public String toString(ClusterSupport support) {\r
-        StringBuilder sb = new StringBuilder(32);\r
-        long rid = getResourceId();\r
-        if (DebugPolicy.VERBOSE) {\r
-            sb.append("[id=");\r
-            sb.append(id);\r
-            sb.append(" - rid=");\r
-            sb.append(rid);\r
-            sb.append(" i=");\r
-            short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id);\r
-            sb.append(ri);\r
-            int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id);\r
-            sb.append(" ck=");\r
-            sb.append(ck);\r
-            ClusterBase cb = support.getClusterByClusterKey(ck);\r
-            if (null != cb) {\r
-                ClusterUID clusterUID = cb.getClusterUID();\r
-                sb.append(" c=");\r
-                sb.append(clusterUID.toString());\r
-            }\r
-            sb.append("]");\r
-        } else {\r
-            sb.append("[id=$");\r
-            sb.append(rid);\r
-            sb.append("]");\r
-        }\r
-        return sb.toString();\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.impl;
+
+import org.simantics.db.Resource;
+import org.simantics.db.impl.support.ResourceSupport;
+import org.simantics.db.service.ClusterUID;
+
+final public class ResourceImpl implements Resource {
+
+    final public ResourceSupport support;
+    final public int id;
+
+    public ResourceImpl(final ResourceSupport support, final int id) {
+        assert(id != 0);
+        this.support = support;
+        this.id = id;
+    }
+
+    @Override
+    final public long getResourceId() {
+        return support.getRandomAccessId(id);
+    }
+
+    @Override
+    public boolean isPersistent() {
+        return id > 0;
+    }
+    
+    @Override
+    public Resource get() {
+        return this;
+    }
+
+    @Override
+    public int hashCode() {
+        return id;
+    }
+
+    @Override
+    public int getThreadHash() {
+        return id >>> 16;
+    }
+    
+    @Override
+    public boolean equals(Object object) {
+        if (this == object)
+            return true;
+        else if (object == null)
+            return false;
+        else if (!(object instanceof ResourceImpl))
+            return false;
+        ResourceImpl r = (ResourceImpl)object;
+        return r.id == id;
+    }
+    
+    @Override
+    public boolean equalsResource(Resource other) {
+        ResourceImpl r = (ResourceImpl)other;
+        return r.id == id;
+    }
+
+    @Override
+    public int compareTo(Resource o) {
+        if(this==o)
+            return 0;
+        if(o instanceof ResourceImpl)
+            return id - ((ResourceImpl)o).id;
+        else
+            return 1;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(32);
+        try {
+            long rid = getResourceId();
+            if(DebugPolicy.VERBOSE) {
+                sb.append("[id=");
+                sb.append(id);
+                sb.append(" - rid=");
+                sb.append(rid);
+                sb.append(" i=");
+                short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id);
+                sb.append(ri);
+                int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id);
+                sb.append(" c=");
+                sb.append(ck);
+                sb.append("]");
+            } else {
+                sb.append("[id=$");
+                sb.append(rid);
+                sb.append("]");
+            }
+        } catch (Exception e) {
+            sb.append("[internal id=");
+            sb.append(id);
+            sb.append(", persistent resource id failed]");
+        }
+        return sb.toString();
+    }
+    public String toString(ClusterSupport support) {
+        StringBuilder sb = new StringBuilder(32);
+        long rid = getResourceId();
+        if (DebugPolicy.VERBOSE) {
+            sb.append("[id=");
+            sb.append(id);
+            sb.append(" - rid=");
+            sb.append(rid);
+            sb.append(" i=");
+            short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id);
+            sb.append(ri);
+            int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id);
+            sb.append(" ck=");
+            sb.append(ck);
+            ClusterBase cb = support.getClusterByClusterKey(ck);
+            if (null != cb) {
+                ClusterUID clusterUID = cb.getClusterUID();
+                sb.append(" c=");
+                sb.append(clusterUID.toString());
+            }
+            sb.append("]");
+        } else {
+            sb.append("[id=$");
+            sb.append(rid);
+            sb.append("]");
+        }
+        return sb.toString();
+    }
+}