Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / tools / resources / upgrade / IntegerArrayAttribute.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/resources/upgrade/IntegerArrayAttribute.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/resources/upgrade/IntegerArrayAttribute.java
new file mode 100644 (file)
index 0000000..1aee1e1
--- /dev/null
@@ -0,0 +1,97 @@
+// IntegerArrayAttribute.java\r
+// $Id: IntegerArrayAttribute.java,v 1.1 2010/06/15 12:22:52 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1996.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.tools.resources.upgrade ;\r
+\r
+import java.io.DataInputStream;\r
+import java.io.DataOutputStream;\r
+import java.io.IOException;\r
+\r
+/**\r
+ * The generic description of an IntegerArrayAttribute.\r
+ */\r
+\r
+public class IntegerArrayAttribute extends Attribute {\r
+\r
+    /**\r
+     * Turn a IntegerArray attribute into a String.\r
+     * We use the <em>normal</em> property convention, which is to separate\r
+     * each item with a <strong>|</strong>.\r
+     * @return A String based encoding for that value.\r
+     */\r
+\r
+    public String stringify(Object value) {\r
+       if ((value == null) || ( ! (value instanceof int[])) )\r
+           return null;\r
+       int          ai[] = (int[]) value;\r
+       StringBuffer sb   = new StringBuffer();\r
+       for (int i = 0 ; i < ai.length ; i++) {\r
+           if ( i > 0 )\r
+               sb.append('|');\r
+           sb.append(ai[i]);\r
+       }\r
+       return sb.toString();\r
+    }\r
+\r
+    /**\r
+     * Is the given object a valid IntegerArrayAttribute value ?\r
+     * @param obj The object to test.\r
+     * @return A boolean <strong>true</strong> if okay.\r
+     */\r
+\r
+    public boolean checkValue(Object obj) {\r
+       return (obj instanceof int[]) ;\r
+    }\r
+\r
+    /**\r
+     * Get the number of bytes required to save that attribute value.\r
+     * @param The value about to be pickled.\r
+     * @return The number of bytes needed to pickle that value.\r
+     */\r
+\r
+    public final int getPickleLength(Object value) {\r
+       return ((int[]) value).length * 4 + 4;\r
+    }\r
+\r
+    /**\r
+     * Pickle a integer array to the given output stream.\r
+     * @param out The output stream to pickle to.\r
+     * @param obj The object to pickle.\r
+     * @exception IOException If some IO error occured.\r
+     */\r
+\r
+    public void pickle(DataOutputStream out, Object ia) \r
+       throws IOException\r
+    {\r
+       int is[] = (int[]) ia ;\r
+       out.writeInt(is.length) ;\r
+       for (int i = 0 ; i < is.length ; i++)\r
+           out.writeInt(is[i]) ;\r
+    }\r
+\r
+    /**\r
+     * Unpickle an integer array from the given input stream.\r
+     * @param in The input stream to unpickle from.\r
+     * @return An instance of int[].\r
+     * @exception IOException If some IO error occured.\r
+     */\r
+\r
+    public Object unpickle (DataInputStream in) \r
+       throws IOException\r
+    {\r
+       int  cnt  = in.readInt() ;\r
+       int  is[] = new int[cnt] ;\r
+       for (int i = 0 ; i < cnt ; i++)\r
+           is[i] = in.readInt() ;\r
+       return is ;\r
+    }\r
+\r
+    public IntegerArrayAttribute(String name, String def[],\r
+                                Integer flags) {\r
+       super(name, def, flags) ;\r
+       this.type = "int[]";\r
+    }\r
+\r
+}\r