Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / sql / compile / ColumnOrdering.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/ColumnOrdering.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/ColumnOrdering.java
new file mode 100644 (file)
index 0000000..4daf241
--- /dev/null
@@ -0,0 +1,204 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.compile.ColumnOrdering\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.sql.compile;\r
+\r
+import org.apache.derby.iapi.sql.compile.RowOrdering;\r
+import org.apache.derby.iapi.sql.compile.Optimizable;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import java.util.Vector;\r
+\r
+class ColumnOrdering {\r
+\r
+       /* See RowOrdering for possible values */\r
+       int     myDirection;\r
+\r
+       /* A vector of column numbers (Integers) */\r
+       Vector columns = new Vector();\r
+\r
+       /*\r
+       ** A vector of table numbers (Integers), corresponding to the column\r
+       ** vector by position.\r
+       */\r
+       Vector tables = new Vector();\r
+\r
+       /**\r
+        * @param direction     See RowOrdering for possible values\r
+        */\r
+       ColumnOrdering(int direction) {\r
+               myDirection = direction;\r
+       }\r
+\r
+       /**\r
+        * Does this ColumnOrdering contain the given column in the given table\r
+        * in the right direction?\r
+        *\r
+        * @param direction             See RowOrdering for possible values\r
+        * @param tableNumber   The number of the table in question\r
+        * @param columnNumber  The column number in the table (one-based)\r
+        *\r
+        * @return      true if the column is found here in the right direction\r
+        */\r
+       boolean ordered(int direction, int tableNumber, int columnNumber) {\r
+               /*\r
+               ** Check the direction only if the direction isn't DONTCARE\r
+               */\r
+               if (direction != RowOrdering.DONTCARE) {\r
+                       if (direction != myDirection)\r
+                               return false;\r
+               }\r
+\r
+               /* The direction matches - see if the column is in this ordering */\r
+               return contains(tableNumber, columnNumber);\r
+       }\r
+\r
+       /**\r
+        * Does this ColumnOrdering contain the given column?\r
+        *\r
+        * @param tableNumber   The number of table in question\r
+        * @param columnNumber  The column number in the table (one-based)\r
+        *\r
+        * @return      true if the column is found here in the right direction\r
+        */\r
+       boolean contains(int tableNumber, int columnNumber)\r
+       {\r
+               for (int i = 0; i < columns.size(); i++) {\r
+                       Integer col = (Integer) columns.elementAt(i);\r
+                       Integer tab = (Integer) tables.elementAt(i);\r
+\r
+                       if (tab.intValue() == tableNumber &&\r
+                               col.intValue() == columnNumber) {\r
+\r
+                               return true;\r
+                       }\r
+               }\r
+\r
+               return false;\r
+       }\r
+\r
+       /**\r
+        * Get the direction of this ColumnOrdering\r
+        */\r
+       int direction()\r
+       {\r
+               return myDirection;\r
+       }\r
+\r
+       /**\r
+        * Add a column in a table to this ColumnOrdering\r
+        *\r
+        * @param tableNumber   The number of table in question\r
+        * @param columnNumber  The column number in the table (one-based)\r
+        */\r
+       void addColumn(int tableNumber, int columnNumber)\r
+       {\r
+               tables.addElement(new Integer(tableNumber));\r
+               columns.addElement(new Integer(columnNumber));\r
+       }\r
+\r
+       /**\r
+        * Remove all columns with the given table number\r
+        */\r
+       void removeColumns(int tableNumber)\r
+       {\r
+               /*\r
+               ** Walk the list backwards, so we can remove elements\r
+               ** by position.\r
+               */\r
+               for (int i = tables.size() - 1; i >= 0; i--)\r
+               {\r
+                       Integer tab = (Integer) tables.elementAt(i);\r
+                       if (tab.intValue() == tableNumber)\r
+                       {\r
+                               tables.removeElementAt(i);\r
+                               columns.removeElementAt(i);\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Tell whether this ColumnOrdering has no elements.\r
+        */\r
+       boolean empty()\r
+       {\r
+               return (tables.size() == 0);\r
+       }\r
+\r
+       /** Return a clone of this ColumnOrdering */\r
+       ColumnOrdering cloneMe() {\r
+               ColumnOrdering retval = new ColumnOrdering(myDirection);\r
+\r
+               for (int i = 0; i < columns.size(); i++) {\r
+                       /* Integers are immutable, so just copy the pointers */\r
+                       retval.columns.addElement(columns.elementAt(i));\r
+                       retval.tables.addElement(tables.elementAt(i));\r
+               }\r
+\r
+               return retval;\r
+       }\r
+\r
+       /** Is the given table number in this ColumnOrdering? */\r
+       boolean hasTable(int tableNumber) {\r
+               if (tables.size() == 0)\r
+                       return false;\r
+\r
+               for (int i = 0; i < tables.size(); i++) {\r
+                       Integer tab = (Integer) tables.elementAt(i);\r
+                       \r
+                       if (tab.intValue() == tableNumber)\r
+                               return true;\r
+               }\r
+\r
+               return false;\r
+       }\r
+\r
+       /** Is there any table other than the given one in this ColumnOrdering? */\r
+       boolean hasAnyOtherTable(int tableNumber) {\r
+               if (tables.size() == 0)\r
+                       return false;\r
+\r
+               for (int i = 0; i < tables.size(); i++) {\r
+                       Integer tab = (Integer) tables.elementAt(i);\r
+                       \r
+                       if (tab.intValue() != tableNumber)\r
+                               return true;\r
+               }\r
+\r
+               return false;\r
+       }\r
+\r
+       public String toString() {\r
+               String retval = "";\r
+\r
+               if (SanityManager.DEBUG) {\r
+                       retval += "Direction: " + myDirection;\r
+\r
+                       for (int i = 0; i < columns.size(); i++) {\r
+                               retval += " Table " + tables.elementAt(i) +\r
+                                                       ", Column " + columns.elementAt(i);\r
+                       }\r
+               }\r
+\r
+               return retval;\r
+       }\r
+}\r