commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1165359 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/User.java java/org/apache/commons/runtime/UserIteratorImpl.java native/os/unix/user.c
Date Mon, 05 Sep 2011 16:52:03 GMT
Author: mturk
Date: Mon Sep  5 16:52:03 2011
New Revision: 1165359

URL: http://svn.apache.org/viewvc?rev=1165359&view=rev
Log:
Use HashSet instead ArrayList for logged users enum

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/User.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/UserIteratorImpl.java
    commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/User.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/User.java?rev=1165359&r1=1165358&r2=1165359&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/User.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/User.java Mon Sep
 5 16:52:03 2011
@@ -17,7 +17,8 @@
 package org.apache.commons.runtime;
 
 import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Iterator;
 
 /**
  * User Information.
@@ -56,7 +57,7 @@ public final class User
     private static native boolean equals0(long a, long b);
     private static native void    enum0(ArrayList<String> uset)
         throws SystemException, SecurityException;
-    private static native void    enum1(ArrayList<String> uset)
+    private static native void    enum1(HashSet<String> uset)
         throws SystemException, SecurityException;
 
     /**
@@ -134,7 +135,7 @@ public final class User
         synchronized(lock) {
             ArrayList<String> users = new ArrayList<String>();
             enum0(users);
-            iter = new UserIteratorImpl(users);
+            iter = new UserIteratorImpl(users.iterator());
         }
         return iter;
     }
@@ -153,9 +154,9 @@ public final class User
     {
         UserIterator iter;
         synchronized(lock) {
-            ArrayList<String> users = new ArrayList<String>();
+            HashSet<String> users = new HashSet<String>();
             enum1(users);
-            iter = new UserIteratorImpl(users);
+            iter = new UserIteratorImpl(users.iterator());
         }
         return iter;
     }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/UserIteratorImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/UserIteratorImpl.java?rev=1165359&r1=1165358&r2=1165359&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/UserIteratorImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/UserIteratorImpl.java
Mon Sep  5 16:52:03 2011
@@ -17,8 +17,7 @@
 package org.apache.commons.runtime;
 
 import java.util.NoSuchElementException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Iterator;
 
 /**
  * User Iterator implementation
@@ -29,28 +28,24 @@ import java.util.List;
 class UserIteratorImpl extends UserIterator
 {
 
-    private ArrayList<String> users;
+    private Iterator<String> users;
     private int pos = 0;
 
-    protected UserIteratorImpl(ArrayList<String> users)
+    protected UserIteratorImpl(Iterator<String> users)
     {
         this.users = users;
     }
 
     public boolean hasNext()
     {
-        if (pos < users.size()) {
-            return true;
-        }
-        else
-            return false;
+        return users.hasNext();
     }
 
     public User next()
         throws NoSuchElementException
     {
-        if (hasNext())
-            return User.get(users.get(pos++));
+        if (users.hasNext())
+            return User.get(users.next());
         else
             throw new NoSuchElementException();
     }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c?rev=1165359&r1=1165358&r2=1165359&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c Mon Sep  5 16:52:03 2011
@@ -337,7 +337,7 @@ ACR_JNI_EXPORT(void, User, enum0)(JNI_ST
     endpwent();
 }
 
-ACR_JNI_EXPORT(void, User, enum1)(JNI_STDARGS, jobject ua)
+ACR_JNI_EXPORT(void, User, enum1)(JNI_STDARGS, jobject us)
 {
     struct utmpx *ut;
     int n = 0;
@@ -363,13 +363,11 @@ ACR_JNI_EXPORT(void, User, enum1)(JNI_ST
                 s = AcrNewJavaStringA(env, ut->ut_user);
                 if (s == 0)
                     break;
-                if (AcrArrayListContains(env, ua, s) == 0) {
-                    AcrArrayListAdd(env, ua, s);
-                    n++;
-                }
+                AcrHashSetAdd(env, us, s);
                 if ((*env)->ExceptionCheck(env))
                     break;
                 (*env)->DeleteLocalRef(env, s);
+                n++;
             }
         }
     }



Mime
View raw message