Skip to content
Browse files

Reformatted all the code to match my style

Reformatting and re-indenting once and for all, to avoid polluting the
history again in future! Sorry, it had to be -- I can't face staring at
2-space indents in Java.
  • Loading branch information...
1 parent d5641b7 commit d3c50d39166af9ade39661d726775007c9575291 Martin Kleppmann committed Feb 28, 2009
Showing with 3,868 additions and 3,738 deletions.
  1. +21 −25 src/fc/test/XmlTest.java
  2. +101 −102 src/fc/test/bench/XmlMemory.java
  3. +77 −83 src/fc/test/bench/XmlPass.java
  4. +155 −155 src/fc/test/junit/XasTest.java
  5. +259 −264 src/fc/test/junit/XmlData.java
  6. +62 −42 src/fc/util/AbstractDictionary.java
  7. +16 −21 src/fc/util/BaInputStream.java
  8. +120 −123 src/fc/util/BinaryData.java
  9. +93 −88 src/fc/util/ByteArray.java
  10. +7 −11 src/fc/util/ByteArrayStream.java
  11. +80 −77 src/fc/util/CompareUtil.java
  12. +313 −296 src/fc/util/Debug.java
  13. +94 −103 src/fc/util/ExtUtil.java
  14. +33 −35 src/fc/util/IOExceptionTrap.java
  15. +247 −234 src/fc/util/IOUtil.java
  16. +171 −136 src/fc/util/ImmutableArrayList.java
  17. +27 −19 src/fc/util/MagicInputStream.java
  18. +214 −192 src/fc/util/Measurer.java
  19. +63 −52 src/fc/util/NonListableSet.java
  20. +16 −17 src/fc/util/Pair.java
  21. +86 −87 src/fc/util/Queue.java
  22. +108 −100 src/fc/util/RaInputStream.java
  23. +156 −149 src/fc/util/RingBuffer.java
  24. +24 −18 src/fc/util/SeekableInputStream.java
  25. +22 −20 src/fc/util/Stack.java
  26. +239 −234 src/fc/util/StringUtil.java
  27. +90 −96 src/fc/util/Utf8Reader.java
  28. +199 −197 src/fc/util/Util.java
  29. +110 −98 src/fc/util/log/AbstractLogger.java
  30. +61 −47 src/fc/util/log/CommonsLogger.java
  31. +65 −65 src/fc/util/log/GroupLogger.java
  32. +126 −112 src/fc/util/log/Log.java
  33. +23 −32 src/fc/util/log/LogLevels.java
  34. +169 −171 src/fc/util/log/Logger.java
  35. +89 −90 src/fc/util/log/StreamLogger.java
  36. +9 −13 src/fc/util/log/SysoutLogger.java
  37. +123 −134 src/fc/xml/diff/Diff.java
