]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/RVIBuilder.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / RVIBuilder.java
index 96f1be4c15e3b18f295529e1ceaecd3182a366c3..4348fe2817c8576da2507da7cb364fce753f707e 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * 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.layer0.variable;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.layer0.variable.RVI.RVIPart;\r
-import org.simantics.db.layer0.variable.Variables.Role;\r
-\r
-/**\r
- * Utility for building RVI parts.\r
- * \r
- * @author toni.kalajainen\r
- */\r
-public class RVIBuilder {\r
-\r
-       Binding rviBinding;\r
-    List<RVIPart> parts;\r
-\r
-    public RVIBuilder(Binding rviBinding)\r
-    {\r
-        parts = new ArrayList<RVIPart>();\r
-    }\r
-\r
-    public RVIBuilder(RVI rvi)\r
-    {\r
-        set(rvi);\r
-    }\r
-\r
-    public RVIBuilder set( RVI rvi ) \r
-    {\r
-       this.rviBinding = rvi.getBinding();\r
-        parts = new ArrayList<RVIPart>( rvi.parts.length + 10 );\r
-        for ( RVIPart part : rvi.parts ) parts.add( part );\r
-        return this;\r
-    }\r
-\r
-    public RVIBuilder append( RVI rvi ) \r
-    {\r
-        for ( RVIPart part : rvi.parts ) parts.add( part );\r
-        return this;\r
-    }\r
-\r
-    public RVIBuilder append( RVIPart part )\r
-    {\r
-        parts.add( part );\r
-        return this;\r
-    }\r
-\r
-    public RVIBuilder append( Role role, String string )\r
-    {\r
-        parts.add( new RVI.StringRVIPart(role, string) );\r
-        return this;\r
-    }\r
-\r
-    public RVIBuilder append( Role role, Resource resource )\r
-    {\r
-        parts.add( new RVI.ResourceRVIPart(role, resource) );\r
-        return this;\r
-    }\r
-    \r
-    public RVIBuilder append( Role role, Resource resource, long mostSignificant, long leastSignificant)\r
-    {\r
-        parts.add( new RVI.GuidRVIPart(role, resource, mostSignificant, leastSignificant) );\r
-        return this;\r
-    }\r
-\r
-    /**\r
-     * @param rvi the RVI to truncate\r
-     * @param n number of parts to remove from the end of the RVI\r
-     * @return truncated RVI\r
-     */\r
-    public RVIBuilder removeLast(int n) {\r
-        if (n > parts.size())\r
-            throw new IllegalArgumentException("Requested to remove " + n + " parts from RVI, only " + parts.size()\r
-                    + " parts exist in '" + parts + "'");\r
-        parts = parts.subList(0, parts.size() - n);\r
-        return this;\r
-    }\r
-\r
-    public RVIBuilder removeFromFirstRole(Role role) {\r
-        for (int i = 0; i < parts.size(); ++i) {\r
-            if (parts.get(i).getRole() == role) {\r
-                parts = parts.subList(0, i);\r
-                return this;\r
-            }\r
-        }\r
-        return this;\r
-    }\r
-\r
-    public RVI toRVI()\r
-    {\r
-        if (parts.isEmpty())\r
-            return RVI.empty( rviBinding );\r
-        RVI rvi = new RVI( rviBinding );\r
-        rvi.parts = (RVIPart[]) parts.toArray( new RVIPart[ parts.size() ] );\r
-        return rvi;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 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.layer0.variable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.simantics.databoard.binding.Binding;
+import org.simantics.db.Resource;
+import org.simantics.db.layer0.variable.RVI.RVIPart;
+import org.simantics.db.layer0.variable.Variables.Role;
+
+/**
+ * Utility for building RVI parts.
+ * 
+ * @author toni.kalajainen
+ */
+public class RVIBuilder {
+
+       Binding rviBinding;
+    List<RVIPart> parts;
+
+    public RVIBuilder(Binding rviBinding)
+    {
+        parts = new ArrayList<RVIPart>();
+    }
+
+    public RVIBuilder(RVI rvi)
+    {
+        set(rvi);
+    }
+
+    public RVIBuilder set( RVI rvi ) 
+    {
+       this.rviBinding = rvi.getBinding();
+        parts = new ArrayList<RVIPart>( rvi.parts.length + 10 );
+        for ( RVIPart part : rvi.parts ) parts.add( part );
+        return this;
+    }
+
+    public RVIBuilder append( RVI rvi ) 
+    {
+        for ( RVIPart part : rvi.parts ) parts.add( part );
+        return this;
+    }
+
+    public RVIBuilder append( RVIPart part )
+    {
+        parts.add( part );
+        return this;
+    }
+
+    public RVIBuilder append( Role role, String string )
+    {
+        parts.add( new RVI.StringRVIPart(role, string) );
+        return this;
+    }
+
+    public RVIBuilder append( Role role, Resource resource )
+    {
+        parts.add( new RVI.ResourceRVIPart(role, resource) );
+        return this;
+    }
+    
+    public RVIBuilder append( Role role, Resource resource, long mostSignificant, long leastSignificant)
+    {
+        parts.add( new RVI.GuidRVIPart(role, resource, mostSignificant, leastSignificant) );
+        return this;
+    }
+
+    /**
+     * @param rvi the RVI to truncate
+     * @param n number of parts to remove from the end of the RVI
+     * @return truncated RVI
+     */
+    public RVIBuilder removeLast(int n) {
+        if (n > parts.size())
+            throw new IllegalArgumentException("Requested to remove " + n + " parts from RVI, only " + parts.size()
+                    + " parts exist in '" + parts + "'");
+        parts = parts.subList(0, parts.size() - n);
+        return this;
+    }
+
+    public RVIBuilder removeFromFirstRole(Role role) {
+        for (int i = 0; i < parts.size(); ++i) {
+            if (parts.get(i).getRole() == role) {
+                parts = parts.subList(0, i);
+                return this;
+            }
+        }
+        return this;
+    }
+
+    public RVI toRVI()
+    {
+        if (parts.isEmpty())
+            return RVI.empty( rviBinding );
+        RVI rvi = new RVI( rviBinding );
+        rvi.parts = (RVIPart[]) parts.toArray( new RVIPart[ parts.size() ] );
+        return rvi;
+    }
+
+}