svn commit: r1154855 [2/2] - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/ native/include/acr/ native/os/win32/ native/shared/

2011-08-08 Thread mturk
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsstream.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsstream.c?rev=1154855r1=1154854r2=1154855view=diff
==
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsstream.c 
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsstream.c Mon Aug 
 8 06:57:15 2011
@@ -55,10 +55,10 @@ ACR_INLINE(int) sdrelease(acr_ss_t *ss)
 return 1;
 }
 
-ACR_NET_EXPORT(jlong, IpcStream, alloc0)(JNI_STDARGS, jlong fp)
+ACR_NET_EXPORT(jlong, IpcStream, alloc0)(JNI_STDARGS, jlong sp)
 {
 acr_ss_t *ss;
-acr_sd_t *sd = J2P(fp, acr_sd_t *);
+acr_sd_t *sd = J2P(sp, acr_sd_t *);
 
 if (sd == 0 || sd-p == 0) {
 ACR_THROW_NET_ERROR(ACR_EBADF);
@@ -79,6 +79,26 @@ ACR_NET_EXPORT(jint, IpcStream, close0)(
 return 0;
 }
 
+ACR_NET_EXPORT(jboolean, IpcStream, eof0)(JNI_STDARGS, jlong sp)
+{
+acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+if (ACR_HASFLAG(ss-sd, ACR_SO_RDEOF))
+return JNI_TRUE;
+else
+return JNI_FALSE;
+}
+
+ACR_NET_EXPORT(jint, IpcStream, avail0)(JNI_STDARGS, jlong sp)
+{
+acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+if (ss-sd != 0)
+return AcrIpcAvail(ss-sd-p, TRUE);
+else
+return -1;
+}
+
 ACR_NET_EXPORT(jint, IpcStream, read0)(JNI_STDARGS, jlong sp)
 {
 int  rc = 0;
@@ -94,7 +114,10 @@ ACR_NET_EXPORT(jint, IpcStream, read0)(J
 }
 if (ACR_HASFLAG(ss-sd, ACR_SO_RDEOF))
 goto finally;
-rd = AcrIpcRead(cp, ch, 1);
+if (cp-dwPageSize == 0)
+rd = AcrIpcRecv(cp, ch, 1);
+else
+rd = AcrIpcRead(cp, ch, 1);
 if (rd == -1)
 rc = ACR_GET_OS_ERROR();
 else if (rd == 1)
@@ -110,3 +133,442 @@ finally:
 return rv;
 }
 
+ACR_NET_EXPORT(jint, IpcStream, read1)(JNI_STDARGS, jlong sp,
+   jbyteArray buf,
+   jint off,
+   jint len)
+{
+int rc = 0;
+int rd = 0;
+jbyte  *bb = 0;
+jbyte  *bc = 0;
+jbyte   onstack[ACR_PBUFF_SIZ];
+acr_ss_t *ss = J2P(sp, acr_ss_t *);
+LPIPCSOCK cp;
+
+if ((cp = sdretain(ss)) == 0) {
+rc = ACR_EBADF;
+goto finally;
+}
+if (ACR_HASFLAG(ss-sd, ACR_SO_RDEOF))
+goto finally;
+if (len  ACR_PBUFF_SIZ) {
+if (len  ACR_MEGABYTE) {
+if ((bc = (*env)-GetByteArrayElements(env, buf, 0)) != 0)
+bb = bc + off;
+}
+else {
+/* Allocate buffer */
+bb = ACR_MALLOC(jbyte, len);
+}
+}
+if (bb == 0) {
+rc = ACR_ENOMEM;
+goto finally;
+}
+if (cp-dwPageSize == 0)
+rd = AcrIpcRecv(cp, bb, len);
+else
+rd = AcrIpcRead(cp, bb, len);
+if (rd == -1) {
+rc = GetLastError();
+goto finally;
+}
+else if (rd == 0)
+ss-sd-flags |= ACR_SO_RDEOF;
+
+finally:
+sdrelease(ss);
+if (rc == 0) {
+if (rd  0) {
+if (bc != 0) {
+(*env)-ReleaseByteArrayElements(env, buf, bc, 0);
+return (jint)rd;
+}
+else
+(*env)-SetByteArrayRegion(env, buf, (jsize)off, (jsize)rd, 
bb);
+}
+}
+if (bb != 0  bb != onstack) {
+if (bc != 0)
+(*env)-ReleaseByteArrayElements(env, buf, bc, JNI_ABORT);
+else
+AcrFree(bb);
+}
+if (rc != 0) {
+rd = 0;
+/* Throw exception */
+ACR_THROW_NET_ERROR(rc);
+}
+return rd;
+}
+
+ACR_NET_EXPORT(jint, IpcStream, read2)(JNI_STDARGS, jlong sp,
+   jlong pa,
+   jlong off,
+   jint len)
+{
+int rc = 0;
+int rd = 0;
+LPIPCSOCK cp;
+ptrdiff_t po = (ptrdiff_t)off;
+char *bb = J2P(pa, char *);
+acr_ss_t *ss = J2P(sp, acr_ss_t *);
+
+if ((cp = sdretain(ss)) == 0) {
+rc = ACR_EBADF;
+goto finally;
+}
+if (ACR_HASFLAG(ss-sd, ACR_SO_RDEOF))
+goto finally;
+if (bb == 0) {
+rc = ACR_EINVAL;
+goto finally;
+}
+if (cp-dwPageSize == 0)
+rd = AcrIpcRecv(cp, bb + po, len);
+else
+rd = AcrIpcRead(cp, bb + po, len);
+if (rd == -1) {
+rc = GetLastError();
+goto finally;
+}
+else if (rd == 0)
+ss-sd-flags |= ACR_SO_RDEOF;
+
+finally:
+sdrelease(ss);
+if (rc != 0) {
+rd = 0;
+/* Throw exception */
+ACR_THROW_NET_ERROR(rc);
+}
+return rd;
+}
+
+
+ACR_NET_EXPORT(jint, IpcStream, read3)(JNI_STDARGS, jlong sp,
+   jobject buf,
+   jint off,
+   jint len)
+{
+int rc = 0;
+

svn commit: r1154877 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/ar/ site/xdoc/ test/java/org/apache/commons/compress/archivers/ar/ test/resources/

2011-08-08 Thread bodewig
Author: bodewig
Date: Mon Aug  8 08:54:33 2011
New Revision: 1154877

URL: http://svn.apache.org/viewvc?rev=1154877view=rev
Log:
support reading of long file names in AR archives that use the BSD variant.  
COMPRESS-144

Added:
commons/proper/compress/trunk/src/test/resources/longfile_bsd.ar
  - copied, changed from r1154851, 
commons/proper/compress/trunk/src/test/resources/longfile_gnu.ar
Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
commons/proper/compress/trunk/src/site/xdoc/examples.xml

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=1154877r1=1154876r2=1154877view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 Mon Aug  8 08:54:33 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.commons.compress.archivers.ar;
 
+import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -143,6 +144,7 @@ public class ArArchiveInputStream extend
 
 // entry name is stored as ASCII string
 String temp = ArchiveUtils.toAsciiString(name).trim();
+long len = asLong(length);
 
 if (temp.equals(//)){ // GNU extended filenames entry
 int bufflen = asInt(length); // Assume length will fit in an int
@@ -158,8 +160,17 @@ public class ArArchiveInputStream extend
 } else if (temp.matches(^/\\d+)) {// GNU long filename ref.
 int offset = Integer.parseInt(temp.substring(1));// get the offset
 temp = getExtendedName(offset); // convert to the long name
+} else if (isBSDLongName(temp)) {
+temp = getBSDLongName(temp);
+// entry length contained the length of the file name in
+// addition to the real length of the entry.
+// assume file name was ASCII, there is no standard otherwise
+int nameLen = temp.length();
+len -= nameLen;
+entryOffset += nameLen;
 }
-currentEntry = new ArArchiveEntry(temp, asLong(length), asInt(userid, 
true),
+
+currentEntry = new ArArchiveEntry(temp, len, asInt(userid, true),
   asInt(groupid, true), 
asInt(filemode, 8),
   asLong(lastmodified));
 return currentEntry;
@@ -301,4 +312,58 @@ public class ArArchiveInputStream extend
 return true;
 }
 
+private static final String BSD_LONGNAME_PREFIX = #1/;
+private static final int BSD_LONGNAME_PREFIX_LEN =
+BSD_LONGNAME_PREFIX.length();
+
+/**
+ * Does the name look like it is a long name (or a name containing
+ * spaces) as encoded by BSD ar?
+ *
+ * pFrom the FreeBSD ar(5) man page:/p
+ * pre
+ * BSD   In the BSD variant, names that are shorter than 16
+ *  characters and without embedded spaces are stored
+ *  directly in this field.  If a name has an embedded
+ *  space, or if it is longer than 16 characters, then
+ *  the string #1/ followed by the decimal represen-
+ *  tation of the length of the file name is placed in
+ *  this field.The actual file name is stored immedi-
+ *  ately after the archive header.  The content of the
+ *  archive member follows the file name.  The ar_size
+ *  field of the header (see below) will then hold the
+ *  sum of the size of the file name and the size of
+ *  the member.
+ * /pre
+ *
+ * @since Apache Commons Compress 1.3
+ */
+private static boolean isBSDLongName(String name) {
+return name.startsWith(BSD_LONGNAME_PREFIX)
+ name.length()  BSD_LONGNAME_PREFIX_LEN;
+}
+
+/**
+ * Reads the real name from the current stream assuming the very
+ * first bytes to be read are the real file name.
+ *
+ * @see #isBSDLongName
+ */
+private String getBSDLongName(String bsdLongName) throws IOException {
+int nameLen =
+Integer.parseInt(bsdLongName.substring(BSD_LONGNAME_PREFIX_LEN));
+byte[] name = new byte[nameLen];
+int read = 0, readNow = 0;
+while ((readNow = input.read(name, read, nameLen - read)) = 0) {
+read += readNow;
+count(readNow);
+if (read == nameLen) {
+break;
+}
+}
+  

svn commit: r1154895 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java

2011-08-08 Thread bodewig
Author: bodewig
Date: Mon Aug  8 09:49:08 2011
New Revision: 1154895

URL: http://svn.apache.org/viewvc?rev=1154895view=rev
Log:
small refactoring of long filename support in AR input stream

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=1154895r1=1154894r2=1154895view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 Mon Aug  8 09:49:08 2011
@@ -138,26 +138,18 @@ public class ArArchiveInputStream extend
 
 entryOffset = offset;
 
-//GNU ar stores multiple extended filenames in the data section of a 
file with the name //, this record is referred to by future headers. A header 
references an extended filename by storing a / followed by a decimal offset 
to the start of the filename in the extended filename data section. The format 
of this // file itself is simply a list of the long filenames, each separated 
by one or more LF characters. Note that the decimal offsets are number of 
characters, not line or string number within the // file.
-//
 //GNU ar uses a '/' to mark the end of the filename; this allows for 
the use of spaces without the use of an extended filename.
 
 // entry name is stored as ASCII string
 String temp = ArchiveUtils.toAsciiString(name).trim();
 long len = asLong(length);
 
-if (temp.equals(//)){ // GNU extended filenames entry
-int bufflen = asInt(length); // Assume length will fit in an int
-namebuffer = new byte[bufflen];
-int read = read(namebuffer, 0, bufflen);
-if (read != bufflen){
-throw new IOException(Failed to read complete // record: 
expected=+bufflen+ read=+read);
-}
-currentEntry = new ArArchiveEntry(temp, bufflen);
+if (isGNUStringTable(temp)) { // GNU extended filenames entry
+currentEntry = readGNUStringTable(length);
 return getNextArEntry();
 } else if (temp.endsWith(/)) { // GNU terminator
 temp = temp.substring(0, temp.length() - 1);
-} else if (temp.matches(^/\\d+)) {// GNU long filename ref.
+} else if (isGNULongName(temp)) {
 int offset = Integer.parseInt(temp.substring(1));// get the offset
 temp = getExtendedName(offset); // convert to the long name
 } else if (isBSDLongName(temp)) {
@@ -315,6 +307,8 @@ public class ArArchiveInputStream extend
 private static final String BSD_LONGNAME_PREFIX = #1/;
 private static final int BSD_LONGNAME_PREFIX_LEN =
 BSD_LONGNAME_PREFIX.length();
+private static final String BSD_LONGNAME_PATTERN =
+^ + BSD_LONGNAME_PREFIX + \\d+;
 
 /**
  * Does the name look like it is a long name (or a name containing
@@ -339,8 +333,7 @@ public class ArArchiveInputStream extend
  * @since Apache Commons Compress 1.3
  */
 private static boolean isBSDLongName(String name) {
-return name.startsWith(BSD_LONGNAME_PREFIX)
- name.length()  BSD_LONGNAME_PREFIX_LEN;
+return name != null  name.matches(BSD_LONGNAME_PATTERN);
 }
 
 /**
@@ -348,6 +341,8 @@ public class ArArchiveInputStream extend
  * first bytes to be read are the real file name.
  *
  * @see #isBSDLongName
+ *
+ * @since Apache Commons Compress 1.3
  */
 private String getBSDLongName(String bsdLongName) throws IOException {
 int nameLen =
@@ -366,4 +361,55 @@ public class ArArchiveInputStream extend
 }
 return ArchiveUtils.toAsciiString(name);
 }
+
+private static final String GNU_STRING_TABLE_NAME = //;
+
+/**
+ * Is this the name of the Archive String Table as used by
+ * SVR4/GNU to store long file names?
+ *
+ * pGNU ar stores multiple extended filenames in the data section
+ * of a file with the name //, this record is referred to by
+ * future headers./p
+ *
+ * pA header references an extended filename by storing a /
+ * followed by a decimal offset to the start of the filename in
+ * the extended filename data section./p
+ * 
+ * pThe format of the // file itself is simply a list of the
+ * long filenames, each separated by one or more LF
+ * characters. Note that the decimal offsets are number of
+ * characters, not line or string number within the // file./p
+ */
+private static boolean 

svn commit: r1154920 - in /commons/sandbox/runtime/trunk: ./ src/main/java/org/apache/commons/runtime/net/ src/main/native/os/win32/ src/main/test/org/apache/commons/runtime/

2011-08-08 Thread mturk
Author: mturk
Date: Mon Aug  8 11:26:12 2011
New Revision: 1154920

URL: http://svn.apache.org/viewvc?rev=1154920view=rev
Log:
Add simple IPC test case and some fixes to make it work

Added:

commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestIpc.java
   (with props)
Modified:
commons/sandbox/runtime/trunk/build.xml

commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IpcDescriptor.java

commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IpcServerEndpoint.java
commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/init.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/semaphore.c

Modified: commons/sandbox/runtime/trunk/build.xml
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/build.xml?rev=1154920r1=1154919r2=1154920view=diff
==
--- commons/sandbox/runtime/trunk/build.xml (original)
+++ commons/sandbox/runtime/trunk/build.xml Mon Aug  8 11:26:12 2011
@@ -430,6 +430,17 @@ The Apache Software Foundation (http://w
 /sequential
 /parallel
 /target
+target name=testipcs depends=tests
+parallel
+sequential
+runtest groups=init,ipcs.parent name=ipcs.parent/
+/sequential
+sequential
+sleep milliseconds=100 /
+runtest groups=init,ipcs.child name=ipcs.child/
+/sequential
+/parallel
+/target
 
 !-- === 
--
 !-- Run Example 
--

Modified: 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IpcDescriptor.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IpcDescriptor.java?rev=1154920r1=1154919r2=1154920view=diff
==
--- 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IpcDescriptor.java
 (original)
+++ 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IpcDescriptor.java
 Mon Aug  8 11:26:12 2011
@@ -34,7 +34,7 @@ final class IpcDescriptor extends Descri
 {
 
 private static native int close0(long fd);
-private static native longcreate0(int flags)
+private static native longcreate0()
 throws IOException;
 private static native longsocket0(int type, boolean blocking)
 throws IOException;
@@ -60,31 +60,25 @@ final class IpcDescriptor extends Descri
 closed  = false;
 }
 
-public void create(AddressFamily af, SocketType type)
-throws IOException
-{
-create(af, type, true);
-}
-
-public void create(AddressFamily af, SocketType type, boolean blocking)
+public void create()
 throws IOException
 {
 if (valid())
 close0(fd);
-fd = socket0(type.valueOf(), blocking);
+fd = create0();
 closed = false;
 }
 
 public void create(SocketType type)
 throws IOException
 {
-create(type, false);
+create(type, true);
 }
 
 public void create(SocketType type, boolean blocking)
 throws IOException
 {
-this.fd = create0(0);
+this.fd = socket0(type.valueOf(), blocking);
 closed  = false;
 }
 

Modified: 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IpcServerEndpoint.java
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IpcServerEndpoint.java?rev=1154920r1=1154919r2=1154920view=diff
==
--- 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IpcServerEndpoint.java
 (original)
+++ 
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IpcServerEndpoint.java
 Mon Aug  8 11:26:12 2011
@@ -164,7 +164,7 @@ public class IpcServerEndpoint extends S
 if (bound)
 throw new IOException(Local.sm.get(endpoint.EBOUND));
 if (sd.closed())
-sd.create(SocketType.STREAM, blocking);
+sd.create();
 if (backlog == 0)
 backlog = LISTEN_BACKLOG;
 int rc = bind0(sd.fd(), endpoint.sockaddr(), backlog);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h?rev=1154920r1=1154919r2=1154920view=diff
==
--- 

svn commit: r1154928 - in /commons/proper/compress/trunk/src: changes/ main/java/org/apache/commons/compress/archivers/ar/ site/xdoc/ test/java/org/apache/commons/compress/archivers/ar/

2011-08-08 Thread bodewig
Author: bodewig
Date: Mon Aug  8 11:39:41 2011
New Revision: 1154928

URL: http://svn.apache.org/viewvc?rev=1154928view=rev
Log:
support writing of BSD dialect AR archives with long file names.  COMPRESS-144

Added:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java
   (with props)
Modified:
commons/proper/compress/trunk/src/changes/changes.xml

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
commons/proper/compress/trunk/src/site/xdoc/examples.xml

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1154928r1=1154927r2=1154928view=diff
==
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Mon Aug  8 11:39:41 
2011
@@ -46,6 +46,10 @@ The action type attribute can be add,u
   body
 release version=1.3 date=unreleased
  description=Release 1.3 - API compatible to 1.2 but requires 
Java5 at runtime
+  action issue=COMPRESS-144 type=update date=2011-08-08
+The AR package now supports the BSD dialect of storing file
+names longer than 16 chars (both reading and writing).
+  /action 
   action type=fix date=2011-08-08
 BZip2CompressorInputStream's getBytesRead method always
 returned 0.

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=1154928r1=1154927r2=1154928view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 Mon Aug  8 11:39:41 2011
@@ -304,7 +304,7 @@ public class ArArchiveInputStream extend
 return true;
 }
 
-private static final String BSD_LONGNAME_PREFIX = #1/;
+static final String BSD_LONGNAME_PREFIX = #1/;
 private static final int BSD_LONGNAME_PREFIX_LEN =
 BSD_LONGNAME_PREFIX.length();
 private static final String BSD_LONGNAME_PATTERN =

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java?rev=1154928r1=1154927r2=1154928view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
 Mon Aug  8 11:39:41 2011
@@ -32,13 +32,19 @@ import org.apache.commons.compress.utils
  * @NotThreadSafe
  */
 public class ArArchiveOutputStream extends ArchiveOutputStream {
+/** Fail if a long file name is required in the archive. */
+public static final int LONGFILE_ERROR = 0;
+
+/** BSD ar extensions are used to store long file names in the archive. */
+public static final int LONGFILE_BSD = 1;
 
 private final OutputStream out;
 private long archiveOffset = 0;
 private long entryOffset = 0;
 private ArArchiveEntry prevEntry;
 private boolean haveUnclosedEntry = false;
-
+private int longFileMode = LONGFILE_ERROR;
+
 /** indicates if this archive is finished */
 private boolean finished = false;
 
@@ -46,6 +52,18 @@ public class ArArchiveOutputStream exten
 this.out = pOut;
 }
 
+/**
+ * Set the long file mode.
+ * This can be LONGFILE_ERROR(0) or LONGFILE_BSD(1).
+ * This specifies the treatment of long file names (names = 16).
+ * Default is LONGFILE_ERROR.
+ * @param longFileMode the mode to use
+ * @since Apache Commons Compress 1.3
+ */
+public void setLongFileMode(int longFileMode) {
+this.longFileMode = longFileMode;
+}
+
 private long writeArchiveHeader() throws IOException {
 byte [] header = ArchiveUtils.toAsciiBytes(ArArchiveEntry.HEADER);
 out.write(header);
@@ -74,7 +92,7 @@ public class ArArchiveOutputStream exten
 if(finished) {
 throw new IOException(Stream has already been finished);
 }
-
+
 ArArchiveEntry pArEntry = (ArArchiveEntry)pEntry;
   

svn commit: r1154949 - /commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java

2011-08-08 Thread ggregory
Author: ggregory
Date: Mon Aug  8 13:06:51 2011
New Revision: 1154949

URL: http://svn.apache.org/viewvc?rev=1154949view=rev
Log:
[CODEC-125] Implement a Beider-Morse phonetic matching codec. No need to create 
7000+ of the same object on startup and keep it around.

Modified:

commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java

Modified: 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java?rev=1154949r1=1154948r2=1154949view=diff
==
--- 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java
 (original)
+++ 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java
 Mon Aug  8 13:06:51 2011
@@ -229,6 +229,16 @@ public class Rule {
 
 }
 
+private static class AllStringsRMatcher implements RPattern {
+
+private static AllStringsRMatcher INSTANCE = new AllStringsRMatcher();
+
+public RMatcher matcher(CharSequence input) {
+return TrueRMatcher.INSTANCE;
+}
+
+}
+
 /**
  * A minimal wrapper around the functionality of Pattern that we use, to 
allow for alternate implementations.
  */
@@ -511,11 +521,7 @@ public class Rule {
 }
 } else if ((startsWith || endsWith)  content.length() == 0) {
 // matches every string
-return new RPattern() {
-public RMatcher matcher(CharSequence input) {
-return TrueRMatcher.INSTANCE;
-}
-};
+return AllStringsRMatcher.INSTANCE;
 } else if (startsWith) {
 // matches from start
 return new RPattern() {




svn commit: r1154972 - in /commons/sandbox/runtime/trunk/src/main: native/os/win32/arch_ipcs.h native/os/win32/ipcsock.c test/org/apache/commons/runtime/TestIpc.java

2011-08-08 Thread mturk
Author: mturk
Date: Mon Aug  8 14:26:24 2011
New Revision: 1154972

URL: http://svn.apache.org/viewvc?rev=1154972view=rev
Log:
Axe debug printf's

Modified:
commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h
commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c

commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestIpc.java

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h?rev=1154972r1=1154971r2=1154972view=diff
==
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h 
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_ipcs.h Mon Aug  
8 14:26:24 2011
@@ -407,6 +407,15 @@ int
 AcrIpcRead(LPIPCSOCK pSocket, void *pData, int nSize);
 
 /**
+ * Initialize IPC system.
+ *
+ * @notice This function must be called before any other
+ * IPC function.
+ */ 
+int
+AcrIpcInit(void);
+
+/**
  * Write the data.
  * @param pSocket the socket to use.
  * @param pData input data buffer

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c?rev=1154972r1=1154971r2=1154972view=diff
==
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/ipcsock.c Mon Aug  8 
14:26:24 2011
@@ -145,10 +145,10 @@ AcquireMutex(HANDLE hMutex)
 
 int AcrIpcInit()
 {
-static int inited = 0;
+static volatile long inited = 0;
 
-if (inited++)
-return WSAEALREADY;
+if (InterlockedExchangeAdd(inited, 1) != 0)
+return 0;
 /* Catch some common immutable variables
  * which won't change for the process life-time.
  */
@@ -330,7 +330,8 @@ AcrIpcServerClose(LPIPCSERVER sp)
 if (sp-nConnections != 0) {
 /* Should never happen [tm]
  */
-printf([server] Found %d active. Should be zero\n, sp-nConnections);
+fprintf(stderr, [server] Found %d active. Should be zero\n, 
sp-nConnections);
+fflush(stderr);
 }
 SAFE_CLOSE_HANDLE(sp-hAcceptSema);
 SAFE_CLOSE_HANDLE(sp-hAcceptSync);
@@ -423,7 +424,6 @@ AcrIoBufMap(HANDLE hMap, DWORD dwSize)
 if (MapViewOfFileEx(hMap, FILE_MAP_ALL_ACCESS, 0, 0, dwSize, pBase + 
dwSize) != 0)
 return pBase; /* Mapped two in a row */
 UnmapViewOfFile(pBase);
-printf([debug] Mapping again %d\n, nAttempts);
 /* Yield the processor */
 SwitchToThread();
 pBase = VirtualAlloc(0, 2 * dwSize, MEM_RESERVE, PAGE_READWRITE);
@@ -504,10 +504,8 @@ retry:
 return 0;
 }
 again:
-printf([server] Waiting on accept ...\n);
 /* Wait for a client connect */
 ws = WaitForSingleObject(sp-hAcceptSync, nTimeout);
-printf([server] Waiting on accept : %d\n, ws);
 switch (ws) {
 case WAIT_OBJECT_0:
 /* Client signaled there is a new
@@ -522,7 +520,6 @@ again:
 case WAIT_TIMEOUT:
 ApcIpcServerUnref(sp);
 /* Timeout */
-printf([server] accept timeout\n);
 if (nTimeout == 0)
 SetLastError(WSAEWOULDBLOCK);
 else
@@ -536,7 +533,6 @@ again:
 default:
 ApcIpcServerUnref(sp);
 /* Error!  */
-printf([server] illegal accept wait result\n);
 SetLastError(rc);
 return 0;
 break;
@@ -548,7 +544,6 @@ again:
  */
 if ((nTimeout == -1) || ((nTimeup  0)  (nTimeup  
GetCurrentMilliseconds( {
 ReleaseMutex(sp-hAcceptLock);
-printf([server] Retrying ...\n);
 goto again;
 }
 ApcIpcServerUnref(sp);
@@ -565,7 +560,6 @@ again:
 ReleaseMutex(sp-hAcceptLock);
 
 a = sp-s-a + i;
-printf([server] Processing accept for client %d:%d\n, i, a-nStatus);
 hClientMeta  = DW2H(a-nClientMeta);
 if (a-nStatus == 0 || hClientMeta == 0) {
 InterlockedExchange(a-nStatus, WSAENOTSOCK);
@@ -573,7 +567,6 @@ again:
  * to the caller?
  */
 if ((nTimeout == -1) || ((nTimeup  0)  (nTimeup  
GetCurrentMilliseconds( {
-printf([server] Restarting ...\n);
 goto retry;
 }
 rc = WSAETIMEDOUT;
@@ -737,22 +730,16 @@ again:
 case WAIT_OBJECT_1:
 case WAIT_ABANDONED_1:
 ReleaseMutex(cp-rp-hProcessLock);
-printf([client] Server died\n);
 rc = WSAECONNREFUSED;
 break;
 case WAIT_TIMEOUT:
-printf([client] Timeout!\n);
 if (nTimeout == 0)
 rc = WSAEWOULDBLOCK;
 else
 rc 

svn commit: r1155027 - /commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java

2011-08-08 Thread ggregory
Author: ggregory
Date: Mon Aug  8 17:49:50 2011
New Revision: 1155027

URL: http://svn.apache.org/viewvc?rev=1155027view=rev
Log:
Renamed testSpeedCheck to testSpeedCheckRandom. Made testSpeedCheck 
deterministic.

Modified:

commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java

Modified: 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java?rev=1155027r1=1155026r2=1155027view=diff
==
--- 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
 (original)
+++ 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
 Mon Aug  8 17:49:50 2011
@@ -34,6 +34,8 @@ import org.junit.Test;
  * @since 2.0
  */
 public class BeiderMorseEncoderTest extends StringEncoderAbstractTest {
+private static final char[] TEST_CHARS = new char[] { 'a', 'b', 'c', 'd', 
'e', 'f', 'g', 'h', 'o', 'u' };
+
 private void assertNotEmpty(BeiderMorseEncoder bmpm, final String value) 
throws EncoderException {
 Assert.assertFalse(value, bmpm.encode(value).equals());
 }
@@ -164,23 +166,32 @@ public class BeiderMorseEncoderTest exte
 
 /**
  * Runs between 1.1 and 13 seconds at length 40 for me (Gary Gregory, 
2011/08/06)
- *  
+ * 
  * @throws EncoderException
  */
 @Test(/* timeout = 2L */)
-public void testSpeedCheck() throws EncoderException {
-char[] chars = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 
'o', 'u' };
-BeiderMorseEncoder bmpm = createGenericApproxEncoder();
+public void testSpeedCheckRandom() throws EncoderException {
+BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
 StringBuffer stringBuffer = new StringBuffer();
 Random rand = new Random();
-stringBuffer.append(chars[rand.nextInt(chars.length)]);
-long start;
+stringBuffer.append(TEST_CHARS[rand.nextInt(TEST_CHARS.length)]);
 for (int i = 0; i  40; i++) {
-start = System.currentTimeMillis();
-// System.out.println(i +  String to encode: + 
stringBuffer.toString());
 bmpm.encode(stringBuffer.toString());
-stringBuffer.append(chars[rand.nextInt(chars.length)]);
-// System.out.println(i +  Elapsed time in ms: + 
(System.currentTimeMillis() - start));
+stringBuffer.append(TEST_CHARS[rand.nextInt(TEST_CHARS.length)]);
+}
+}
+
+@Test(/* timeout = 2L */)
+public void testSpeedCheck() throws EncoderException {
+BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
+StringBuffer stringBuffer = new StringBuffer();
+stringBuffer.append(TEST_CHARS[0]);
+for (int i = 0, j = 1; i  40; i++, j++) {
+if (j == TEST_CHARS.length) {
+j = 0;
+}
+bmpm.encode(stringBuffer.toString());
+stringBuffer.append(TEST_CHARS[j]);
 }
 }
 }




svn commit: r1155040 - /commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java

2011-08-08 Thread ggregory
Author: ggregory
Date: Mon Aug  8 18:25:34 2011
New Revision: 1155040

URL: http://svn.apache.org/viewvc?rev=1155040view=rev
Log:
Add testSpeedCheckAZ

Modified:

commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java

Modified: 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java?rev=1155040r1=1155039r2=1155040view=diff
==
--- 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
 (original)
+++ 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java
 Mon Aug  8 18:25:34 2011
@@ -165,23 +165,11 @@ public class BeiderMorseEncoderTest exte
 }
 
 /**
- * Runs between 1.1 and 13 seconds at length 40 for me (Gary Gregory, 
2011/08/06)
+ * (Un)luckily, the worse performing test because of the data in {@link 
TEST_CHARS}
  * 
  * @throws EncoderException
  */
 @Test(/* timeout = 2L */)
-public void testSpeedCheckRandom() throws EncoderException {
-BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
-StringBuffer stringBuffer = new StringBuffer();
-Random rand = new Random();
-stringBuffer.append(TEST_CHARS[rand.nextInt(TEST_CHARS.length)]);
-for (int i = 0; i  40; i++) {
-bmpm.encode(stringBuffer.toString());
-stringBuffer.append(TEST_CHARS[rand.nextInt(TEST_CHARS.length)]);
-}
-}
-
-@Test(/* timeout = 2L */)
 public void testSpeedCheck() throws EncoderException {
 BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
 StringBuffer stringBuffer = new StringBuffer();
@@ -194,4 +182,35 @@ public class BeiderMorseEncoderTest exte
 stringBuffer.append(TEST_CHARS[j]);
 }
 }
+
+/**
+ * Another odd performance edge case.
+ * 
+ * @throws EncoderException
+ */
+@Test(/* timeout = 2L */)
+public void testSpeedCheckAZ() throws EncoderException {
+BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
+String phrase = abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz;
+for (int i = 1; i = phrase.length(); i++) {
+bmpm.encode(phrase.subSequence(0, i));
+}
+}
+
+/**
+ * Runs between 1.6 and 13 seconds at length 40 for me (Gary Gregory, 
2011/08/06)
+ * 
+ * @throws EncoderException
+ */
+@Test(/* timeout = 2L */)
+public void testSpeedCheckRandom() throws EncoderException {
+BeiderMorseEncoder bmpm = this.createGenericApproxEncoder();
+StringBuffer stringBuffer = new StringBuffer();
+Random rand = new Random();
+stringBuffer.append(TEST_CHARS[rand.nextInt(TEST_CHARS.length)]);
+for (int i = 0; i  40; i++) {
+bmpm.encode(stringBuffer.toString());
+stringBuffer.append(TEST_CHARS[rand.nextInt(TEST_CHARS.length)]);
+}
+}
 }




svn commit: r1155135 - in /commons/proper/codec/trunk/src: java/org/apache/commons/codec/language/bm/ test/org/apache/commons/codec/language/bm/

2011-08-08 Thread ggregory
Author: ggregory
Date: Mon Aug  8 22:47:24 2011
New Revision: 1155135

URL: http://svn.apache.org/viewvc?rev=1155135view=rev
Log:
[CODEC-125] Implement a Beider-Morse phonetic matching codec. Applied patch 
https://issues.apache.org/jira/secure/attachment/12489755/fightingMemoryChurn.patch

Modified:

commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Lang.java

commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Languages.java

commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/NameType.java

commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/PhoneticEngine.java

commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java

commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/BeiderMorseEncoderTest.java

commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java

Modified: 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Lang.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Lang.java?rev=1155135r1=1155134r2=1155135view=diff
==
--- 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Lang.java
 (original)
+++ 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Lang.java
 Mon Aug  8 22:47:24 2011
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.EnumMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Scanner;
 import java.util.Set;
@@ -71,7 +72,7 @@ import java.util.regex.Pattern;
  */
 public class Lang {
 
-private static class LangRule {
+private static final class LangRule {
 private final boolean acceptOnMatch;
 private final SetString languages;
 private final Pattern pattern;
@@ -199,7 +200,7 @@ public class Lang {
  */
 public String guessLanguage(String text) {
 Languages.LanguageSet ls = guessLanguages(text);
-return ls.isSingleton() ? ls.getAny() : Languages.ANY; 
+return ls.isSingleton() ? ls.getAny() : Languages.ANY;
 }
 
 /**
@@ -210,7 +211,7 @@ public class Lang {
  * @return a Set of Strings of language names that are potential matches 
for the input word
  */
 public Languages.LanguageSet guessLanguages(String input) {
-String text = input.toLowerCase(); // todo: locale?
+String text = input.toLowerCase(Locale.ENGLISH);
 // System.out.println(Testing text: ' + text + ');
 
 SetString langs = new HashSetString(this.languages.getLanguages());

Modified: 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Languages.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Languages.java?rev=1155135r1=1155134r2=1155135view=diff
==
--- 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Languages.java
 (original)
+++ 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Languages.java
 Mon Aug  8 22:47:24 2011
@@ -58,9 +58,9 @@ public class Languages {
  * A set of languages.
  */
 public static abstract class LanguageSet {
-
+
 public static LanguageSet from(SetString langs) {
-return langs.isEmpty() ? NO_LANGUAGES : new SomeLanguages(langs);  
+return langs.isEmpty() ? NO_LANGUAGES : new SomeLanguages(langs);
 }
 
 public abstract boolean contains(String language);
@@ -77,7 +77,7 @@ public class Languages {
 /**
  * Some languages, explicitly enumerated.
  */
-public static class SomeLanguages extends LanguageSet {
+public static final class SomeLanguages extends LanguageSet {
 private final SetString languages;
 
 private SomeLanguages(SetString languages) {
@@ -116,9 +116,13 @@ public class Languages {
 return this;
 } else {
 SomeLanguages sl = (SomeLanguages) other;
-SetString ls = new HashSetString(this.languages);
-ls.retainAll(sl.languages);
-return from(ls);
+if (sl.languages.containsAll(languages)) {
+return this;
+} else {
+SetString ls = new HashSetString(this.languages);
+ls.retainAll(sl.languages);
+return from(ls);
+}
 }
 }
 

Modified: 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/NameType.java
URL: 

svn commit: r1155182 - in /commons/proper/codec/trunk/src: java/org/apache/commons/codec/language/bm/PhoneticEngine.java java/org/apache/commons/codec/language/bm/Rule.java test/org/apache/commons/cod

2011-08-08 Thread ggregory
Author: ggregory
Date: Tue Aug  9 01:16:09 2011
New Revision: 1155182

URL: http://svn.apache.org/viewvc?rev=1155182view=rev
Log:
[CODEC-125] Implement a Beider-Morse phonetic matching codec. Applied patch 
https://issues.apache.org/jira/secure/attachment/12489767/comparator.patch

Modified:

commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/PhoneticEngine.java

commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java

commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java

Modified: 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/PhoneticEngine.java?rev=1155182r1=1155181r2=1155182view=diff
==
--- 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
 (original)
+++ 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
 Tue Aug  9 01:16:09 2011
@@ -251,7 +251,7 @@ public class PhoneticEngine {
 return phonemeBuilder;
 }
 
-SetRule.Phoneme phonemes = new TreeSetRule.Phoneme();
+SetRule.Phoneme phonemes = new 
TreeSetRule.Phoneme(Rule.Phoneme.COMPARATOR);
 
 for (Rule.Phoneme phoneme : phonemeBuilder.getPhonemes()) {
 PhonemeBuilder subBuilder = 
PhonemeBuilder.empty(phoneme.getLanguages());

Modified: 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java?rev=1155182r1=1155181r2=1155182view=diff
==
--- 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java
 (original)
+++ 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java
 Tue Aug  9 01:16:09 2011
@@ -21,6 +21,7 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -80,7 +81,26 @@ import java.util.regex.Pattern;
  */
 public class Rule {
 
-public static final class Phoneme implements PhonemeExpr, 
ComparablePhoneme {
+public static final class Phoneme implements PhonemeExpr {
+public static final ComparatorPhoneme COMPARATOR = new 
ComparatorPhoneme() {
+public int compare(Phoneme o1, Phoneme o2) {
+for (int i = 0; i  o1.phonemeText.length(); i++) {
+if (i = o2.phonemeText.length()) {
+return +1;
+}
+int c = o1.phonemeText.charAt(i) - 
o2.phonemeText.charAt(i);
+if (c != 0) {
+return c;
+}
+}
+
+if (o1.phonemeText.length()  o2.phonemeText.length()) {
+return -1;
+}
+
+return 0;
+}
+};
 
 private final CharSequence phonemeText;
 private final Languages.LanguageSet languages;
@@ -94,24 +114,6 @@ public class Rule {
 return new Phoneme(this.phonemeText.toString() + str.toString(), 
this.languages);
 }
 
-public int compareTo(Phoneme o) {
-for (int i = 0; i  phonemeText.length(); i++) {
-if (i = o.phonemeText.length()) {
-return +1;
-}
-int c = phonemeText.charAt(i) - o.phonemeText.charAt(i);
-if (c != 0) {
-return c;
-}
-}
-
-if (phonemeText.length()  o.phonemeText.length()) {
-return -1;
-}
-
-return 0;
-}
-
 public Languages.LanguageSet getLanguages() {
 return this.languages;
 }

Modified: 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java?rev=1155182r1=1155181r2=1155182view=diff
==
--- 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java
 (original)
+++ 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java
 Tue Aug  9 01:16:09 2011
@@ -63,7 +63,7 @@ public class RuleTest {
 for (Rule.Phoneme[] phs : makePhonemes()) {
 for (int i = 0; i  phs.length; i++) {
 for (int j = i + 1; j  phs.length; j++) {
-int c = phs[i].compareTo(phs[j]);
+ 

svn commit: r1155183 - /commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java

2011-08-08 Thread ggregory
Author: ggregory
Date: Tue Aug  9 01:17:26 2011
New Revision: 1155183

URL: http://svn.apache.org/viewvc?rev=1155183view=rev
Log:
Prefix @Test method names with test.

Modified:

commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java

Modified: 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java?rev=1155183r1=1155182r2=1155183view=diff
==
--- 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java
 (original)
+++ 
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/bm/RuleTest.java
 Tue Aug  9 01:17:26 2011
@@ -59,7 +59,7 @@ public class RuleTest {
 }
 
 @Test
-public void phonemeComparedToLaterIsNegative() {
+public void testPhonemeComparedToLaterIsNegative() {
 for (Rule.Phoneme[] phs : makePhonemes()) {
 for (int i = 0; i  phs.length; i++) {
 for (int j = i + 1; j  phs.length; j++) {
@@ -73,7 +73,7 @@ public class RuleTest {
 }
 
 @Test
-public void phonemeComparedToSelfIsZero() {
+public void testPhonemeComparedToSelfIsZero() {
 for (Rule.Phoneme[] phs : makePhonemes()) {
 for (Rule.Phoneme ph : phs) {
 assertEquals(Phoneme compared to itself should be zero:  + 
ph.getPhonemeText(), 0,
@@ -83,7 +83,7 @@ public class RuleTest {
 }
 
 @Test
-public void subSequenceWorks() {
+public void testSubSequenceWorks() {
 // AppendableCharSequence is private to Rule. We can only make it 
through a Phoneme.
 
 Rule.Phoneme a = new Rule.Phoneme(a, null);