Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / iapi / services / classfile / CONSTANT_Utf8_info.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/services/classfile/CONSTANT_Utf8_info.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/services/classfile/CONSTANT_Utf8_info.java
new file mode 100644 (file)
index 0000000..281c209
--- /dev/null
@@ -0,0 +1,108 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.services.classfile.CONSTANT_Utf8_info\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.iapi.services.classfile;\r
+\r
+import org.apache.derby.iapi.services.classfile.VMDescriptor;\r
+import java.io.IOException;\r
+\r
+/** Constant Pool class - pages 92-99 */\r
+\r
+/** Utf8- page 100 - Section 4.4.7 */\r
+public final class CONSTANT_Utf8_info extends ConstantPoolEntry {\r
+       private final String value;\r
+       private int asString;\r
+       private int asCode;\r
+       \r
+       CONSTANT_Utf8_info(String value) {\r
+               super(VMDescriptor.CONSTANT_Utf8);\r
+               this.value = value;\r
+       }\r
+\r
+       Object getKey() {\r
+               return value;\r
+       }\r
+\r
+       /**\r
+               We assume here that the String is ASCII, thus this\r
+               might return a size smaller than actual size.\r
+       */\r
+       int classFileSize() {\r
+               // 1 (tag) + 2 (utf length) + string length\r
+               return 1 + 2 + value.length();\r
+       }\r
+\r
+       public String toString() {\r
+               return value;\r
+       }\r
+\r
+       // if this returns 0 then the caller must put another CONSTANT_Utf8_info into the\r
+       // constant pool with no hash table entry and then call setAlternative() with its index.\r
+       int setAsCode() {\r
+               if (ClassHolder.isExternalClassName(value))\r
+               {\r
+                       if (asString == 0) {\r
+                               // only used as code at the moment\r
+                               asCode = getIndex();\r
+                       }\r
+\r
+                       return asCode;\r
+               }\r
+               // no dots in the string so it can be used as a JVM internal string and\r
+               // an external string.\r
+               return getIndex();\r
+       }\r
+\r
+       int setAsString() {\r
+               if (ClassHolder.isExternalClassName(value))\r
+               {\r
+\r
+                       if (asCode == 0) {\r
+                               // only used as String at the moment\r
+                               asString = getIndex();\r
+                       }\r
+                       return asString;\r
+               }\r
+               \r
+               // no dots in the string so it can be used as a JVM internal string and\r
+               // an external string.\r
+               return getIndex();\r
+       }\r
+\r
+       void setAlternative(int index) {\r
+\r
+               if (asCode == 0)\r
+                       asCode = index;\r
+               else\r
+                       asString = index;\r
+       }\r
+\r
+       void put(ClassFormatOutput out) throws IOException {\r
+               super.put(out);\r
+\r
+               if (getIndex() == asCode)\r
+               {\r
+                       out.writeUTF(ClassHolder.convertToInternalClassName(value));\r
+               }\r
+               else\r
+                       out.writeUTF(value);\r
+       }\r
+}\r