Sorry, we could not display the entire diff because it was too big.
View
46 src/fc/test/XmlTest.java
@@ -1,12 +1,10 @@
/*
* Copyright 2005--2008 Helsinki Institute for Information Technology
- *
- * This file is a part of Fuego middleware. Fuego middleware is free
- * software; you can redistribute it and/or modify it under the terms
- * of the MIT license, included as the file MIT-LICENSE in the Fuego
- * middleware source distribution. If you did not receive the MIT
- * license with the distribution, write to the Fuego Core project at
- * fuego-xas-users@hoslab.cs.helsinki.fi.
+ *
+ * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
+ * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
+ * Fuego middleware source distribution. If you did not receive the MIT license with the
+ * distribution, write to the Fuego Core project at fuego-xas-users@hoslab.cs.helsinki.fi.
*/
package fc.test;
@@ -24,24 +22,22 @@
public class XmlTest {
- public static void main (String[] args) {
- try {
- for (String fileName : args) {
- XmlPullParser parser = new KXmlParser();
- ItemSource is =
- new XmlPullSource(parser,
- new FileInputStream(fileName));
- ItemTarget it = new XmlOutput(System.out, "ISO-8859-1");
- for (Item i = is.next(); i != null; i = is.next()) {
- System.out.println(i);
- it.append(i);
- }
- System.out.println();
- System.out.println();
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
+ public static void main(String[] args) {
+ try {
+ for (String fileName : args) {
+ XmlPullParser parser = new KXmlParser();
+ ItemSource is = new XmlPullSource(parser, new FileInputStream(fileName));
+ ItemTarget it = new XmlOutput(System.out, "ISO-8859-1");
+ for (Item i = is.next(); i != null; i = is.next()) {
+ System.out.println(i);
+ it.append(i);
+ }
+ System.out.println();
+ System.out.println();
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
}
}
View
203 src/fc/test/bench/XmlMemory.java
@@ -1,12 +1,10 @@
/*
* Copyright 2005--2008 Helsinki Institute for Information Technology
- *
- * This file is a part of Fuego middleware. Fuego middleware is free
- * software; you can redistribute it and/or modify it under the terms
- * of the MIT license, included as the file MIT-LICENSE in the Fuego
- * middleware source distribution. If you did not receive the MIT
- * license with the distribution, write to the Fuego Core project at
- * fuego-xas-users@hoslab.cs.helsinki.fi.
+ *
+ * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
+ * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
+ * Fuego middleware source distribution. If you did not receive the MIT license with the
+ * distribution, write to the Fuego Core project at fuego-xas-users@hoslab.cs.helsinki.fi.
*/
package fc.test.bench;
@@ -38,107 +36,108 @@
private static Object result = null;
- private static void saxParse (String fileName) throws Exception {
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware(true);
- SAXParser parser = factory.newSAXParser();
- XMLReader reader = parser.getXMLReader();
- DefaultHandler2 handler = new DefaultHandler2();
- reader.setContentHandler(handler);
- reader.setProperty("http://xml.org/sax/properties/lexical-handler",
- handler);
- reader.parse(fileName);
+
+ private static void saxParse(String fileName) throws Exception {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ SAXParser parser = factory.newSAXParser();
+ XMLReader reader = parser.getXMLReader();
+ DefaultHandler2 handler = new DefaultHandler2();
+ reader.setContentHandler(handler);
+ reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
+ reader.parse(fileName);
}
- private static void domParse (String fileName) throws Exception {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document document = builder.parse(fileName);
- Stack<Node> stack = new Stack<Node>();
- stack.push(document);
- while (!stack.isEmpty()) {
- Node node = stack.pop();
- switch (node.getNodeType()) {
- case Node.DOCUMENT_NODE: {
- NodeList nodes = node.getChildNodes();
- if (nodes != null) {
- int n = nodes.getLength();
- for (int i = n - 1; i >= 0; i-- ) {
- stack.push(nodes.item(i));
- }
- }
- }
- case Node.ELEMENT_NODE: {
- NamedNodeMap atts = node.getAttributes();
- if (atts != null) {
- int n = atts.getLength();
- for (int i = 0; i < n; i++ ) {
- Attr att = (Attr) atts.item(i);
- result = att.getNodeName();
- }
- }
- NodeList nodes = node.getChildNodes();
- if (nodes != null) {
- int l = nodes.getLength();
- for (int i = l - 1; i >= 0; i-- ) {
- stack.push(nodes.item(i));
- }
- }
- }
- }
- }
- result = document;
+
+ private static void domParse(String fileName) throws Exception {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(fileName);
+ Stack<Node> stack = new Stack<Node>();
+ stack.push(document);
+ while (!stack.isEmpty()) {
+ Node node = stack.pop();
+ switch (node.getNodeType()) {
+ case Node.DOCUMENT_NODE: {
+ NodeList nodes = node.getChildNodes();
+ if (nodes != null) {
+ int n = nodes.getLength();
+ for (int i = n - 1; i >= 0; i--) {
+ stack.push(nodes.item(i));
+ }
+ }
+ }
+ case Node.ELEMENT_NODE: {
+ NamedNodeMap atts = node.getAttributes();
+ if (atts != null) {
+ int n = atts.getLength();
+ for (int i = 0; i < n; i++) {
+ Attr att = (Attr) atts.item(i);
+ result = att.getNodeName();
+ }
+ }
+ NodeList nodes = node.getChildNodes();
+ if (nodes != null) {
+ int l = nodes.getLength();
+ for (int i = l - 1; i >= 0; i--) {
+ stack.push(nodes.item(i));
+ }
+ }
+ }
+ }
+ }
+ result = document;
}
- private static void xasParse (String fileName) throws Exception {
- InputStream in = new FileInputStream(fileName);
- KXmlParser parser = new KXmlParser();
- XmlPullSource source = new XmlPullSource(parser, in);
- ItemList list = new ItemList();
- Item item;
- while ((item = source.next()) != null) {
- list.append(item);
- }
- result = list;
+
+ private static void xasParse(String fileName) throws Exception {
+ InputStream in = new FileInputStream(fileName);
+ KXmlParser parser = new KXmlParser();
+ XmlPullSource source = new XmlPullSource(parser, in);
+ ItemList list = new ItemList();
+ Item item;
+ while ((item = source.next()) != null) {
+ list.append(item);
+ }
+ result = list;
}
- public static void main (String[] args) {
- try {
- if (args.length != 2) {
- System.err.println("Usage: XmlMemory (sax|dom|xas) <file>");
- System.exit(1);
- }
- long beginMemory = 0;
- int end = 10;
- for (int i = 0; i < end; i++ ) {
- result = null;
- Util.runGc();
- beginMemory = Util.usedMemory();
- if (args[0].equals("sax")) {
- saxParse(args[1]);
- } else if (args[0].equals("dom")) {
- domParse(args[1]);
- } else if (args[0].equals("xas")) {
- xasParse(args[1]);
- } else {
- System.err.println("Usage: XmlMemory (sax|dom|xas) <file>");
- System.exit(1);
- }
- long spentMemory = Util.usedMemory();
- Util.runGc();
- long endMemory = Util.usedMemory();
- System.out.println("Total memory spent: "
- + (spentMemory - beginMemory));
- System.out.println("Object size: " + (endMemory - beginMemory));
- System.out
- .println("Result: " + System.identityHashCode(result));
- }
- // System.in.read();
- } catch (Exception ex) {
- ex.printStackTrace();
- System.exit(1);
- }
+
+ public static void main(String[] args) {
+ try {
+ if (args.length != 2) {
+ System.err.println("Usage: XmlMemory (sax|dom|xas) <file>");
+ System.exit(1);
+ }
+ long beginMemory = 0;
+ int end = 10;
+ for (int i = 0; i < end; i++) {
+ result = null;
+ Util.runGc();
+ beginMemory = Util.usedMemory();
+ if (args[0].equals("sax")) {
+ saxParse(args[1]);
+ } else if (args[0].equals("dom")) {
+ domParse(args[1]);
+ } else if (args[0].equals("xas")) {
+ xasParse(args[1]);
+ } else {
+ System.err.println("Usage: XmlMemory (sax|dom|xas) <file>");
+ System.exit(1);
+ }
+ long spentMemory = Util.usedMemory();
+ Util.runGc();
+ long endMemory = Util.usedMemory();
+ System.out.println("Total memory spent: " + (spentMemory - beginMemory));
+ System.out.println("Object size: " + (endMemory - beginMemory));
+ System.out.println("Result: " + System.identityHashCode(result));
+ }
+ // System.in.read();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ System.exit(1);
+ }
}
}
View
160 src/fc/test/bench/XmlPass.java
@@ -1,12 +1,10 @@
/*
* Copyright 2005--2008 Helsinki Institute for Information Technology
- *
- * This file is a part of Fuego middleware. Fuego middleware is free
- * software; you can redistribute it and/or modify it under the terms
- * of the MIT license, included as the file MIT-LICENSE in the Fuego
- * middleware source distribution. If you did not receive the MIT
- * license with the distribution, write to the Fuego Core project at
- * fuego-xas-users@hoslab.cs.helsinki.fi.
+ *
+ * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
+ * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
+ * Fuego middleware source distribution. If you did not receive the MIT license with the
+ * distribution, write to the Fuego Core project at fuego-xas-users@hoslab.cs.helsinki.fi.
*/
package fc.test.bench;
@@ -34,88 +32,84 @@
public class XmlPass {
- private static void saxPass (String inFile, String outFile)
- throws Exception {
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware(true);
- SAXParser parser = factory.newSAXParser();
- XMLReader reader = parser.getXMLReader();
- OutputFormat format = new OutputFormat();
- XMLSerializer serializer = new XMLSerializer(new FileOutputStream(
- outFile), format);
- reader.setContentHandler(serializer);
- reader.setProperty("http://xml.org/sax/properties/lexical-handler",
- serializer);
- reader.parse(inFile);
+ private static void saxPass(String inFile, String outFile) throws Exception {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ SAXParser parser = factory.newSAXParser();
+ XMLReader reader = parser.getXMLReader();
+ OutputFormat format = new OutputFormat();
+ XMLSerializer serializer = new XMLSerializer(new FileOutputStream(outFile), format);
+ reader.setContentHandler(serializer);
+ reader.setProperty("http://xml.org/sax/properties/lexical-handler", serializer);
+ reader.parse(inFile);
}
- private static void domPass (String inFile, String outFile)
- throws Exception {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document document = builder.parse(inFile);
- OutputFormat format = new OutputFormat();
- XMLSerializer serializer = new XMLSerializer(new FileOutputStream(
- outFile), format);
- serializer.serialize(document);
+
+ private static void domPass(String inFile, String outFile) throws Exception {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(inFile);
+ OutputFormat format = new OutputFormat();
+ XMLSerializer serializer = new XMLSerializer(new FileOutputStream(outFile), format);
+ serializer.serialize(document);
}
- private static void xasPass (String inFile, String outFile)
- throws Exception {
- KXmlParser parser = new KXmlParser();
- FileInputStream in = new FileInputStream(inFile);
- XmlPullSource source = new XmlPullSource(parser, in);
- XmlOutput serializer = null;
- FileOutputStream out = new FileOutputStream(outFile);
- serializer = new XmlOutput(out, source.getEncoding());
- Item item;
- while ((item = source.next()) != null) {
- serializer.append(item);
- }
+
+ private static void xasPass(String inFile, String outFile) throws Exception {
+ KXmlParser parser = new KXmlParser();
+ FileInputStream in = new FileInputStream(inFile);
+ XmlPullSource source = new XmlPullSource(parser, in);
+ XmlOutput serializer = null;
+ FileOutputStream out = new FileOutputStream(outFile);
+ serializer = new XmlOutput(out, source.getEncoding());
+ Item item;
+ while ((item = source.next()) != null) {
+ serializer.append(item);
+ }
}
- public static void main (String[] args) {
- try {
- if (args.length != 2) {
- System.err.println("Usage: XmlPass (sax|dom|xas) <file>");
- System.exit(1);
- }
- Measurer.init(Measurer.TIMING);
- Measurer timer = Measurer.get(Measurer.TIMING);
- String outFile = args[1].concat(".pass");
- int end = 10;
- for (int i = 0; i < end; i++ ) {
- Util.runGc();
- long beginMemory = Util.usedMemory();
- Object token = timer.start();
- if (args[0].equals("sax")) {
- saxPass(args[1], outFile);
- } else if (args[0].equals("dom")) {
- domPass(args[1], outFile);
- } else if (args[0].equals("xas")) {
- xasPass(args[1], outFile);
- } else {
- System.err.println("Usage: XmlPass (sax|dom|xas) <file>");
- System.exit(1);
- }
- if (i >= end - 2) {
- timer.finish(token, "XML passthrough");
- }
- long spentMemory = Util.usedMemory();
- Util.runGc();
- long endMemory = Util.usedMemory();
- System.out.println("Total memory spent: "
- + (spentMemory - beginMemory));
- System.out.println("Object size: " + (endMemory - beginMemory));
- if (i >= end - 2) {
- timer.output(System.out);
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- System.exit(1);
- }
+
+ public static void main(String[] args) {
+ try {
+ if (args.length != 2) {
+ System.err.println("Usage: XmlPass (sax|dom|xas) <file>");
+ System.exit(1);
+ }
+ Measurer.init(Measurer.TIMING);
+ Measurer timer = Measurer.get(Measurer.TIMING);
+ String outFile = args[1].concat(".pass");
+ int end = 10;
+ for (int i = 0; i < end; i++) {
+ Util.runGc();
+ long beginMemory = Util.usedMemory();
+ Object token = timer.start();
+ if (args[0].equals("sax")) {
+ saxPass(args[1], outFile);
+ } else if (args[0].equals("dom")) {
+ domPass(args[1], outFile);
+ } else if (args[0].equals("xas")) {
+ xasPass(args[1], outFile);
+ } else {
+ System.err.println("Usage: XmlPass (sax|dom|xas) <file>");
+ System.exit(1);
+ }
+ if (i >= end - 2) {
+ timer.finish(token, "XML passthrough");
+ }
+ long spentMemory = Util.usedMemory();
+ Util.runGc();
+ long endMemory = Util.usedMemory();
+ System.out.println("Total memory spent: " + (spentMemory - beginMemory));
+ System.out.println("Object size: " + (endMemory - beginMemory));
+ if (i >= end - 2) {
+ timer.output(System.out);
+ }
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ System.exit(1);
+ }
}
}
View
310 src/fc/test/junit/XasTest.java
@@ -1,12 +1,10 @@
/*
* Copyright 2005--2008 Helsinki Institute for Information Technology
- *
- * This file is a part of Fuego middleware. Fuego middleware is free
- * software; you can redistribute it and/or modify it under the terms
- * of the MIT license, included as the file MIT-LICENSE in the Fuego
- * middleware source distribution. If you did not receive the MIT
- * license with the distribution, write to the Fuego Core project at
- * fuego-xas-users@hoslab.cs.helsinki.fi.
+ *
+ * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
+ * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
+ * Fuego middleware source distribution. If you did not receive the MIT license with the
+ * distribution, write to the Fuego Core project at fuego-xas-users@hoslab.cs.helsinki.fi.
*/
package fc.test.junit;
@@ -50,21 +48,24 @@
List<XasFragment> fragments;
List<ItemList> typeds;
- protected void setUp () throws IOException {
- fragments = XmlData.getData();
- typeds = XmlData.getTypedData();
- Codec.registerPrimitiveCodec(new XmlCodec());
- Codec.registerValueCodec(new XmlData.PersonCodec());
+
+ protected void setUp() throws IOException {
+ fragments = XmlData.getData();
+ typeds = XmlData.getTypedData();
+ Codec.registerPrimitiveCodec(new XmlCodec());
+ Codec.registerValueCodec(new XmlData.PersonCodec());
}
- public void testTreeify () {
- Log.log("Begin test", Log.DEBUG);
- for (XasFragment f : fragments) {
- f.treeify();
- Log.log("Fragment", Log.DEBUG, f);
- }
+
+ public void testTreeify() {
+ Log.log("Begin test", Log.DEBUG);
+ for (XasFragment f : fragments) {
+ f.treeify();
+ Log.log("Fragment", Log.DEBUG, f);
+ }
}
+
// public void testFlattenPure () {
// Log.log("Begin test", Log.DEBUG);
// for (XasFragment f : fragments) {
@@ -94,152 +95,151 @@ public void testTreeify () {
// }
// }
- private void ioRoundTrip (XasFragment f) throws IOException {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- XmlOutput target = new XmlOutput(bout, "UTF-8");
- Iterator<Item> it = f.iterator();
- while (it.hasNext()) {
- target.append(it.next());
- }
- byte[] init = bout.toByteArray();
- ByteArrayInputStream bin = new ByteArrayInputStream(init);
- KXmlParser parser = new KXmlParser();
- XmlPullSource source = new XmlPullSource(parser, bin);
- bout = new ByteArrayOutputStream();
- target = new XmlOutput(bout, "UTF-8");
- for (Item item = source.next(); item != null; item = source.next()) {
- target.append(item);
- }
- byte[] result = bout.toByteArray();
- assertEquals("Input/output round trip failed",
- new String(init, "UTF-8"), new String(result, "UTF-8"));
+ private void ioRoundTrip(XasFragment f) throws IOException {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ XmlOutput target = new XmlOutput(bout, "UTF-8");
+ Iterator<Item> it = f.iterator();
+ while (it.hasNext()) {
+ target.append(it.next());
+ }
+ byte[] init = bout.toByteArray();
+ ByteArrayInputStream bin = new ByteArrayInputStream(init);
+ KXmlParser parser = new KXmlParser();
+ XmlPullSource source = new XmlPullSource(parser, bin);
+ bout = new ByteArrayOutputStream();
+ target = new XmlOutput(bout, "UTF-8");
+ for (Item item = source.next(); item != null; item = source.next()) {
+ target.append(item);
+ }
+ byte[] result = bout.toByteArray();
+ assertEquals("Input/output round trip failed", new String(init, "UTF-8"),
+ new String(result, "UTF-8"));
}
- public void testIoRoundTrip () throws IOException {
- Log.log("Begin test", Log.DEBUG);
- for (XasFragment f : fragments) {
- ioRoundTrip(f);
- // ioRoundTrip(f.flattenPure());
- // ioRoundTrip(f.treeifyPure());
- }
+
+ public void testIoRoundTrip() throws IOException {
+ Log.log("Begin test", Log.DEBUG);
+ for (XasFragment f : fragments) {
+ ioRoundTrip(f);
+ // ioRoundTrip(f.flattenPure());
+ // ioRoundTrip(f.treeifyPure());
+ }
}
- public void testTyping () throws IOException {
- Log.log("Begin test", Log.DEBUG);
- for (String type : XasUtil.factoryTypes()) {
- for (ItemList source : typeds) {
- Log.debug("Source fragment", source);
- ItemList target = new ItemList();
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- FormatFactory factory = XasUtil.getFactory(type);
- SerializerTarget serTarget =
- factory.createTarget(bout, "UTF-8");
- XasUtil.copy(source.source(), serTarget);
- serTarget.flush();
- byte[] result = bout.toByteArray();
- Log.log("Document", Log.DEBUG, Util.toPrintable(result));
- ByteArrayInputStream bin = new ByteArrayInputStream(result);
- ParserSource parserSource = factory.createSource(bin);
- ItemSource primitiveSource =
- new PrimitiveSource(parserSource, type, "UTF-8");
- ItemSource decodeSource = new DecodeSource(primitiveSource);
- XasUtil.copy(decodeSource, target);
- Log.debug("Target fragment", target);
- assertEquals("Type information did not round-trip with type "
- + type, source, target);
- }
- typeds = XmlData.getTypedData();
- }
+
+ public void testTyping() throws IOException {
+ Log.log("Begin test", Log.DEBUG);
+ for (String type : XasUtil.factoryTypes()) {
+ for (ItemList source : typeds) {
+ Log.debug("Source fragment", source);
+ ItemList target = new ItemList();
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ FormatFactory factory = XasUtil.getFactory(type);
+ SerializerTarget serTarget = factory.createTarget(bout, "UTF-8");
+ XasUtil.copy(source.source(), serTarget);
+ serTarget.flush();
+ byte[] result = bout.toByteArray();
+ Log.log("Document", Log.DEBUG, Util.toPrintable(result));
+ ByteArrayInputStream bin = new ByteArrayInputStream(result);
+ ParserSource parserSource = factory.createSource(bin);
+ ItemSource primitiveSource = new PrimitiveSource(parserSource, type, "UTF-8");
+ ItemSource decodeSource = new DecodeSource(primitiveSource);
+ XasUtil.copy(decodeSource, target);
+ Log.debug("Target fragment", target);
+ assertEquals("Type information did not round-trip with type " + type, source,
+ target);
+ }
+ typeds = XmlData.getTypedData();
+ }
}
- public void testQuery () throws IOException {
- Log.log("Begin test", Log.DEBUG);
- for (Queryable fragment : XmlData.getTrees()) {
- if (fragment instanceof Iterable) {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- XmlOutput xout = new XmlOutput(bout, "UTF-8");
- Iterable<Item> f = (Iterable<Item>) fragment;
- for (Item i : f) {
- xout.append(i);
- }
- xout.flush();
- Log.log("Document", Log.DEBUG, new String(bout.toByteArray(),
- "UTF-8"));
- }
- int[] k0 = new int[] {};
- int[] k1 = new int[] { 0 };
- int[] k2 = new int[] { 0, 1 };
- int[] k3 = new int[] { 0, 2 };
- int[] k4 = new int[] { 0, 1, 1 };
- Pointer p0 = fragment.query(k0);
- Pointer p1 = fragment.query(k1);
- Pointer p2 = fragment.query(k2);
- Pointer p3 = fragment.query(k3);
- Pointer p4 = fragment.query(k4);
- assertNotNull(p0);
- assertNotNull(p1);
- assertNotNull(p2);
- assertNull(p3);
- assertNotNull(p4);
- p0.canonicalize();
- p1.canonicalize();
- p2.canonicalize();
- p4.canonicalize();
- assertEquals(XmlData.sd, p0.get());
- assertEquals(XmlData.s0, p1.get());
- assertEquals(XmlData.s01, p2.get());
- assertEquals(XmlData.s011, p4.get());
- }
+ public void testQuery() throws IOException {
+ Log.log("Begin test", Log.DEBUG);
+ for (Queryable fragment : XmlData.getTrees()) {
+ if (fragment instanceof Iterable) {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ XmlOutput xout = new XmlOutput(bout, "UTF-8");
+ Iterable<Item> f = (Iterable<Item>) fragment;
+ for (Item i : f) {
+ xout.append(i);
+ }
+ xout.flush();
+ Log.log("Document", Log.DEBUG, new String(bout.toByteArray(), "UTF-8"));
+ }
+ int[] k0 = new int[] {};
+ int[] k1 = new int[] { 0 };
+ int[] k2 = new int[] { 0, 1 };
+ int[] k3 = new int[] { 0, 2 };
+ int[] k4 = new int[] { 0, 1, 1 };
+ Pointer p0 = fragment.query(k0);
+ Pointer p1 = fragment.query(k1);
+ Pointer p2 = fragment.query(k2);
+ Pointer p3 = fragment.query(k3);
+ Pointer p4 = fragment.query(k4);
+ assertNotNull(p0);
+ assertNotNull(p1);
+ assertNotNull(p2);
+ assertNull(p3);
+ assertNotNull(p4);
+ p0.canonicalize();
+ p1.canonicalize();
+ p2.canonicalize();
+ p4.canonicalize();
+ assertEquals(XmlData.sd, p0.get());
+ assertEquals(XmlData.s0, p1.get());
+ assertEquals(XmlData.s01, p2.get());
+ assertEquals(XmlData.s011, p4.get());
+ }
}
- public void testModify () throws IOException {
- Log.log("Begin test", Log.DEBUG);
- for (Queryable fragment : XmlData.getTrees()) {
- boolean isVer = fragment instanceof VersionedDocument;
- int[] k001 = new int[] { 0, 0, 1 };
- int[] k011 = new int[] { 0, 1, 1 };
- int[] k012 = new int[] { 0, 1, 2 };
- MutablePointer p001 = (MutablePointer) fragment.query(k001);
- VersionedPointer q001 = null;
- if (isVer) {
- q001 = (VersionedPointer) fragment.query(k001);
- }
- MutablePointer p011 = (MutablePointer) fragment.query(k011);
- MutablePointer p012 = (MutablePointer) fragment.query(k012);
- VersionedPointer q012 = null;
- if (isVer) {
- q012 = (VersionedPointer) fragment.query(k012);
- }
- assertNotNull(p001);
- assertNotNull(p011);
- assertNotNull(p012);
- if (isVer) {
- assertNotNull(q001);
- assertNotNull(q012);
- }
- p011.insert(XmlData.getFragment());
- p001.move(p012);
- p012.delete();
- if (isVer) {
- assertFalse(q012.isValid());
- assertNotNull(p001.get());
- assertNotNull(q001.get());
- assertEquals(p001.get(), q001.get());
- }
- if (fragment instanceof Iterable) {
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- XmlOutput xout = new XmlOutput(bout, "UTF-8");
- Iterable<Item> f = (Iterable<Item>) fragment;
- for (Item i : f) {
- xout.append(i);
- }
- xout.flush();
- Log.log("Fragment", Log.DEBUG, fragment);
- Log.log("Result", Log.DEBUG, new String(bout.toByteArray(),
- "UTF-8"));
- }
- }
+
+ public void testModify() throws IOException {
+ Log.log("Begin test", Log.DEBUG);
+ for (Queryable fragment : XmlData.getTrees()) {
+ boolean isVer = fragment instanceof VersionedDocument;
+ int[] k001 = new int[] { 0, 0, 1 };
+ int[] k011 = new int[] { 0, 1, 1 };
+ int[] k012 = new int[] { 0, 1, 2 };
+ MutablePointer p001 = (MutablePointer) fragment.query(k001);
+ VersionedPointer q001 = null;
+ if (isVer) {
+ q001 = (VersionedPointer) fragment.query(k001);
+ }
+ MutablePointer p011 = (MutablePointer) fragment.query(k011);
+ MutablePointer p012 = (MutablePointer) fragment.query(k012);
+ VersionedPointer q012 = null;
+ if (isVer) {
+ q012 = (VersionedPointer) fragment.query(k012);
+ }
+ assertNotNull(p001);
+ assertNotNull(p011);
+ assertNotNull(p012);
+ if (isVer) {
+ assertNotNull(q001);
+ assertNotNull(q012);
+ }
+ p011.insert(XmlData.getFragment());
+ p001.move(p012);
+ p012.delete();
+ if (isVer) {
+ assertFalse(q012.isValid());
+ assertNotNull(p001.get());
+ assertNotNull(q001.get());
+ assertEquals(p001.get(), q001.get());
+ }
+ if (fragment instanceof Iterable) {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ XmlOutput xout = new XmlOutput(bout, "UTF-8");
+ Iterable<Item> f = (Iterable<Item>) fragment;
+ for (Item i : f) {
+ xout.append(i);
+ }
+ xout.flush();
+ Log.log("Fragment", Log.DEBUG, fragment);
+ Log.log("Result", Log.DEBUG, new String(bout.toByteArray(), "UTF-8"));
+ }
+ }
}
}
View
523 src/fc/test/junit/XmlData.java
@@ -1,12 +1,10 @@
/*
* Copyright 2005--2008 Helsinki Institute for Information Technology
- *
- * This file is a part of Fuego middleware. Fuego middleware is free
- * software; you can redistribute it and/or modify it under the terms
- * of the MIT license, included as the file MIT-LICENSE in the Fuego
- * middleware source distribution. If you did not receive the MIT
- * license with the distribution, write to the Fuego Core project at
- * fuego-xas-users@hoslab.cs.helsinki.fi.
+ *
+ * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
+ * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
+ * Fuego middleware source distribution. If you did not receive the MIT license with the
+ * distribution, write to the Fuego Core project at fuego-xas-users@hoslab.cs.helsinki.fi.
*/
package fc.test.junit;
@@ -53,296 +51,293 @@
static final String TEST_NS = "http://www.hiit.fi/fuego/fc/test";
private static final AsymmetricCipherKeyPair keyPair;
- private static final Map<XasFragment, Integer> sigCounts =
- new IdentityHashMap<XasFragment, Integer>();
+ private static final Map<XasFragment, Integer> sigCounts = new IdentityHashMap<XasFragment, Integer>();
static StartDocument sd;
static StartTag s0;
static StartTag s01;
static StartTag s011;
- private XmlData () {
+
+ private XmlData() {
}
static {
- BigInteger modulus =
- new BigInteger(
- "114223138481062383818743472854345446729415521820579721478671411120076686448918620302220709845014730631814478188984612465856840519852245805751892337820823145686311359090114506894126920369485682523288840662511969165284005936035859388250282090838456799125935768645086141305672131191153192376610593502582005436827");
- BigInteger pub = new BigInteger("65537");
- BigInteger priv =
- new BigInteger(
- "70156155961948275567326563815950795233214260644274158546789757111501088844901677266662957312531515817361615431606536850758127492036749476157451855811245452516036408423715290481767027536732741413397901727264890487785997545700283017129062803344411768517700818077537872436050914359831030152123534899150431708577");
- RSAKeyParameters privParam = new RSAKeyParameters(true, modulus, priv);
- RSAKeyParameters pubParam = new RSAKeyParameters(true, modulus, pub);
- keyPair = new AsymmetricCipherKeyPair(pubParam, privParam);
+ BigInteger modulus = new BigInteger(
+ "114223138481062383818743472854345446729415521820579721478671411120076686448918620302220709845014730631814478188984612465856840519852245805751892337820823145686311359090114506894126920369485682523288840662511969165284005936035859388250282090838456799125935768645086141305672131191153192376610593502582005436827");
+ BigInteger pub = new BigInteger("65537");
+ BigInteger priv = new BigInteger(
+ "70156155961948275567326563815950795233214260644274158546789757111501088844901677266662957312531515817361615431606536850758127492036749476157451855811245452516036408423715290481767027536732741413397901727264890487785997545700283017129062803344411768517700818077537872436050914359831030152123534899150431708577");
+ RSAKeyParameters privParam = new RSAKeyParameters(true, modulus, priv);
+ RSAKeyParameters pubParam = new RSAKeyParameters(true, modulus, pub);
+ keyPair = new AsymmetricCipherKeyPair(pubParam, privParam);
}
- private static XasFragment convert (ItemSource source) throws IOException {
- List<Item> items = new ArrayList<Item>();
- Item item = source.next();
- Item firstItem = item;
- while (item != null) {
- items.add(item);
- item = source.next();
- }
- return new XasFragment(items, firstItem);
+
+ private static XasFragment convert(ItemSource source) throws IOException {
+ List<Item> items = new ArrayList<Item>();
+ Item item = source.next();
+ Item firstItem = item;
+ while (item != null) {
+ items.add(item);
+ item = source.next();
+ }
+ return new XasFragment(items, firstItem);
}
- public static AsymmetricCipherKeyPair getKeyPair () {
- return keyPair;
+
+ public static AsymmetricCipherKeyPair getKeyPair() {
+ return keyPair;
}
- public static List<XasFragment> getData () throws IOException {
- List<XasFragment> result = new ArrayList<XasFragment>();
- // BUG-20070204-1: This does not work in the Xebu project due
- // to the URL being a jar: URL instead of a file: URL. Need
- // to find a way to get resources from either kind of URL.
- URL url = XmlData.class.getResource("/test/xml/");
- try {
- File dir = new File(new URI(url.toString()));
- File[] files = dir.listFiles(); // NOTE: also lists dirs,despite
- // its name
- for (int i = 0; i < files.length; i++) {
- if (files[i].isDirectory())
- continue;
- KXmlParser parser = new KXmlParser();
- result.add(convert(new XmlPullSource(parser,
- new FileInputStream(files[i]))));
- }
- } catch (Exception ex) {
- //Util.throwWrapped(new IOException(ex.getMessage()), ex);
- }
- return result;
+
+ public static List<XasFragment> getData() throws IOException {
+ List<XasFragment> result = new ArrayList<XasFragment>();
+ // BUG-20070204-1: This does not work in the Xebu project due
+ // to the URL being a jar: URL instead of a file: URL. Need
+ // to find a way to get resources from either kind of URL.
+ URL url = XmlData.class.getResource("/test/xml/");
+ try {
+ File dir = new File(new URI(url.toString()));
+ File[] files = dir.listFiles(); // NOTE: also lists dirs,despite
+ // its name
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) continue;
+ KXmlParser parser = new KXmlParser();
+ result.add(convert(new XmlPullSource(parser, new FileInputStream(files[i]))));
+ }
+ } catch (Exception ex) {
+ // Util.throwWrapped(new IOException(ex.getMessage()), ex);
+ }
+ return result;
}
- public static List<ItemList> getTypedData () {
- List<ItemList> result = new ArrayList<ItemList>();
- ItemList list = new ItemList();
- list.append(StartDocument.instance());
- StartTag st = new StartTag(new Qname(TEST_NS, "foo"));
- st.addPrefix(XasUtil.XSI_NS, "xsi");
- st.addPrefix(XasUtil.XSD_NS, "xsd");
- st.addPrefix(TEST_NS, "test");
- st.addAttribute(XasUtil.XSI_TYPE, new ParsedPrimitive(new Qname(
- XasUtil.XSD_NS, "QName"), new Qname(XasUtil.XSD_NS, "int")));
- list.append(st);
- list.append(new ParsedPrimitive(new Qname(XasUtil.XSD_NS, "int"),
- Integer.valueOf(188)));
- list.append(new EndTag(new Qname(TEST_NS, "foo")));
- list.append(EndDocument.instance());
- result.add(list);
- list = new ItemList();
- list.append(StartDocument.instance());
- st = new StartTag(new Qname(TEST_NS, "bar"));
- st.addPrefix(XasUtil.XSI_NS, "xsi");
- st.addPrefix(XasUtil.XSD_NS, "xsd");
- st.addPrefix(TEST_NS, "test");
- st.addAttribute(XasUtil.XSI_TYPE, new ParsedPrimitive(new Qname(
- XasUtil.XSD_NS, "QName"), new Qname(TEST_NS, "person")));
- list.append(st);
- Person person =
- new Person("Jaakko", 30, Calendar.getInstance(TimeZone
- .getTimeZone("UTC")));
- list.append(new TypedItem(new Qname(TEST_NS, "person"), person));
- list.append(new EndTag(new Qname(TEST_NS, "bar")));
- list.append(EndDocument.instance());
- result.add(list);
- return result;
+
+ public static List<ItemList> getTypedData() {
+ List<ItemList> result = new ArrayList<ItemList>();
+ ItemList list = new ItemList();
+ list.append(StartDocument.instance());
+ StartTag st = new StartTag(new Qname(TEST_NS, "foo"));
+ st.addPrefix(XasUtil.XSI_NS, "xsi");
+ st.addPrefix(XasUtil.XSD_NS, "xsd");
+ st.addPrefix(TEST_NS, "test");
+ st.addAttribute(XasUtil.XSI_TYPE, new ParsedPrimitive(new Qname(XasUtil.XSD_NS, "QName"),
+ new Qname(XasUtil.XSD_NS, "int")));
+ list.append(st);
+ list.append(new ParsedPrimitive(new Qname(XasUtil.XSD_NS, "int"), Integer.valueOf(188)));
+ list.append(new EndTag(new Qname(TEST_NS, "foo")));
+ list.append(EndDocument.instance());
+ result.add(list);
+ list = new ItemList();
+ list.append(StartDocument.instance());
+ st = new StartTag(new Qname(TEST_NS, "bar"));
+ st.addPrefix(XasUtil.XSI_NS, "xsi");
+ st.addPrefix(XasUtil.XSD_NS, "xsd");
+ st.addPrefix(TEST_NS, "test");
+ st.addAttribute(XasUtil.XSI_TYPE, new ParsedPrimitive(new Qname(XasUtil.XSD_NS, "QName"),
+ new Qname(TEST_NS, "person")));
+ list.append(st);
+ Person person = new Person("Jaakko", 30, Calendar.getInstance(TimeZone.getTimeZone("UTC")));
+ list.append(new TypedItem(new Qname(TEST_NS, "person"), person));
+ list.append(new EndTag(new Qname(TEST_NS, "bar")));
+ list.append(EndDocument.instance());
+ result.add(list);
+ return result;
}
- public static int getSignatureCount (XasFragment f) {
- Integer count = sigCounts.get(f);
- if (count != null) {
- return count.intValue();
- } else {
- return 0;
- }
+ public static int getSignatureCount(XasFragment f) {
+ Integer count = sigCounts.get(f);
+ if (count != null) {
+ return count.intValue();
+ } else {
+ return 0;
+ }
}
- public static XasFragment getFragment () {
- Qname n = new Qname(XmlData.TEST_NS, "n");
- StartTag s = new StartTag(n);
- EndTag e = new EndTag(n);
- ArrayList<Item> result = new ArrayList<Item>();
- result.add(s);
- result.add(e);
- return new XasFragment(result, s);
+
+ public static XasFragment getFragment() {
+ Qname n = new Qname(XmlData.TEST_NS, "n");
+ StartTag s = new StartTag(n);
+ EndTag e = new EndTag(n);
+ ArrayList<Item> result = new ArrayList<Item>();
+ result.add(s);
+ result.add(e);
+ return new XasFragment(result, s);
}
- public static List<Queryable> getTrees () {
- ArrayList<Queryable> result = new ArrayList<Queryable>();
- sd = StartDocument.instance();
- EndDocument ed = EndDocument.instance();
- Qname n0 = new Qname(XmlData.TEST_NS, "n0");
- Qname n00 = new Qname(XmlData.TEST_NS, "n00");
- Qname n01 = new Qname(XmlData.TEST_NS, "n01");
- Qname n000 = new Qname(XmlData.TEST_NS, "n000");
- Qname n001 = new Qname(XmlData.TEST_NS, "n001");
- Qname n010 = new Qname(XmlData.TEST_NS, "n010");
- Qname n011 = new Qname(XmlData.TEST_NS, "n011");
- Qname n012 = new Qname(XmlData.TEST_NS, "n012");
- Qname n0110 = new Qname(XmlData.TEST_NS, "n0110");
- Qname n0111 = new Qname(XmlData.TEST_NS, "n0111");
- s0 = new StartTag(n0);
- StartTag s00 = new StartTag(n00, s0);
- s01 = new StartTag(n01, s0);
- StartTag s000 = new StartTag(n000, s00);
- StartTag s001 = new StartTag(n001, s00);
- StartTag s010 = new StartTag(n010, s01);
- s011 = new StartTag(n011, s01);
- StartTag s012 = new StartTag(n012, s01);
- StartTag s0110 = new StartTag(n0110, s011);
- StartTag s0111 = new StartTag(n0111, s011);
- EndTag e0 = new EndTag(n0);
- EndTag e00 = new EndTag(n00);
- EndTag e01 = new EndTag(n01);
- EndTag e000 = new EndTag(n000);
- EndTag e001 = new EndTag(n001);
- EndTag e010 = new EndTag(n010);
- EndTag e011 = new EndTag(n011);
- EndTag e012 = new EndTag(n012);
- EndTag e0110 = new EndTag(n0110);
- EndTag e0111 = new EndTag(n0111);
- ItemList list = new ItemList();
- list.append(sd);
- list.append(s0);
- list.append(s00);
- list.append(s000);
- list.append(e000);
- list.append(s001);
- list.append(e001);
- list.append(e00);
- list.append(s01);
- list.append(s010);
- list.append(e010);
- list.append(s011);
- list.append(s0110);
- list.append(e0110);
- list.append(s0111);
- list.append(e0111);
- list.append(e011);
- list.append(s012);
- list.append(e012);
- list.append(e01);
- list.append(e0);
- list.append(ed);
- // It's not possible to use non-versioned fragment for the things
- // XasTest wants to do
- // result.add(list.fragment());
- result.add(new VersionedDocument(list.fragment()));
- return result;
+
+ public static List<Queryable> getTrees() {
+ ArrayList<Queryable> result = new ArrayList<Queryable>();
+ sd = StartDocument.instance();
+ EndDocument ed = EndDocument.instance();
+ Qname n0 = new Qname(XmlData.TEST_NS, "n0");
+ Qname n00 = new Qname(XmlData.TEST_NS, "n00");
+ Qname n01 = new Qname(XmlData.TEST_NS, "n01");
+ Qname n000 = new Qname(XmlData.TEST_NS, "n000");
+ Qname n001 = new Qname(XmlData.TEST_NS, "n001");
+ Qname n010 = new Qname(XmlData.TEST_NS, "n010");
+ Qname n011 = new Qname(XmlData.TEST_NS, "n011");
+ Qname n012 = new Qname(XmlData.TEST_NS, "n012");
+ Qname n0110 = new Qname(XmlData.TEST_NS, "n0110");
+ Qname n0111 = new Qname(XmlData.TEST_NS, "n0111");
+ s0 = new StartTag(n0);
+ StartTag s00 = new StartTag(n00, s0);
+ s01 = new StartTag(n01, s0);
+ StartTag s000 = new StartTag(n000, s00);
+ StartTag s001 = new StartTag(n001, s00);
+ StartTag s010 = new StartTag(n010, s01);
+ s011 = new StartTag(n011, s01);
+ StartTag s012 = new StartTag(n012, s01);
+ StartTag s0110 = new StartTag(n0110, s011);
+ StartTag s0111 = new StartTag(n0111, s011);
+ EndTag e0 = new EndTag(n0);
+ EndTag e00 = new EndTag(n00);
+ EndTag e01 = new EndTag(n01);
+ EndTag e000 = new EndTag(n000);
+ EndTag e001 = new EndTag(n001);
+ EndTag e010 = new EndTag(n010);
+ EndTag e011 = new EndTag(n011);
+ EndTag e012 = new EndTag(n012);
+ EndTag e0110 = new EndTag(n0110);
+ EndTag e0111 = new EndTag(n0111);
+ ItemList list = new ItemList();
+ list.append(sd);
+ list.append(s0);
+ list.append(s00);
+ list.append(s000);
+ list.append(e000);
+ list.append(s001);
+ list.append(e001);
+ list.append(e00);
+ list.append(s01);
+ list.append(s010);
+ list.append(e010);
+ list.append(s011);
+ list.append(s0110);
+ list.append(e0110);
+ list.append(s0111);
+ list.append(e0111);
+ list.append(e011);
+ list.append(s012);
+ list.append(e012);
+ list.append(e01);
+ list.append(e0);
+ list.append(ed);
+ // It's not possible to use non-versioned fragment for the things
+ // XasTest wants to do
+ // result.add(list.fragment());
+ result.add(new VersionedDocument(list.fragment()));
+ return result;
}
public static class Person {
- public String name;
- public int age;
- public Calendar birthday;
-
- public Person (String name, int age, Calendar birthday) {
- this.name = name;
- this.age = age;
- this.birthday = birthday;
- }
-
- public int hashCode () {
- return name.hashCode() ^ age ^ birthday.hashCode();
- }
-
- public boolean equals (Object o) {
- if (o instanceof Person) {
- Person p = (Person) o;
- return name.equals(p.name) && age == p.age
- && birthday.equals(p.birthday);
- } else {
- return false;
- }
- }
-
- public String toString () {
- return "Person(name=" + name + ",age=" + age + ",birthday="
- + birthday + ")";
- }
+ public String name;
+ public int age;
+ public Calendar birthday;
+
+
+ public Person(String name, int age, Calendar birthday) {
+ this.name = name;
+ this.age = age;
+ this.birthday = birthday;
+ }
+
+
+ public int hashCode() {
+ return name.hashCode() ^ age ^ birthday.hashCode();
+ }
+
+
+ public boolean equals(Object o) {
+ if (o instanceof Person) {
+ Person p = (Person) o;
+ return name.equals(p.name) && age == p.age && birthday.equals(p.birthday);
+ } else {
+ return false;
+ }
+ }
+
+
+ public String toString() {
+ return "Person(name=" + name + ",age=" + age + ",birthday=" + birthday + ")";
+ }
}
public static class PersonCodec implements ValueCodec {
- private static final Qname KNOWN_TYPE = new Qname(TEST_NS, "person");
- private static final Qname NAME_NAME = new Qname(TEST_NS, "name");
- private static final Qname AGE_NAME = new Qname(TEST_NS, "age");
- private static final Qname BIRTHDAY_NAME =
- new Qname(TEST_NS, "birthday");
- private static final Qname NAME_TYPE =
- new Qname(XasUtil.XSD_NS, "string");
- private static final Qname AGE_TYPE = new Qname(XasUtil.XSD_NS, "int");
- private static final Qname BIRTHDAY_TYPE =
- new Qname(XasUtil.XSD_NS, "dateTime");
- private static final EndTag NAME_END =
- new EndTag(new Qname(TEST_NS, "name"));
- private static final EndTag AGE_END =
- new EndTag(new Qname(TEST_NS, "age"));
- private static final EndTag BIRTHDAY_END =
- new EndTag(new Qname(TEST_NS, "birthday"));
-
- private static StartTag tag (Qname name, Qname type, StartTag parent) {
- StartTag result = new StartTag(name, parent);
- result.addAttribute(XasUtil.XSI_TYPE, new ParsedPrimitive(
- new Qname(XasUtil.XSD_NS, "QName"), type));
- return result;
- }
-
- public boolean isKnown (Qname typeName) {
- return KNOWN_TYPE.equals(typeName);
- }
-
- public void encode (Qname typeName, Object value, ItemTarget target,
- StartTag parent) throws IOException {
- Person person = (Person) value;
- target.append(tag(NAME_NAME, NAME_TYPE, parent));
- target.append(new ParsedPrimitive(NAME_TYPE, person.name));
- target.append(NAME_END);
- target.append(tag(AGE_NAME, AGE_TYPE, parent));
- target.append(new ParsedPrimitive(AGE_TYPE, person.age));
- target.append(AGE_END);
- target.append(tag(BIRTHDAY_NAME, BIRTHDAY_TYPE, parent));
- target.append(new ParsedPrimitive(BIRTHDAY_TYPE, person.birthday));
- target.append(BIRTHDAY_END);
- }
-
- private Object expect (Qname name, Qname type, ItemSource source)
- throws IOException {
- Object result = null;
- Item item = source.next();
- if (Item.isStartTag(item)) {
- StartTag st = (StartTag) item;
- if (st.getName().equals(name)) {
- item = source.next();
- if (ParsedPrimitive.isParsedPrimitive(item)) {
- ParsedPrimitive pp = (ParsedPrimitive) item;
- if (pp.getTypeName().equals(type)) {
- result = pp.getValue();
- source.next();
- }
- }
- }
- }
- return result;
- }
-
- public Object decode (Qname typeName, ItemSource source)
- throws IOException {
- String name = (String) expect(NAME_NAME, NAME_TYPE, source);
- Integer age = (Integer) expect(AGE_NAME, AGE_TYPE, source);
- Calendar birthday =
- (Calendar) expect(BIRTHDAY_NAME, BIRTHDAY_TYPE, source);
- if (name != null && age != null && birthday != null) {
- return new Person(name, age.intValue(), birthday);
- } else {
- return null;
- }
- }
+ private static final Qname KNOWN_TYPE = new Qname(TEST_NS, "person");
+ private static final Qname NAME_NAME = new Qname(TEST_NS, "name");
+ private static final Qname AGE_NAME = new Qname(TEST_NS, "age");
+ private static final Qname BIRTHDAY_NAME = new Qname(TEST_NS, "birthday");
+ private static final Qname NAME_TYPE = new Qname(XasUtil.XSD_NS, "string");
+ private static final Qname AGE_TYPE = new Qname(XasUtil.XSD_NS, "int");
+ private static final Qname BIRTHDAY_TYPE = new Qname(XasUtil.XSD_NS, "dateTime");
+ private static final EndTag NAME_END = new EndTag(new Qname(TEST_NS, "name"));
+ private static final EndTag AGE_END = new EndTag(new Qname(TEST_NS, "age"));
+ private static final EndTag BIRTHDAY_END = new EndTag(new Qname(TEST_NS, "birthday"));
+
+
+ private static StartTag tag(Qname name, Qname type, StartTag parent) {
+ StartTag result = new StartTag(name, parent);
+ result.addAttribute(XasUtil.XSI_TYPE, new ParsedPrimitive(new Qname(XasUtil.XSD_NS,
+ "QName"), type));
+ return result;
+ }
+
+
+ public boolean isKnown(Qname typeName) {
+ return KNOWN_TYPE.equals(typeName);
+ }
+
+
+ public void encode(Qname typeName, Object value, ItemTarget target, StartTag parent)
+ throws IOException {
+ Person person = (Person) value;
+ target.append(tag(NAME_NAME, NAME_TYPE, parent));
+ target.append(new ParsedPrimitive(NAME_TYPE, person.name));
+ target.append(NAME_END);
+ target.append(tag(AGE_NAME, AGE_TYPE, parent));
+ target.append(new ParsedPrimitive(AGE_TYPE, person.age));
+ target.append(AGE_END);
+ target.append(tag(BIRTHDAY_NAME, BIRTHDAY_TYPE, parent));
+ target.append(new ParsedPrimitive(BIRTHDAY_TYPE, person.birthday));
+ target.append(BIRTHDAY_END);
+ }
+
+
+ private Object expect(Qname name, Qname type, ItemSource source) throws IOException {
+ Object result = null;
+ Item item = source.next();
+ if (Item.isStartTag(item)) {
+ StartTag st = (StartTag) item;
+ if (st.getName().equals(name)) {
+ item = source.next();
+ if (ParsedPrimitive.isParsedPrimitive(item)) {
+ ParsedPrimitive pp = (ParsedPrimitive) item;
+ if (pp.getTypeName().equals(type)) {
+ result = pp.getValue();
+ source.next();
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+
+ public Object decode(Qname typeName, ItemSource source) throws IOException {
+ String name = (String) expect(NAME_NAME, NAME_TYPE, source);
+ Integer age = (Integer) expect(AGE_NAME, AGE_TYPE, source);
+ Calendar birthday = (Calendar) expect(BIRTHDAY_NAME, BIRTHDAY_TYPE, source);
+ if (name != null && age != null && birthday != null) {
+ return new Person(name, age.intValue(), birthday);
+ } else {
+ return null;
+ }
+ }
}
View
104 src/fc/util/AbstractDictionary.java
@@ -1,12 +1,10 @@
/*
* Copyright 2005--2008 Helsinki Institute for Information Technology
- *
- * This file is a part of Fuego middleware. Fuego middleware is free
- * software; you can redistribute it and/or modify it under the terms
- * of the MIT license, included as the file MIT-LICENSE in the Fuego
- * middleware source distribution. If you did not receive the MIT
- * license with the distribution, write to the Fuego Core project at
- * fc-util-users@hoslab.cs.helsinki.fi.
+ *
+ * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
+ * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
+ * Fuego middleware source distribution. If you did not receive the MIT license with the
+ * distribution, write to the Fuego Core project at fc-util-users@hoslab.cs.helsinki.fi.
*/
package fc.util;
@@ -15,96 +13,118 @@
import java.util.Map;
import java.util.Set;
-/** Read-only map with un-listable keys. Any attempts to modify the
- * map, or list the keys (or corresponding values) will result in an
- * {@link java.lang.UnsupportedOperationException}. On the bright side,
- * it allows you to easily implement an efficient lookup table by only
- * overriding one method ({@link #lookup(String)}).
- *
+/**
+ * Read-only map with un-listable keys. Any attempts to modify the map, or list the keys (or
+ * corresponding values) will result in an {@link java.lang.UnsupportedOperationException}. On the
+ * bright side, it allows you to easily implement an efficient lookup table by only overriding one
+ * method ({@link #lookup(String)}).
* @author Tancred Lindholm
*/
-public abstract class AbstractDictionary implements Map<String,String> {
+public abstract class AbstractDictionary implements Map<String, String> {
public AbstractDictionary() {
-
+
}
-
+
+
protected abstract String lookup(String key);
-
- /** Not supported.
+
+
+ /**
+ * Not supported.
*/
-
+
public void clear() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
- /** Not supported.
+
+ /**
+ * Not supported.
*/
public String put(String key, String value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
- /** Not supported.
+
+ /**
+ * Not supported.
*/
public void putAll(Map<? extends String, ? extends String> m) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
- /** Not supported.
+
+ /**
+ * Not supported.
*/
public String remove(Object key) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
- /** Not supported.
+
+ /**
+ * Not supported.
*/
public int size() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
- /** Not supported.
+
+ /**
+ * Not supported.
*/
public boolean isEmpty() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
+
public boolean containsKey(Object key) {
- return key instanceof String && lookup((String)key)!=null;
+ return key instanceof String && lookup((String) key) != null;
}
- /** Not supported.
+
+ /**
+ * Not supported.
*/
public boolean containsValue(Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
+
public String get(Object key) {
- return key instanceof String ? lookup((String) key) : null;
+ return key instanceof String ? lookup((String) key) : null;
}
- /** Not supported.
+
+ /**
+ * Not supported.
*/
-
+
public Set<String> keySet() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
- /** Not supported.
- */
+
+ /**
+ * Not supported.
+ */
public Collection<String> values() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
- /** Not supported.
+
+ /**
+ * Not supported.
*/
public Set<Entry<String, String>> entrySet() {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
}
View
37 src/fc/util/BaInputStream.java
@@ -1,12 +1,10 @@
/*
* Copyright 2005--2008 Helsinki Institute for Information Technology
- *
- * This file is a part of Fuego middleware. Fuego middleware is free
- * software; you can redistribute it and/or modify it under the terms
- * of the MIT license, included as the file MIT-LICENSE in the Fuego
- * middleware source distribution. If you did not receive the MIT
- * license with the distribution, write to the Fuego Core project at
- * fc-util-users@hoslab.cs.helsinki.fi.
+ *
+ * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
+ * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
+ * Fuego middleware source distribution. If you did not receive the MIT license with the
+ * distribution, write to the Fuego Core project at fc-util-users@hoslab.cs.helsinki.fi.
*/
package fc.util;
@@ -15,27 +13,24 @@
import java.io.IOException;
/**
- *
* @author Jaakko Kangasharju
- *
*/
-public class BaInputStream extends ByteArrayInputStream
- implements SeekableInputStream {
+public class BaInputStream extends ByteArrayInputStream implements SeekableInputStream {
- public BaInputStream (byte[] buf) {
- super(buf);
+ public BaInputStream(byte[] buf) {
+ super(buf);
}
- public BaInputStream (byte[] buf, int offset, int length) {
- super(buf, offset, length);
+
+ public BaInputStream(byte[] buf, int offset, int length) {
+ super(buf, offset, length);
}
- public void seek (long pos) throws IOException {
- if (pos < 0 || pos > count) {
- throw new IOException(String.valueOf(pos) + " not between 0 and "
- + count);
- }
- this.pos = (int) pos;
+
+ public void seek(long pos) throws IOException {
+ if (pos < 0 || pos > count) { throw new IOException(String.valueOf(pos) +
+ " not between 0 and " + count); }
+ this.pos = (int) pos;
}
}
View
243 src/fc/util/BinaryData.java
@@ -1,12 +1,10 @@
/*
* Copyright 2005--2008 Helsinki Institute for Information Technology
- *
- * This file is a part of Fuego middleware. Fuego middleware is free
- * software; you can redistribute it and/or modify it under the terms
- * of the MIT license, included as the file MIT-LICENSE in the Fuego
- * middleware source distribution. If you did not receive the MIT
- * license with the distribution, write to the Fuego Core project at
- * fc-util-users@hoslab.cs.helsinki.fi.
+ *
+ * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
+ * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
+ * Fuego middleware source distribution. If you did not receive the MIT license with the
+ * distribution, write to the Fuego Core project at fc-util-users@hoslab.cs.helsinki.fi.
*/
package fc.util;
@@ -16,143 +14,142 @@
import java.io.OutputStream;
/**
- *
* @author Jaakko Kangasharju
- *
*/
public class BinaryData {
- private BinaryData () {
+ private BinaryData() {
}
- public static long readNumber (InputStream in) throws IOException {
- return readNumber(in, in.read());
+
+ public static long readNumber(InputStream in) throws IOException {
+ return readNumber(in, in.read());
}
- public static long readNumber (InputStream in, int first)
- throws IOException {
- if (first == 0) {
- return 0;
- }
- long value = first & 0x7F;
- int i = 7;
- while ((first & 0x80) != 0) {
- first = in.read();
- value |= (((long) (first & 0x7F)) << i);
- i += 7;
- }
- return value;
+
+ public static long readNumber(InputStream in, int first) throws IOException {
+ if (first == 0) { return 0; }
+ long value = first & 0x7F;
+ int i = 7;
+ while ((first & 0x80) != 0) {
+ first = in.read();
+ value |= (((long) (first & 0x7F)) << i);
+ i += 7;
+ }
+ return value;
}
- public static long readNumber (byte[] b, int off, int len) {
- if (b == null) {
- throw new NullPointerException("Received null byte array");
- }
- if (off < 0 || off >= b.length) {
- throw new IllegalArgumentException("Invalid offset " + off
- + " not in [0," + b.length + ")");
- }
- if (len < 0 || off + len > b.length) {
- throw new IllegalArgumentException("Invalid length " + len
- + " not in [0," + (b.length - off) + "]");
- }
- int l = len;
- int o = off;
- long result = 0;
- int i = 0;
- while (l > 0) {
- byte value = b[o];
- result |= (((long) (value & 0x7F)) << i);
- i += 7;
- o += 1;
- l -= 1;
- if ((value & 0x80) == 0) {
- break;
- }
- }
- if (l == 0 && (b[o - 1] & 0x80) != 0) {
- throw new IllegalArgumentException("Array "
- + Util.toPrintable(b, off, len)
- + " does not start with a valid number");
- }
- return result;
+
+ public static long readNumber(byte[] b, int off, int len) {
+ if (b == null) { throw new NullPointerException("Received null byte array"); }
+ if (off < 0 || off >= b.length) { throw new IllegalArgumentException("Invalid offset " +
+ off + " not in [0," +
+ b.length + ")"); }
+ if (len < 0 || off + len > b.length) { throw new IllegalArgumentException(
+ "Invalid length " +
+ len +
+ " not in [0," +
+ (b.length - off) +
+ "]"); }
+ int l = len;
+ int o = off;
+ long result = 0;
+ int i = 0;
+ while (l > 0) {
+ byte value = b[o];
+ result |= (((long) (value & 0x7F)) << i);
+ i += 7;
+ o += 1;
+ l -= 1;
+ if ((value & 0x80) == 0) {
+ break;
+ }
+ }
+ if (l == 0 && (b[o - 1] & 0x80) != 0) { throw new IllegalArgumentException(
+ "Array " +
+ Util.toPrintable(
+ b,
+ off,
+ len) +
+ " does not start with a valid number"); }
+ return result;
}
- public static int numberLength (byte[] b, int off, int len) {
- if (b == null) {
- throw new NullPointerException("Received null byte array");
- }
- if (off < 0 || off >= b.length) {
- throw new IllegalArgumentException("Invalid offset " + off
- + " not in [0," + b.length + ")");
- }
- if (len < 0 || off + len > b.length) {
- throw new IllegalArgumentException("Invalid length " + len
- + " not in [0," + (b.length - off) + "]");
- }
- int result = 0;
- int o = off;
- int l = len;
- do {
- result += 1;
- o += 1;
- l -= 1;
- } while (l > 0 && (b[o - 1] & 0x80) != 0);
- if (l == 0 && (b[o - 1] & 0x80) != 0) {
- throw new IllegalArgumentException("Array "
- + Util.toPrintable(b, off, len)
- + " does not contain a complete number");
- }
- return result;
+
+ public static int numberLength(byte[] b, int off, int len) {
+ if (b == null) { throw new NullPointerException("Received null byte array"); }
+ if (off < 0 || off >= b.length) { throw new IllegalArgumentException("Invalid offset " +
+ off + " not in [0," +
+ b.length + ")"); }
+ if (len < 0 || off + len > b.length) { throw new IllegalArgumentException(
+ "Invalid length " +
+ len +
+ " not in [0," +
+ (b.length - off) +
+ "]"); }
+ int result = 0;
+ int o = off;
+ int l = len;
+ do {
+ result += 1;
+ o += 1;
+ l -= 1;
+ } while (l > 0 && (b[o - 1] & 0x80) != 0);
+ if (l == 0 && (b[o - 1] & 0x80) != 0) { throw new IllegalArgumentException(
+ "Array " +
+ Util.toPrintable(
+ b,
+ off,
+ len) +
+ " does not contain a complete number"); }
+ return result;
}
- public static String readString (InputStream in) throws IOException {
- return readString(in, in.read());
+
+ public static String readString(InputStream in) throws IOException {
+ return readString(in, in.read());
}
- private static String readString (InputStream in, int first)
- throws IOException {
- int len = (int) readNumber(in, first);
- byte[] bytes = new byte[len];
- int offset = 0;
- while (len > 0) {
- int n = in.read(bytes, offset, len);
- if (n < 0) {
- throw new IOException(
- "Premature end of stream, expected to read " + len
- + " more bytes");
- }
- offset += n;
- len -= n;
- }
- return new String(bytes, "US-ASCII");
+
+ private static String readString(InputStream in, int first) throws IOException {
+ int len = (int) readNumber(in, first);
+ byte[] bytes = new byte[len];
+ int offset = 0;
+ while (len > 0) {
+ int n = in.read(bytes, offset, len);
+ if (n < 0) { throw new IOException("Premature end of stream, expected to read " + len +
+ " more bytes"); }
+ offset += n;
+ len -= n;
+ }
+ return new String(bytes, "US-ASCII");
}
- public static void writeNumber (long value, OutputStream out)
- throws IOException {
- if (value == 0) {
- out.write(0x00);
- } else if (value > 0) {
- do {
- long next = value >>> 7;
- int b = (int) (value & 0x7F);
- if (next > 0) {
- b |= 0x80;
- }
- out.write(b);
- value = next;
- } while (value > 0);
- } else {
- throw new IOException("Negative value " + value + " not supported");
- }
+
+ public static void writeNumber(long value, OutputStream out) throws IOException {
+ if (value == 0) {
+ out.write(0x00);
+ } else if (value > 0) {
+ do {
+ long next = value >>> 7;
+ int b = (int) (value & 0x7F);
+ if (next > 0) {
+ b |= 0x80;
+ }
+ out.write(b);
+ value = next;
+ } while (value > 0);
+ } else {
+ throw new IOException("Negative value " + value + " not supported");
+ }
}
- public static void writeString (String value, OutputStream out)
- throws IOException {
- byte[] bytes = value.getBytes("US-ASCII");
- writeNumber(bytes.length, out);
- out.write(bytes);
+
+ public static void writeString(String value, OutputStream out) throws IOException {
+ byte[] bytes = value.getBytes("US-ASCII");
+ writeNumber(bytes.length, out);
+ out.write(bytes);
}
}
View
181 src/fc/util/ByteArray.java
</
@@ -1,12 +1,10 @@
/*
* Copyright 2005--2008 Helsinki Institute for Information Technology
- *
- * This file is a part of Fuego middleware. Fuego middleware is free
- * software; you can redistribute it and/or modify it under the terms
- * of the MIT license, included as the file MIT-LICENSE in the Fuego
- * middleware source distribution. If you did not receive the MIT
- * license with the distribution, write to the Fuego Core project at
- * fc-util-users@hoslab.cs.helsinki.fi.
+ *
+ * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
+ * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
+ * Fuego middleware source distribution. If you did not receive the MIT license with the
+ * distribution, write to the Fuego Core project at fc-util-users@hoslab.cs.helsinki.fi.
*/
package fc.util;
@@ -27,106 +25,113 @@
private byte[] data;
private int hash = 0;
- private static void insert (ByteArray array) {
- short size = (short) entries.size();
- if (size < MAX_SIZE) {
- if (tail >= 0) {
- nexts[tail] = size;
- } else {
- head = 0;
- }
- prevs[size] = tail;
- nexts[size] = -1;
- tail = size;
- } else {
- // XXX KLUDGE-20070305-1: This was observed to be null in SeisGen
- if (keys[tail] != null) {
- entries.remove(keys[tail]);
- }
- }
- entries.put(array, new Entry(array, tail));
- access(tail);
- keys[tail] = array;
+
+ private static void insert(ByteArray array) {
+ short size = (short) entries.size();
+ if (size < MAX_SIZE) {
+ if (tail >= 0) {
+ nexts[tail] = size;
+ } else {
+ head = 0;
+ }
+ prevs[size] = tail;
+ nexts[size] = -1;
+ tail = size;
+ } else {
+ // XXX KLUDGE-20070305-1: This was observed to be null in SeisGen
+ if (keys[tail] != null) {
+ entries.remove(keys[tail]);
+ }
+ }
+ entries.put(array, new Entry(array, tail));
+ access(tail);
+ keys[tail] = array;
}
- private static void access (short index) {
- if (head != index) {
- short next = nexts[index];
- short prev = prevs[index];
- nexts[prev] = next;
- if (next >= 0) {
- prevs[next] = prev;
- } else {
- tail = prev;
- }
- nexts[index] = head;
- prevs[index] = -1;
- prevs[head] = index;
- head = index;
- }
+
+ private static void access(short index) {
+ if (head != index) {
+ short next = nexts[index];
+ short prev = prevs[index];
+ nexts[prev] = next;
+ if (next >= 0) {
+ prevs[next] = prev;
+ } else {
+ tail = prev;
+ }
+ nexts[index] = head;
+ prevs[index] = -1;
+ prevs[head] = index;
+ head = index;
+ }
}
- private ByteArray (byte[] data) {
- this.data = data;
+
+ private ByteArray(byte[] data) {
+ this.data = data;
}
- public static ByteArray construct (byte[] data) {
- return new ByteArray(data).intern();
+
+ public static ByteArray construct(byte[] data) {
+ return new ByteArray(data).intern();
}
- public ByteArray intern () {
- Entry entry = (Entry) entries.get(this);
- if (entry != null) {
- access(entry.index);
- return entry.array;
- } else {
- insert(this);
- return this;
- }
+
+ public ByteArray intern() {
+ Entry entry = (Entry) entries.get(this);
+ if (entry != null) {
+ access(entry.index);
+ return entry.array;
+ } else {
+ insert(this);
+ return this;
+ }
}
- public byte[] getData () {
- return data;
+
+ public byte[] getData() {
+ return data;
}
- public int hashCode () {
- if (hash == 0) {
- for (int i = 0; i < data.length; i++) {
- hash = 37 * hash + data[i];
- }
- }
- return hash;
+
+ public int hashCode() {
+ if (hash == 0) {
+ for (int i = 0; i < data.length; i++) {
+ hash = 37 * hash + data[i];
+ }
+ }
+ return hash;
}
- public boolean equals (Object o) {
- if (this == o) {
- return true;
- } else if (!(o instanceof ByteArray)) {
- return false;
- } else {
- ByteArray array = (ByteArray) o;
- if (data.length != array.data.length) {
- return false;
- } else {
- for (int i = 0; i < data.length; i++) {
- if (data[i] != array.data[i]) {
- return false;
- }
- }
- return true;
- }
- }
+
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ } else if (!(o instanceof ByteArray)) {
+ return false;
+ } else {
+ ByteArray array = (ByteArray) o;
+ if (data.length != array.data.length) {
+ return false;
+ } else {
+ for (int i = 0; i < data.length; i++) {
+ if (data[i] != array.data[i]) { return false; }
+ }
+ return true;
+ }
+ }
}
private static final class Entry {
- public ByteArray array;
- public short index;
+ public ByteArray array;
+ public short index;
+
- public Entry (ByteArray array, short index) {
- this.array = array;
- this.index = index;
- }
+ public Entry(ByteArray array, short index) {
+ this.array = array;
+ this.index = index;