You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by di...@apache.org on 2008/11/16 23:35:38 UTC
svn commit: r718128 [6/6] - in /incubator/etch/branches/etch-python: ./
binding-csharp/compiler/src/main/java/etch/bindings/csharp/compiler/
binding-csharp/compiler/src/main/resources/etch/bindings/csharp/compiler/
binding-csharp/runtime/ binding-cshar...
Modified: incubator/etch/branches/etch-python/tests/build.xml
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/tests/build.xml?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/tests/build.xml (original)
+++ incubator/etch/branches/etch-python/tests/build.xml Sun Nov 16 14:35:35 2008
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
-<project name="etch-tests" basedir="." default="build-all">
+<project name="etch-tests" basedir="." default="help">
<description>Functional Tests</description>
<property name="Etch.basedir" location="${basedir}/.." />
<import file="${Etch.basedir}/build-support/etch.includes.xml" />
+ <target name="help"><echo>Please select a target...</echo></target>
<!-- import etch task -->
<taskdef name="etch"
@@ -16,19 +17,20 @@
<property name="bin" location="${target}/bin" />
<property name="generated-sources" location="${target}/generated-sources/" />
<property name="classes" location="${target}/classes" />
- <property name="test-results" location="${target}/test-results" />
+ <property name="test-results" location="${target}/test-results" />
+ <property name="nunit-results" location="${target}/nunit-results" />
<!-- macros -->
<macrodef name="etch-test">
<attribute name="home" default="${Etch.HOME}" />
<attribute name="binding" />
<attribute name="file" />
- <attribute name="what" default="both" />
- <attribute name="output" default="${generated-sources}/main/etch/@{binding}" />
- <attribute name="templateoutput" default="${src}/main/@{binding}" />
+ <attribute name="what" default="both, intf" />
+ <attribute name="outputDir" default="${generated-sources}/main/etch/@{binding}" />
+ <attribute name="templateOutputDir" default="${src}/main/@{binding}" />
<element name="etchelements" implicit="true" optional="true" />
<sequential>
- <etch home="@{home}" binding="@{binding}" output="@{output}" what="@{what}" file="@{file}" >
+ <etch home="@{home}" binding="@{binding}" outputDir="@{outputDir}" what="@{what}" file="@{file}" >
<etchelements />
</etch>
</sequential>
@@ -43,17 +45,17 @@
<etch-test binding="@{binding}" file="${src}/main/etch/Async.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Bar.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Baz.etch" />
- <!-- <etch-test binding="@{binding}" file="${src}/main/etch/BigIdl.etch" /> -->
+ <etch-test binding="@{binding}" file="${src}/main/etch/BigIdl.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Closing.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Cuae.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Foo.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Inheritance.etch" />
- <etch-test binding="@{binding}" what="both,force,impl,main" file="${src}/main/etch/Test1.etch" />
+ <etch-test binding="@{binding}" what="all,force" file="${src}/main/etch/Test1.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Test2.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Test3.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Test4.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Test6.etch" />
- <etch-test binding="@{binding}" what="both,force,impl,main" file="${src}/main/etch/TestIncludes.etch" />
+ <etch-test binding="@{binding}" what="all,force" file="${src}/main/etch/TestIncludes.etch" />
<etch-test binding="@{binding}" file="${src}/main/etch/Types.etch" />
<!-- negative tests -->
@@ -70,6 +72,7 @@
<mkdir dir="${generated-sources}" />
<mkdir dir="${classes}" />
<mkdir dir="${test-results}" />
+ <mkdir dir="${nunit-results}" />
</target>
<!-- build the server -->
@@ -92,18 +95,10 @@
</fileset>
<fileset dir="${generated-sources}/main/etch/java" >
<include name="**/*.java" />
- <!-- <exclude name="**/*Test1*.java" /> -->
- <!-- <exclude name="**/*TestXml*.java" /> -->
- <!-- <exclude name="**/*TestIncludes*.java" /> -->
-
+ <exclude name="**/*BigIdl*.java" />
</fileset>
<testsources dir="${src}/test/java" >
- <include name="**/FakeTest1.java" />
- <include name="**/Test*.java" />
- <!-- <exclude name="**/*Test1*.java" /> -->
- <!-- <exclude name="**/*Test*Xml*.java" /> -->
- <!-- <exclude name="**/*Test*Includes*.java" /> -->
-
+ <include name="**/*.java" />
</testsources>
</initialize-clover>
</target>
@@ -115,14 +110,10 @@
<src path="${generated-sources}/main/etch/java" />
<src path="${src}/main/java" />
<src path="${src}/test/java" />
- <!-- <exclude name="**/*Test1*.java" /> -->
- <!-- <exclude name="**/*Test*Xml*.java" /> -->
- <!-- <exclude name="**/*Test*Includes*.java" /> -->
-
<classpath>
<pathelement location="${Etch.HOME}/lib/${etch-java-runtime.jar}" />
- <pathelement location="${Etch.HOME}/lib/${etch-compiler.jar}" />
<pathelement location="${Etch.dependency.junit.jar}" />
+ <pathelement location="${Etch.HOME}/lib/${etch-compiler.jar}" />
</classpath>
</javac>
</target>
@@ -133,10 +124,9 @@
errorProperty="build.tests.fail" failureProperty="build.tests.fail">
<classpath>
<pathelement location="${classes}" />
- <pathelement location="${Etch.dependency.junit.jar}" />
<pathelement location="${Etch.HOME}/lib/${etch-java-runtime.jar}" />
+ <pathelement location="${Etch.dependency.junit.jar}" />
<pathelement location="${Etch.HOME}/lib/${etch-compiler.jar}" />
-
<!-- TODO: remove if clover not available -->
<pathelement location="${Etch.dependency.clover.jar}"/>
</classpath>
@@ -144,22 +134,38 @@
<batchtest fork="true" todir="${test-results}">
<fileset dir="${src}/test/java">
<include name="**/Test*.java" />
-
- <!-- <include name="**/FakeTest1.java" /> -->
<!-- TODO debug Test*Xml failures -->
- <exclude name="**/*Test*Xml*.java" />
-
+ <exclude name="**/Test*Xml.java" />
</fileset>
</batchtest>
</junit>
</target>
- <target name="build-csharp" depends="generate-csharp" >
+ <target name="build-csharp" depends="generate-csharp,build-tests-csharp"
+ if="BUILD.csharp" />
- </target>
+ <target name="build-tests-csharp"
+ depends="build-tests-csharp-dotnet,build-tests-csharp-mono" />
- <target name="test-csharp" depends="build-csharp" >
+ <target name="build-tests-csharp-dotnet" if="USE.dotnet" >
+ <msbuild buildfile="${src}/test/csharp/TestsProj/TestsProj.csproj">
+ <property name="Configuration" value="${Etch.build.target}" />
+ </msbuild>
+ </target>
+ <target name="build-tests-csharp-mono" if="USE.mono" >
+ <echo message="TODO: build w/ mono" />
+ </target>
+
+ <target name="test-csharp" depends="build-csharp" if="BUILD.csharp" >
+ <mkdir dir="${nunit-results}" />
+
+ <nunit xmlout="${nunit-results}/NUnitResults.xml">
+ <testassembly name="${src}/test/csharp/TestsProj/bin/${Etch.build.target}/Tests.dll" />
+ </nunit>
+
+ <xslt style="${Etch.buildSupportDirectory}/NUnitToJUnit.xsl"
+ in="${nunit-results}/NUnitResults.xml" out="${test-results}/TEST-NUnitResults.xml" />
</target>
<target name="build-xml" depends="generate-xml" >
@@ -175,14 +181,12 @@
<!-- run unit tests -->
<target name="test" depends="build,test-java,test-csharp,test-xml" />
-
- <!-- build everything -->
- <target name="debug" depends="test" />
- <target name="release" depends="test" />
<!-- clean -->
<target name="clean">
<delete dir="${target}" quiet="true" />
+ <delete dir="${src}/test/csharp/TestsProj/obj" />
+ <delete dir="${src}/test/csharp/TestsProj/bin" />
</target>
</project>
Modified: incubator/etch/branches/etch-python/tests/src/main/etch/Bar.etch
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/tests/src/main/etch/Bar.etch?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/tests/src/main/etch/Bar.etch (original)
+++ incubator/etch/branches/etch-python/tests/src/main/etch/Bar.etch Sun Nov 16 14:35:35 2008
@@ -23,8 +23,8 @@
@Extern( java, "etch.bindings.java.util.StrStrHashMap", "",
"etch.bindings.java.util.StrStrHashMapSerializer", "" )
- @Extern(csharp, "StrStrHashMap", "Etch.Util",
- "StrStrHashMapSerializer", "")
+ @Extern( csharp, "StrStrHashMap", "Etch.Util",
+ "StrStrHashMapSerializer", "" )
extern BarTable
struct BarData( int code, BarTable barTable, BazData bazData )
Modified: incubator/etch/branches/etch-python/util/src/main/java/etch/util/URL.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/util/src/main/java/etch/util/URL.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/util/src/main/java/etch/util/URL.java (original)
+++ incubator/etch/branches/etch-python/util/src/main/java/etch/util/URL.java Sun Nov 16 14:35:35 2008
@@ -17,11 +17,11 @@
package etch.util;
+import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
-import java.util.Set;
/**
* Models a url of the form scheme://user:password@host:port/uri;parms?terms#fragment
@@ -50,7 +50,7 @@
this.host = other.host;
this.port = other.port;
this.uri = other.uri;
- this.params = copyParams( other.params );
+ this.params = copyList( other.params );
this.terms = copyTerms( other.terms );
this.fragment = other.fragment;
}
@@ -235,7 +235,7 @@
private String uri;
- private Set<String> params;
+ private List<String> params;
private Map<String, Object> terms;
@@ -318,7 +318,7 @@
*/
public void setPassword( String password )
{
- checkNotBlank( "password", password );
+ //checkNotBlank( "password", password );
this.password = password;
}
@@ -419,7 +419,7 @@
*
* @param prefix the prefix of the param to fetch (e.g., "transport=").
*
- * @return the param which starts with the specified prefix.
+ * @return the first param which starts with the specified prefix.
*/
public String getParam( String prefix )
{
@@ -428,13 +428,10 @@
if (params == null)
return null;
- Iterator<String> i = getParams();
- while (i.hasNext())
- {
- String s = i.next();
- if (s.startsWith( prefix ))
- return s;
- }
+ for (String p: params)
+ if (p.startsWith( prefix ))
+ return p;
+
return null;
}
@@ -443,17 +440,17 @@
* of the form "transport=tcp". But they can be anything you like, really.
* The iterator might be empty.
*/
- public Iterator<String> getParams()
+ public String[] getParams()
{
if (params == null)
- return new EmptyIterator<String>();
+ return new String[] {};
- return params.iterator();
+ return params.toArray( new String[] {} );
}
/**
- * Adds a param to the set of params for this url. Only the set of unique
- * params is maintained. Duplicate param values are suppressed.
+ * Adds a param to the list of params for this url. Only the unique
+ * params are maintained. Duplicate param values are suppressed.
*
* @param param a param (e.g., "transport=tcp" or "01831864574898475").
*/
@@ -480,24 +477,16 @@
if (params == null)
return null;
- Iterator<String> i = getParams();
- while (i.hasNext())
+ for (String p: getParams())
{
- String s = i.next();
- if (s.startsWith( prefix ))
+ if (p.startsWith( prefix ))
{
- i.remove();
- return s;
+ params.remove( p );
+ return p;
}
}
return null;
}
-
- private void checkNotNull( Object v, String msg )
- {
- if (v == null)
- throw new NullPointerException( msg );
- }
/**
* Removes all the params.
@@ -511,7 +500,7 @@
private void ensureParams()
{
if (params == null)
- params = new HashSet<String>();
+ params = new ArrayList<String>();
}
/////////////////
@@ -524,7 +513,7 @@
*/
public boolean hasTerms()
{
- return terms != null && terms.size() > 0;
+ return terms != null && !terms.isEmpty();
}
/**
@@ -535,6 +524,8 @@
*/
public boolean hasTerm( String name )
{
+ checkName( name );
+
if (terms == null)
return false;
@@ -546,17 +537,23 @@
* @param value
* @return true if there is a query term with the specified value.
*/
+ @SuppressWarnings("unchecked")
public boolean hasTerm( String name, String value )
{
+ checkName( name );
+
if (terms == null)
return false;
+ if (value == null)
+ return hasTerm( name );
+
Object obj = terms.get( name );
if (obj == null)
return false;
- if (obj instanceof Set)
- return ((Set<?>) obj).contains( value );
+ if (obj instanceof List)
+ return ((List<String>) obj).contains( value );
return obj.equals( value );
}
@@ -568,7 +565,7 @@
*/
public boolean hasTerm( String name, Integer value )
{
- return hasTerm( name, value.toString() );
+ return hasTerm( name, toString( value ) );
}
/**
@@ -578,17 +575,7 @@
*/
public boolean hasTerm( String name, Double value )
{
- return hasTerm( name, value.toString() );
- }
-
- /**
- * @param name
- * @param value
- * @return true if there is a query term with the specified value.
- */
- public boolean hasTerm( String name, int value )
- {
- return hasTerm( name, valueToString( value ) );
+ return hasTerm( name, toString( value ) );
}
/**
@@ -596,17 +583,20 @@
* @param value
* @return true if there is a query term with the specified value.
*/
- public boolean hasTerm( String name, double value )
+ public boolean hasTerm( String name, Boolean value )
{
- return hasTerm( name, valueToString( value ) );
+ return hasTerm( name, toString( value ) );
}
/**
* @param name
* @return true if the query term specified by name has multiple values.
*/
+ @SuppressWarnings("unchecked")
public boolean hasMultipleValues( String name )
{
+ checkName( name );
+
if (terms == null)
return false;
@@ -614,8 +604,8 @@
if (obj == null)
return false;
- if (obj instanceof Set)
- return ((Set<?>) obj).size() > 1;
+ if (obj instanceof List)
+ return ((List<String>) obj).size() > 1;
return false;
}
@@ -634,9 +624,11 @@
* @see #getIntegerTerm(String)
* @see #getDoubleTerm(String)
*/
- @SuppressWarnings(value={"unchecked"})
+ @SuppressWarnings("unchecked")
public String getTerm( String name )
{
+ checkName( name );
+
if (terms == null)
return null;
@@ -644,13 +636,20 @@
if (obj == null)
return null;
- if (obj instanceof Set)
+ if (obj instanceof List)
{
- Iterator<String> i = ((Set<String>) obj).iterator();
- String s = i.next();
+ Iterator<String> i = ((List<String>) obj).iterator();
+
+ if (!i.hasNext())
+ return null;
+
+ String v = i.next();
+
if (i.hasNext())
- throw new UnsupportedOperationException( "term has multiple values" );
- return s;
+ throw new UnsupportedOperationException( String.format(
+ "term '%s' has multiple values", name ) );
+
+ return v;
}
return (String) obj;
@@ -668,77 +667,92 @@
return defaultValue;
return value;
}
-
+
/**
- * Gets the boolean value of the specified query term.
+ * Gets the Integer value of the specified query term.
* @param name
- * @return the boolean value, or null if not found.
+ * @return the Integer value, or null if not found.
* @see #getTerm(String)
*/
- public Boolean getBooleanTerm( String name )
+ public Integer getIntegerTerm( String name )
{
String s = getTerm( name );
if (s == null)
return null;
- return new Boolean( s );
+ return Integer.valueOf( s );
}
/**
- * Gets the boolean value of the specified query term.
+ * Gets the integer value of the specified query term.
* @param name
* @param defaultValue the value to return if the term is not found.
- * @return the boolean value, or defaultValue if not found.
+ * @return the integer value, or defaultValue if not found.
* @see #getTerm(String)
*/
- public boolean getBooleanTerm( String name, boolean defaultValue )
+ public int getIntegerTerm( String name, int defaultValue )
{
- String s = getTerm( name );
- if (s == null)
+ Integer value = getIntegerTerm( name );
+ if (value == null)
return defaultValue;
- return Boolean.valueOf( s );
+ return value;
}
/**
- * Gets the integer value of the specified query term.
+ * Gets the Double value of the specified query term.
* @param name
- * @return the integer value, or null if not found.
+ * @return the Double value, or null if not found.
* @see #getTerm(String)
*/
- public Integer getIntegerTerm( String name )
+ public Double getDoubleTerm( String name )
{
String s = getTerm( name );
if (s == null)
return null;
- return new Integer( s );
+ return Double.valueOf( s );
}
/**
- * Gets the integer value of the specified query term.
+ * Gets the double value of the specified query term.
* @param name
* @param defaultValue the value to return if the term is not found.
- * @return the integer value, or defaultValue if not found.
+ * @return the double value, or defaultValue if not found.
* @see #getTerm(String)
*/
- public int getIntegerTerm( String name, int defaultValue )
+ public double getDoubleTerm( String name, double defaultValue )
{
- Integer i = getIntegerTerm( name );
- if (i == null)
+ Double value = getDoubleTerm( name );
+ if (value == null)
return defaultValue;
- return i;
+ return value;
}
-
+
/**
- * Gets the double value of the specified query term.
+ * Gets the boolean value of the specified query term.
* @param name
- * @return the double value, or null if not found.
+ * @return the boolean value, or null if not found.
* @see #getTerm(String)
*/
- public Double getDoubleTerm( String name )
+ public Boolean getBooleanTerm( String name )
{
String s = getTerm( name );
if (s == null)
return null;
- return new Double( s );
+ return Boolean.valueOf( s );
+ }
+
+ /**
+ * Gets the boolean value of the specified query term.
+ * @param name
+ * @param defaultValue the value to return if the term is not found.
+ * @return the boolean value, or defaultValue if not found.
+ * @see #getTerm(String)
+ */
+ public boolean getBooleanTerm( String name, boolean defaultValue )
+ {
+ Boolean value = getBooleanTerm( name );
+ if (value == null)
+ return defaultValue;
+ return value;
}
/**
@@ -746,43 +760,50 @@
* @param name
* @return an iterator over the string values of the query term. May be empty.
*/
- @SuppressWarnings(value={"unchecked"})
- public Iterator<String> getTerms( String name )
+ @SuppressWarnings("unchecked")
+ public String[] getTerms( String name )
{
+ checkName( name );
+
if (terms == null)
- return new EmptyIterator<String>();
+ return new String[] {};
Object obj = terms.get( name );
if (obj == null)
- return new EmptyIterator<String>();
+ return new String[] {};
- if (obj instanceof Set)
- return ((Set<String>) obj).iterator();
+ if (obj instanceof List)
+ return ((List<String>) obj).toArray( new String[] {} );
- return new SingleIterator<String>( (String) obj );
+ return new String[] { (String) obj };
}
/**
* Gets the names of the query terms.
* @return an iterator over the string names.
*/
- public Iterator<String> getTermNames()
+ public String[] getTermNames()
{
if (terms == null)
- return new EmptyIterator<String>();
+ return new String[] {};
- return terms.keySet().iterator();
+ return terms.keySet().toArray( new String[] {} );
}
/**
- * Adds the specified query term to the set of query terms. Duplicate
+ * Adds the specified query term to the list of query terms. Duplicate
* name/value pairs are suppressed.
* @param name
* @param value
*/
- @SuppressWarnings(value={"unchecked"})
+ @SuppressWarnings("unchecked")
public void addTerm( String name, String value )
{
+ checkName( name );
+
+ if (value == null)
+ return;
+
ensureTerms();
Object obj = terms.get( name );
@@ -792,60 +813,55 @@
return;
}
- if (obj instanceof Set)
+ if (obj instanceof List)
{
- ((Set<String>) obj).add( value );
+ List<String> values = (List<String>) obj;
+ if (!values.contains( value ))
+ values.add( value );
return;
}
- Set<String> values = new HashSet<String>();
+ // obj is not a list but we need one, so replace obj in terms with a
+ // list, then add value to the list.
+
+ List<String> values = new ArrayList<String>();
+ terms.put( name, values );
values.add( (String) obj );
+
values.add( value );
- terms.put( name, values );
}
/**
- * Adds the specified query term to the set of query terms. Duplicate
+ * Adds the specified query term to the list of query terms. Duplicate
* name/value pairs are suppressed.
* @param name
* @param value
*/
public void addTerm( String name, Integer value )
{
- addTerm( name, value.toString() );
+ addTerm( name, toString( value ) );
}
/**
- * Adds the specified query term to the set of query terms. Duplicate
+ * Adds the specified query term to the list of query terms. Duplicate
* name/value pairs are suppressed.
* @param name
* @param value
*/
public void addTerm( String name, Double value )
{
- addTerm( name, value.toString() );
- }
-
- /**
- * Adds the specified query term to the set of query terms. Duplicate
- * name/value pairs are suppressed.
- * @param name
- * @param value
- */
- public void addTerm( String name, int value )
- {
- addTerm( name, valueToString( value ) );
+ addTerm( name, toString( value ) );
}
/**
- * Adds the specified query term to the set of query terms. Duplicate
+ * Adds the specified query term to the list of query terms. Duplicate
* name/value pairs are suppressed.
* @param name
* @param value
*/
- public void addTerm( String name, double value )
+ public void addTerm( String name, Boolean value )
{
- addTerm( name, valueToString( value ) );
+ addTerm( name, toString( value ) );
}
/**
@@ -855,6 +871,8 @@
*/
public boolean removeTerm( String name )
{
+ checkName( name );
+
if (terms == null)
return false;
@@ -862,32 +880,75 @@
}
/**
- * Removes the specified name/value pair from the set of query terms.
+ * Removes the specified name/value pair from the list of query terms.
* @param name
* @param value
* @return true if the name/value pair was found and removed.
*/
- @SuppressWarnings(value={"unchecked"})
+ @SuppressWarnings("unchecked")
public boolean removeTerm( String name, String value )
{
+ checkName( name );
+
if (terms == null)
return false;
+ if (value == null)
+ return removeTerm( name );
+
Object obj = terms.get( name );
if (obj == null)
return false;
- if (obj instanceof Set)
+ if (obj instanceof List)
{
- Set<String> x = (Set<String>) obj;
- boolean ok = x.remove( value );
- if (x.size() == 1)
- terms.put( name, x.iterator().next() );
+ List<String> values = (List<String>) obj;
+ boolean ok = values.remove( value );
+ if (values.isEmpty())
+ terms.remove( name );
return ok;
}
- terms.remove( name );
- return true;
+ if (obj.equals( value ))
+ {
+ terms.remove( name );
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Removes the specified name/value pair from the list of query terms.
+ * @param name
+ * @param value
+ * @return true if the name/value pair was found and removed.
+ */
+ public boolean removeTerm( String name, Integer value )
+ {
+ return removeTerm( name, toString( value ) );
+ }
+
+ /**
+ * Removes the specified name/value pair from the list of query terms.
+ * @param name
+ * @param value
+ * @return true if the name/value pair was found and removed.
+ */
+ public boolean removeTerm( String name, Double value )
+ {
+ return removeTerm( name, toString( value ) );
+ }
+
+ /**
+ * Removes the specified name/value pair from the list of query terms.
+ * @param name
+ * @param value
+ * @return true if the name/value pair was found and removed.
+ */
+ public boolean removeTerm( String name, Boolean value )
+ {
+ return removeTerm( name, toString( value ) );
}
/**
@@ -996,12 +1057,12 @@
return code;
}
- private int hc( Map<?, ?> m )
+ private int hc( Map<String, Object> m )
{
return m != null ? m.hashCode() : 793;
}
- private int hc( Set<?> s )
+ private int hc( List<String> s )
{
return s != null ? s.hashCode() : 161;
}
@@ -1022,10 +1083,10 @@
if (obj == this)
return true;
- if (obj.getClass() != URL.class)
+ if (obj == null)
return false;
- if (obj == null)
+ if (obj.getClass() != URL.class)
return false;
URL other = (URL) obj;
@@ -1042,16 +1103,16 @@
if (!StringUtil.equals( host, other.host ))
return false;
- if (!equals( port, other.port ))
+ if (!eq( port, other.port ))
return false;
if (!StringUtil.equals( uri, other.uri ))
return false;
- if (!compareParams( params, other.params ))
+ if (!eq( params, other.params ))
return false;
- if (!compareTerms( terms, other.terms ))
+ if (!eq( terms, other.terms ))
return false;
if (!StringUtil.equals( fragment, other.fragment ))
@@ -1060,71 +1121,31 @@
return true;
}
- private boolean equals( Integer a, Integer b )
+ private boolean eq( Object a, Object b )
{
return a == b || (a != null && b != null && a.equals( b ));
}
- private boolean compareParams( Set<?> a, Set<?> b )
- {
- if (a == b)
- return true;
-
- int na = a != null ? a.size() : 0;
- int nb = b != null ? b.size() : 0;
-
- if (na == 0 || nb == 0)
- {
- // one or the other is empty
- return na == 0 && nb == 0; // true only if both are empty
- }
-
- return a.equals( b );
- }
-
- private boolean compareTerms( Map<?, ?> a, Map<?, ?> b )
- {
- if (a == b)
- return true;
-
- int na = a != null ? a.size() : 0;
- int nb = b != null ? b.size() : 0;
-
- if (na == 0 || nb == 0)
- {
- // one or the other is empty
- return na == 0 && nb == 0; // true only if both are empty
- }
-
- return a.equals( b );
- }
-
private void paramsToString( StringBuffer sb )
{
- Iterator<String> i = getParams();
- while (i.hasNext())
+ for (String p: getParams())
{
- String param = i.next();
sb.append( ';' );
- escape( sb, param );
+ escape( sb, p );
}
}
private void termsToString( StringBuffer sb )
{
char sep = '?';
- Iterator<String> i = getTermNames();
- while (i.hasNext())
+ for (String n: getTermNames())
{
- String name = i.next();
- Iterator<String> j = getTerms( name );
- while (j.hasNext())
+ for (String v: getTerms( n ))
{
- String value = j.next();
sb.append( sep );
- escape( sb, name );
+ escape( sb, n );
sb.append( '=' );
- escape( sb, value );
+ escape( sb, v );
sep = '&';
}
}
@@ -1202,7 +1223,7 @@
return true;
}
- private String unescape( String s )
+ private static String unescape( String s )
{
StringBuffer sb = new StringBuffer();
CharIterator i = new CharIterator( s );
@@ -1226,6 +1247,23 @@
}
return sb.toString();
}
+
+ private static void checkName( String name )
+ {
+ if (name == null || name.length() == 0)
+ throw new IllegalArgumentException( "name null or empty" );
+ }
+
+ private static String toString( Object value )
+ {
+ return value != null ? value.toString() : null;
+ }
+
+ private static void checkNotNull( Object v, String msg )
+ {
+ if (v == null)
+ throw new NullPointerException( msg );
+ }
private static void checkNotBlank( String name, String value )
{
@@ -1233,7 +1271,7 @@
throw new IllegalArgumentException( name+" is blank" );
}
- private void checkNotInteger( String name, String value )
+ private static void checkNotInteger( String name, String value )
{
checkNotBlank( name, value );
try
@@ -1245,40 +1283,32 @@
throw new IllegalArgumentException( name+" is not integer" );
}
}
-
- private static String valueToString( int value )
- {
- return Integer.toString( value );
- }
-
- private static String valueToString( double value )
- {
- return Double.toString( value );
- }
- private static Set<String> copyParams( Set<String> params )
+ private static List<String> copyList( List<String> params )
{
+ // just goes one level deep.
+
if (params == null)
return null;
- return new HashSet<String>( params );
+ return new ArrayList<String>( params );
}
- @SuppressWarnings(value={"unchecked"})
+ @SuppressWarnings("unchecked")
private static Map<String, Object> copyTerms( Map<String, Object> terms )
{
if (terms == null)
return null;
- Map<String, Object> map = new HashMap<String, Object>( terms );
- Iterator<Map.Entry<String, Object>> i = map.entrySet().iterator();
- while (i.hasNext())
+ Map<String, Object> nterms = new HashMap<String, Object>();
+ for (Map.Entry<String, Object> me: terms.entrySet())
{
- Map.Entry<String, Object> me = i.next();
- Object obj = me.getValue();
- if (obj instanceof Set)
- me.setValue( new HashSet<String>( (Set<String>) obj ) );
+ String name = me.getKey();
+ Object value = me.getValue();
+ if (value instanceof List)
+ value = copyList( (List<String>) value );
+ nterms.put( name, value );
}
- return map;
+ return nterms;
}
}
Modified: incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/CommandParser.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/CommandParser.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/CommandParser.java (original)
+++ incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/CommandParser.java Sun Nov 16 14:35:35 2008
@@ -61,46 +61,60 @@
*/
public void define( Option option )
{
- if (option.isHidden() && option.getDefaultValues() == null)
- throw new IllegalArgumentException( "hidden option '"+option+"' has no default value" );
-
- if (option.isHidden() && option.isSingleton())
- throw new IllegalArgumentException( "hidden option '"+option+"' redundantly marked singleton" );
+ // hidden options are just that, hidden, they aren't required. hidden means
+ // help doesn't show them. they can still be specified.
+// if (option.isHidden() && option.getDefaultValues() == null)
+// throw new IllegalArgumentException( "hidden option '"+option+"' has no default value" );
+
+ // adding hidden to an option just means it isn't shown in the help. it
+ // you shouldn't have to otherwise edit it. rude it is, however, to hide
+ // a required option with no default value.
+// if (option.isHidden() && option.isSingleton())
+// throw new IllegalArgumentException( "hidden option '"+option+"' redundantly marked singleton" );
if (option.isRequired() && option.getDefaultValues() != null)
throw new IllegalArgumentException( "option '"+option+"' with default value redundantly marked required" );
- if (!option.isHidden())
+ // we still want to process hidden options, just not show them.
+ if (true /* !option.isHidden() */)
{
Iterator<String> i = option.getTokens();
while (i.hasNext())
{
String token = i.next();
- if (!token.startsWith( "-" ))
- throw new IllegalArgumentException( "option token '"+token+"' does not start with dash" );
-
if (token.startsWith( "--" ))
{
- // long option
+ // long option (e.g., --name)
+
+ String name = token.substring( 2 );
- if (token.length() <= 2)
+ // rule out empty name
+ if (name.length() == 0)
throw new IllegalArgumentException( "long option token '"+token+"' has no chars after the dashes" );
- String name = token.substring( 2 );
- checkValidChars( name, "long option", token, tokenChars );
+ // rule out three or more dashes
+ if (name.startsWith( "-" ))
+ throw new IllegalArgumentException( "long option token '"+token+"' starts with three or more dashes" );
+
+ checkValidChars( name, "long option", token, longTokenChars );
defineOption( options, name, option );
continue;
}
- // short option (by char only, no dash)
+ if (!token.startsWith( "-" ))
+ throw new IllegalArgumentException( "option token '"+token+"' does not start with dash" );
- if (token.length() != 2)
- throw new IllegalArgumentException( "short option token '"+token+"' has more than one char after the dash" );
+ // short option (e.g., -c)
+
+ String c = token.substring( 1 );
+
+ // rule out any but single char
+ if (c.length() != 1)
+ throw new IllegalArgumentException( "short option token '"+token+"' must have only one char after the dash" );
- String ch = token.substring( 1 );
- checkValidChars( ch, "short option", token, shortTokenChars );
- defineOption( shortOptions, ch, option );
+ checkValidChars( c, "short option", token, shortTokenChars );
+ defineOption( shortOptions, c, option );
}
}
@@ -113,7 +127,7 @@
throw new IllegalArgumentException( descr+" token '"+token+"' has bad chars" );
}
- private final Pattern tokenChars = Pattern.compile( "^[a-z0-9]+(-[a-z0-9]+)*$" );
+ private final Pattern longTokenChars = Pattern.compile( "^[a-z0-9]+(-[a-z0-9]+)*$" );
private final Pattern shortTokenChars = Pattern.compile( "^[a-zA-Z0-9]$" );
@@ -178,9 +192,11 @@
if (token.startsWith( "-" ))
{
+ // might be a long option (e.g., --name), a short option
+ // (e.g., -c) or a parameter (-).
if (token.startsWith( "--" ))
{
- // handle long option
+ // handle long option (e.g., --name)
String[] x = StringUtil.leftSplit( token, '=' );
String tok = null;
@@ -222,10 +238,13 @@
if (!option.deliverValue( tok, values, false ))
return false;
+
+ continue;
}
- else
+ else if (token.length() > 1)
{
- // handle short option
+ // handle short option (e.g., -c)
+
CharIterator i = new CharIterator( token.substring( 1 ) );
while (i.hasNext())
{
@@ -235,7 +254,7 @@
if (option == null)
{
report( String.format(
- "unexpected command line option (%s)", tok ),
+ "unexpected command line option (-%s)", tok ),
token, argsIterator );
return false;
}
@@ -257,11 +276,10 @@
if (!option.deliverValue( tok, values, false ))
return false;
-
- continue;
}
+ continue;
}
- continue;
+ // token is -, which is a parameter, so just fall through...
}
// ok, we're delivering a non-option value.
@@ -501,7 +519,7 @@
continue;
// only show [options] if there are any visible options...
- System.err.print( " [options] " );
+ System.err.print( " [options]" );
hasOptions = true;
break;
}
Modified: incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/IntegerOption.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/IntegerOption.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/IntegerOption.java (original)
+++ incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/IntegerOption.java Sun Nov 16 14:35:35 2008
@@ -50,6 +50,6 @@
@Override
protected Object convertValue( String value )
{
- return new Integer( value );
+ return Integer.valueOf( value );
}
}
Modified: incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/IntegerParameter.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/IntegerParameter.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/IntegerParameter.java (original)
+++ incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/IntegerParameter.java Sun Nov 16 14:35:35 2008
@@ -43,6 +43,6 @@
@Override
public Object convertValue( String value )
{
- return new Integer( value );
+ return Integer.valueOf( value );
}
}
Modified: incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/Option.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/Option.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/Option.java (original)
+++ incubator/etch/branches/etch-python/util/src/main/java/etch/util/cmd/Option.java Sun Nov 16 14:35:35 2008
@@ -394,11 +394,12 @@
*/
private boolean checkOkToDeliver( String token, boolean hiddenOk )
{
- if (isHidden() && !hiddenOk)
- {
- getCommandParser().report( "option '"+toString( token )+"' not allowed", null, null );
- return false;
- }
+ // allow hidden option to be specified. just don't show it in help.
+// if (isHidden() && !hiddenOk)
+// {
+// getCommandParser().report( "option '"+toString( token )+"' not allowed", null, null );
+// return false;
+// }
if (getCommandParser().isAlreadySpecified( this, true ) && isSingleton())
{
Modified: incubator/etch/branches/etch-python/util/src/test/java/etch/util/TestCircularQueue.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/util/src/test/java/etch/util/TestCircularQueue.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/util/src/test/java/etch/util/TestCircularQueue.java (original)
+++ incubator/etch/branches/etch-python/util/src/test/java/etch/util/TestCircularQueue.java Sun Nov 16 14:35:35 2008
@@ -36,16 +36,17 @@
@Test
public void testgettimes() throws Exception
{
+ @SuppressWarnings("unused")
double[] times;
times = gettimes();
- System.out.printf( "times: hp %f / tod %f\n", times[0], times[1] );
+// System.out.printf( "times: hp %f / tod %f\n", times[0], times[1] );
times = gettimes();
- System.out.printf( "times: hp %f / tod %f\n", times[0], times[1] );
+// System.out.printf( "times: hp %f / tod %f\n", times[0], times[1] );
times = gettimes();
- System.out.printf( "times: hp %f / tod %f\n", times[0], times[1] );
+// System.out.printf( "times: hp %f / tod %f\n", times[0], times[1] );
}
private double[] gettimes() throws InterruptedException
@@ -213,7 +214,7 @@
for (int i: new int[] { 10, 20, 30, 50, 80, 130, 210, 340, 550, 890, 1440 } )
{
- System.out.printf( "get delay = %d\n", i );
+// System.out.printf( "get delay = %d\n", i );
long t0 = System.nanoTime();
assertNull( queue.get( i ) );
double t = (System.nanoTime() - t0) / 1000000.0;