From: <bo...@us...> - 2010-08-20 12:56:23
|
Revision: 433 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=433&view=rev Author: bodewig Date: 2010-08-20 12:56:17 +0000 (Fri, 20 Aug 2010) Log Message: ----------- cleanup Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml trunk/xmlunit/src/main/net-core/diff/XPathContext.cs trunk/xmlunit/src/main/net-core/util/Convert.cs trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java trunk/xmlunit/src/main/net-core/util/Linqy.cs Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java 2010-08-20 12:56:17 UTC (rev 433) @@ -96,20 +96,10 @@ public String getXPath() { StringBuilder sb = new StringBuilder(); - boolean first = true, second = false; for (Level l : path) { - if (!second) { - sb.append("/"); - } - sb.append(l.expression); - if (first) { - second = true; - } else { - second = false; - } - first = false; + sb.append("/").append(l.expression); } - return sb.toString(); + return sb.toString().replace("//", "/"); } private String getName(QName name) { Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java 2010-08-20 12:56:17 UTC (rev 433) @@ -13,7 +13,6 @@ */ package net.sf.xmlunit.util; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.w3c.dom.Node; @@ -50,20 +49,9 @@ } /** - * Turns the iterable into a list. - */ - public static List<Node> asList(IterableNodeList l) { - ArrayList<Node> a = new ArrayList<Node>(l.length); - for (Node n : l) { - a.add(n); - } - return a; - } - - /** * Turns the NodeList into a list. */ public static List<Node> asList(NodeList l) { - return asList(new IterableNodeList(l)); + return Linqy.asList(new IterableNodeList(l)); } } Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 2010-08-20 12:56:17 UTC (rev 433) @@ -0,0 +1,30 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +package net.sf.xmlunit.util; + +import java.util.ArrayList; +import java.util.List; + +public final class Linqy { + /** + * Turns the iterable into a list. + */ + public static <E> List<E> asList(Iterable<E> i) { + ArrayList<E> a = new ArrayList<E>(); + for (E e : i) { + a.add(e); + } + return a; + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-20 12:56:17 UTC (rev 433) @@ -21,6 +21,7 @@ <import reference="System.Collections.Generic"/> <import reference="System.Xml"/> <import reference="System.Xml.Schema"/> + <import reference="net.sf.xmlunit.util"/> <literal><![CDATA[ @@ -266,11 +267,9 @@ private ComparisonResult CompareNodeLists(XmlNodeList control, XmlNodeList test) { IList<XmlNode> controlList = - new List<XmlNode>(net.sf.xmlunit.util.Convert - .Cast<XmlNode>(control)); + new List<XmlNode>(Linqy.Cast<XmlNode>(control)); IList<XmlNode> testList = - new List<XmlNode>(net.sf.xmlunit.util.Convert - .Cast<XmlNode>(test)); + new List<XmlNode>(Linqy.Cast<XmlNode>(test)); IDictionary<int, object> unmatchedTestIndexes = new SortedDictionary<int, object>(); for (int i = 0; i < testList.Count; i++) { Modified: trunk/xmlunit/src/main/net-core/diff/XPathContext.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/XPathContext.cs 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/main/net-core/diff/XPathContext.cs 2010-08-20 12:56:17 UTC (rev 433) @@ -95,20 +95,10 @@ public string XPath { get { StringBuilder sb = new StringBuilder(); - bool first = true, second = false; foreach (Level l in path) { - if (!second) { - sb.Append("/"); - } - sb.Append(l.Expression); - if (first) { - second = true; - } else { - second = false; - } - first = false; + sb.AppendFormat("/{0}", l.Expression); } - return sb.ToString(); + return sb.Replace("//", "/").ToString(); } } Modified: trunk/xmlunit/src/main/net-core/util/Convert.cs =================================================================== --- trunk/xmlunit/src/main/net-core/util/Convert.cs 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/main/net-core/util/Convert.cs 2010-08-20 12:56:17 UTC (rev 433) @@ -12,7 +12,6 @@ limitations under the License. */ -using System.Collections; using System.Collections.Generic; using System.Xml; using net.sf.xmlunit.input; @@ -73,11 +72,5 @@ } return man; } - - public static IEnumerable<T> Cast<T>(IEnumerable i) { - foreach (T t in i) { - yield return t; - } - } } } Added: trunk/xmlunit/src/main/net-core/util/Linqy.cs =================================================================== --- trunk/xmlunit/src/main/net-core/util/Linqy.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/util/Linqy.cs 2010-08-20 12:56:17 UTC (rev 433) @@ -0,0 +1,34 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using System.Collections; +using System.Collections.Generic; + +namespace net.sf.xmlunit.util { + /// <summary> + /// Conversion methods. + /// </summary> + public sealed class Linqy { + public static IEnumerable<T> Cast<T>(IEnumerable i) { + foreach (T t in i) { + yield return t; + } + } + + public static IEnumerable<T> Singleton<T>(T t) { + yield return t; + } + + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/net-core/util/Linqy.cs ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs 2010-08-20 12:56:17 UTC (rev 433) @@ -14,6 +14,7 @@ using System; using System.Collections.Generic; using System.Xml; +using net.sf.xmlunit.util; using NUnit.Framework; namespace net.sf.xmlunit.diff { @@ -71,7 +72,7 @@ [Test] public void Attributes() { XPathContext ctx = new XPathContext(); - ctx.RegisterChildren(Singleton(new Element("foo"))); + ctx.RegisterChildren(Linqy.Singleton(new Element("foo"))); ctx.NavigateToChild(0); List<XmlQualifiedName> l = new List<XmlQualifiedName>(); l.Add(new XmlQualifiedName("bar")); @@ -80,10 +81,6 @@ Assert.AreEqual("/foo[1]/@bar", ctx.XPath); } - private static IEnumerable<T> Singleton<T>(T t) { - yield return t; - } - [Test] public void Mixed() { List<XPathContext.INodeInfo> l = new List<XPathContext.INodeInfo>(); @@ -147,7 +144,8 @@ Dictionary<string, string> m = new Dictionary<string, string>(); m["urn:foo:bar"] = "bar"; XPathContext ctx = new XPathContext(m); - ctx.RegisterChildren(Singleton(new Element("foo", "urn:foo:bar"))); + ctx.RegisterChildren(Linqy.Singleton(new Element("foo", + "urn:foo:bar"))); ctx.NavigateToChild(0); List<XmlQualifiedName> l = new List<XmlQualifiedName>(); l.Add(new XmlQualifiedName("baz")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |