harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r546363 - in /harmony/enhanced/classlib/branches/java6/modules: luni/src/main/java/java/util/ luni/src/test/java/tests/api/java/util/ sql/src/main/java/javax/sql/rowset/serial/
Date Tue, 12 Jun 2007 03:21:38 GMT
Author: pyang
Date: Mon Jun 11 20:21:37 2007
New Revision: 546363

URL: http://svn.apache.org/viewvc?view=rev&rev=546363
Log:
Merge updates from classlib trunk@546205 since r545915

Modified:
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/LinkedHashMap.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/ListResourceBundle.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Observable.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java
    harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/tests/api/java/util/VectorTest.java
    harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/LinkedHashMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/LinkedHashMap.java?view=diff&rev=546363&r1=546362&r2=546363
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/LinkedHashMap.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/LinkedHashMap.java
Mon Jun 11 20:21:37 2007
@@ -221,6 +221,35 @@
             return entry;
         }
     }
+    
+    /**
+     * Searches this map for the specified value.
+     * 
+     * @param value
+     *            the object to search for
+     * @return true if <code>value</code> is a value of this HashMap, false
+     *         otherwise
+     */
+    @Override
+    public boolean containsValue(Object value) {
+        LinkedHashMapEntry<K, V> entry = head;
+        if (null == value) {
+            while (null != entry) {
+                if (null == entry.value) {
+                    return true;
+                }
+                entry = entry.chainForward;
+            }
+        } else {
+            while (null != entry) {
+                if (value.equals(entry.value)) {
+                    return true;
+                }
+                entry = entry.chainForward;
+            }
+        }
+        return false;
+    }
 
     /**
      * Create a new element array

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/ListResourceBundle.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/ListResourceBundle.java?view=diff&rev=546363&r1=546362&r2=546363
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/ListResourceBundle.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/ListResourceBundle.java
Mon Jun 11 20:21:37 2007
@@ -17,7 +17,6 @@
 
 package java.util;
 
-
 /**
  * ListResourceBundle is the abstract superclass of classes which provide
  * resources by implementing the <code>getContents()</code> method to return
@@ -27,103 +26,116 @@
  * @since 1.1
  */
 public abstract class ListResourceBundle extends ResourceBundle {
-	Hashtable<String, Object> table;
+    HashMap<String, Object> table;
 
-	/**
-	 * Constructs a new instance of this class.
-	 */
-	public ListResourceBundle() {
-		super();
-	}
-
-	/**
-	 * Answers an Object array which contains the resources of this
-	 * ListResourceBundle. Each element in the array is an array of two
-	 * elements, the first is the resource key and the second is the resource.
-	 * 
-	 * @return a Object array containing the resources
-	 */
-	protected abstract Object[][] getContents();
-
-	/**
-	 * Answers the names of the resources contained in this ListResourceBundle.
-	 * 
-	 * @return an Enumeration of the resource names
-	 */
-	@Override
+    /**
+     * Constructs a new instance of this class.
+     */
+    public ListResourceBundle() {
+        super();
+    }
+
+    /**
+     * Answers an Object array which contains the resources of this
+     * ListResourceBundle. Each element in the array is an array of two
+     * elements, the first is the resource key and the second is the resource.
+     * 
+     * @return a Object array containing the resources
+     */
+    protected abstract Object[][] getContents();
+
+    /**
+     * Answers the names of the resources contained in this ListResourceBundle.
+     * 
+     * @return an Enumeration of the resource names
+     */
+    @Override
     public Enumeration<String> getKeys() {
-		if (table == null) {
-            initializeTable();
-        }
-		if (parent == null) {
-            return table.keys();
-        }
-		return new Enumeration<String>() {
-			Enumeration<String> local = table.keys();
+        initializeTable();
+        if (parent != null) {
+            return new Enumeration<String>() {
+                Iterator<String> local = table.keySet().iterator();
+
+                Enumeration<String> pEnum = parent.getKeys();
+
+                String nextElement;
+
+                private boolean findNext() {
+                    if (nextElement != null) {
+                        return true;
+                    }
+                    while (pEnum.hasMoreElements()) {
+                        String next = pEnum.nextElement();
+                        if (!table.containsKey(next)) {
+                            nextElement = next;
+                            return true;
+                        }
+                    }
+                    return false;
+                }
 
-			Enumeration<String> pEnum = parent.getKeys();
+                public boolean hasMoreElements() {
+                    if (local.hasNext()) {
+                        return true;
+                    }
+                    return findNext();
+                }
 
-			String nextElement;
+                public String nextElement() {
+                    if (local.hasNext()) {
+                        return local.next();
+                    }
+                    if (findNext()) {
+                        String result = nextElement;
+                        nextElement = null;
+                        return result;
+                    }
+                    // Cause an exception
+                    return pEnum.nextElement();
+                }
+            };
+        } else {
+            return new Enumeration<String>() {
+                Iterator<String> it = table.keySet().iterator();
 
-			private boolean findNext() {
-				if (nextElement != null) {
-                    return true;
-                }
-				while (pEnum.hasMoreElements()) {
-					String next = pEnum.nextElement();
-					if (!table.containsKey(next)) {
-						nextElement = next;
-						return true;
-					}
-				}
-				return false;
-			}
-
-			public boolean hasMoreElements() {
-				if (local.hasMoreElements()) {
-                    return true;
-                }
-				return findNext();
-			}
-
-			public String nextElement() {
-				if (local.hasMoreElements()) {
-                    return local.nextElement();
-                }
-				if (findNext()) {
-					String result = nextElement;
-					nextElement = null;
-					return result;
-				}
-				// Cause an exception
-				return pEnum.nextElement();
-			}
-		};
-	}
-
-	/**
-	 * Answers the named resource from this ResourceBundle, or null if the
-	 * resource is not found.
-	 * 
-	 * @param key
-	 *            the name of the resource
-	 * @return the resource object
-	 */
-	@Override
+                public boolean hasMoreElements() {
+                    return it.hasNext();
+                }
+
+                public String nextElement() {
+                    return it.next();
+                }
+            };
+        }
+    }
+
+    /**
+     * Answers the named resource from this ResourceBundle, or null if the
+     * resource is not found.
+     * 
+     * @param key
+     *            the name of the resource
+     * @return the resource object
+     */
+    @Override
     public final Object handleGetObject(String key) {
-		if (table == null) {
-            initializeTable();
+        initializeTable();
+        if (key == null) {
+            throw new NullPointerException();
         }
-		return table.get(key);
-	}
+        return table.get(key);
+    }
 
-	private synchronized void initializeTable() {
-		if (table == null) {
-			Object[][] contents = getContents();
-			table = new Hashtable<String, Object>(contents.length / 3 * 4 + 3);
-			for (int i = 0; i < contents.length; i++) {
-				table.put((String)contents[i][0], contents[i][1]);
-			}
-		}
-	}
+    private synchronized void initializeTable() {
+        if (table == null) {
+            Object[][] contents = getContents();
+            table = new HashMap<String, Object>(contents.length / 3 * 4 + 3);
+            for (Object[] content : contents) {
+                if (content[0] == null || content[1] == null) {
+                    throw new NullPointerException();
+                }
+                table.put((String) content[0], content[1]);
+            }
+        }
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Observable.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Observable.java?view=diff&rev=546363&r1=546362&r2=546363
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Observable.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Observable.java
Mon Jun 11 20:21:37 2007
@@ -17,117 +17,130 @@
 
 package java.util;
 
-
 /**
  * Observable is used to notify a group of Observer objects when a change
  * occurs.
  */
 public class Observable {
-	
-	Vector<Observer> observers = new Vector<Observer>();
 
-	boolean changed = false;
+    List<Observer> observers = new ArrayList<Observer>();
+
+    boolean changed = false;
+
+    /**
+     * Constructs a new Observable object.
+     */
+    public Observable() {
+        super();
+    }
+
+    /**
+     * Adds the specified Observer to the list of observers.
+     * 
+     * @param observer
+     *            the Observer to add
+     */
+    public void addObserver(Observer observer) {
+        if (observer == null) {
+            throw new NullPointerException();
+        }
+        synchronized (this) {
+            if (!observers.contains(observer))
+                observers.add(observer);
+        }
+    }
+
+    /**
+     * Clears the changed flag for this Observable. After calling
+     * <code>clearChanged()</code>, <code>hasChanged()</code> will
return
+     * false.
+     */
+    protected void clearChanged() {
+        changed = false;
+    }
+
+    /**
+     * Answers the number of Observers in the list of observers.
+     * 
+     * @return the number of observers
+     */
+    public int countObservers() {
+        return observers.size();
+    }
 
-	/**
-	 * Constructs a new Observable object.
-	 */
-	public Observable() {
-		super();
-	}
-
-	/**
-	 * Adds the specified Observer to the list of observers.
-	 * 
-	 * @param observer
-	 *            the Observer to add
-	 */
-	public synchronized void addObserver(Observer observer) {
-		if (observer == null) {
-			throw new NullPointerException();
-		}
-		if (!observers.contains(observer))
-			observers.addElement(observer);
-	}
-
-	/**
-	 * Clears the changed flag for this Observable.  After calling <code>clearChanged()</code>,
<code>hasChanged()</code> will return false.
-	 */
-	protected synchronized void clearChanged() {
-		changed = false;
-	}
-
-	/**
-	 * Answers the number of Observers in the list of observers.
-	 * 
-	 * @return the number of observers
-	 */
-	public synchronized int countObservers() {
-		return observers.size();
-	}
-
-	/**
-	 * Removes the specified Observer from the list of observers.
-	 * 
-	 * @param observer
-	 *            the Observer to remove
-	 */
-	public synchronized void deleteObserver(Observer observer) {
-		observers.removeElement(observer);
-	}
-
-	/**
-	 * Removes all Observers from the list of observers.
-	 */
-	public synchronized void deleteObservers() {
-		observers.setSize(0);
-	}
-
-	/**
-	 * Answers the changed flag for this Observable.
-	 * 
-	 * @return true when the changed flag for this Observable is set, false
-	 *         otherwise
-	 */
-	public synchronized boolean hasChanged() {
-		return changed;
-	}
-
-	/**
-	 * If <code>hasChanged()</code> returns true, calls the <code>update()</code>
method for
-	 * every Observer in the list of observers using null as the argument.
-	 * Afterwards calls <code>clearChanged()</code>.
+    /**
+     * Removes the specified Observer from the list of observers.
+     * 
+     * @param observer
+     *            the Observer to remove
+     */
+    public synchronized void deleteObserver(Observer observer) {
+        observers.remove(observer);
+    }
+
+    /**
+     * Removes all Observers from the list of observers.
+     */
+    public synchronized void deleteObservers() {
+        observers.clear();
+    }
+
+    /**
+     * Answers the changed flag for this Observable.
+     * 
+     * @return true when the changed flag for this Observable is set, false
+     *         otherwise
+     */
+    public boolean hasChanged() {
+        return changed;
+    }
+
+    /**
+     * If <code>hasChanged()</code> returns true, calls the
+     * <code>update()</code> method for every Observer in the list of
+     * observers using null as the argument. Afterwards calls
+     * <code>clearChanged()</code>.
      * 
      * Equivalent to calling <code>notifyObservers(null)</code>
-	 */
-	public void notifyObservers() {
-		notifyObservers(null);
-	}
-
-	/**
-	 * If <code>hasChanged()</code> returns true, calls the <code>update()</code>
method for
-	 * every Observer in the list of observers using the specified argument.
-	 * Afterwards calls <code>clearChanged()</code>.
-	 * 
-	 * @param data
-	 *            the argument passed to update()
-	 */
+     */
+    public void notifyObservers() {
+        notifyObservers(null);
+    }
+
+    /**
+     * If <code>hasChanged()</code> returns true, calls the
+     * <code>update()</code> method for every Observer in the list of
+     * observers using the specified argument. Afterwards calls
+     * <code>clearChanged()</code>.
+     * 
+     * @param data
+     *            the argument passed to update()
+     */
     @SuppressWarnings("unchecked")
     public void notifyObservers(Object data) {
-		if (hasChanged()) {
-			// Must clone the vector in case deleteObserver is called
-			Vector<Observer> clone = (Vector<Observer>)observers.clone();
-			int size = clone.size();
-			for (int i = 0; i < size; i++) {
-				clone.elementAt(i).update(this, data);
+        int size = 0;
+        Observer[] arrays = null;
+        synchronized (this) {
+            if (hasChanged()) {
+                clearChanged();
+                size = observers.size();
+                arrays = new Observer[size];
+                observers.toArray(arrays);
+            }
+        }
+        if (arrays != null) {
+            for (Observer observer : arrays) {
+                observer.update(this, data);
             }
-			clearChanged();
-		}
-	}
-
-	/**
-	 * Sets the changed flag for this Observable. After calling <code>setChanged()</code>,
<code>hasChanged()</code> will return true.
-	 */
-	protected synchronized void setChanged() {
-		changed = true;
-	}
+        }
+    }
+
+    /**
+     * Sets the changed flag for this Observable. After calling
+     * <code>setChanged()</code>, <code>hasChanged()</code> will
return
+     * true.
+     */
+    protected void setChanged() {
+        changed = true;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java?view=diff&rev=546363&r1=546362&r2=546363
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/UUID.java
Mon Jun 11 20:21:37 2007
@@ -132,9 +132,8 @@
             if (rng == null) {
                 rng = new SecureRandom();
             }
-            rng.nextBytes(data = new byte[16]);
         }
-
+        rng.nextBytes(data = new byte[16]);
         long msb = (data[0] & 0xFFL) << 56;
         msb |= (data[1] & 0xFFL) << 48;
         msb |= (data[2] & 0xFFL) << 40;

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java?view=diff&rev=546363&r1=546362&r2=546363
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Vector.java
Mon Jun 11 20:21:37 2007
@@ -450,7 +450,7 @@
      * @see #size
      */
     @Override
-    public synchronized E get(int location) {
+    public E get(int location) {
         return elementAt(location);
     }
 

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/tests/api/java/util/VectorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/tests/api/java/util/VectorTest.java?view=diff&rev=546363&r1=546362&r2=546363
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/tests/api/java/util/VectorTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/tests/api/java/util/VectorTest.java
Mon Jun 11 20:21:37 2007
@@ -496,8 +496,8 @@
 	 */
 	public void test_indexOfLjava_lang_ObjectI() {
 		// Test for method int java.util.Vector.indexOf(java.lang.Object, int)
-		assertTrue("Failed to find correct index", (tVector.indexOf("Test 98",
-				50) == 98));
+		assertEquals("Failed to find correct index", tVector.indexOf("Test 98",
+				50), 98);
 		assertTrue("Found index of bogus element", (tVector.indexOf(
 				"Test 1001", 50) == -1));
 		tVector.setElementAt(null, 20);
@@ -507,6 +507,22 @@
 				+ tVector.indexOf(null, 25), tVector.indexOf(null, 25) == 40);
 		assertTrue("b) Incorrect indexOf returned for null: "
 				+ tVector.indexOf(null, 20), tVector.indexOf(null, 20) == 20);
+		try {
+			tVector.indexOf("Test 98", -1);
+			fail("should throw ArrayIndexOutOfBoundsException");
+		} catch (ArrayIndexOutOfBoundsException e) {
+
+		}
+		assertEquals(-1, tVector.indexOf("Test 98", 1000));
+		assertEquals(-1, tVector.indexOf("Test 98", Integer.MAX_VALUE));
+		assertEquals(-1, tVector.indexOf("Test 98", tVector.size()));
+		assertEquals(98, tVector.indexOf("Test 98", 0));
+		try {
+			tVector.indexOf("Test 98", Integer.MIN_VALUE);
+			fail("should throw ArrayIndexOutOfBoundsException");
+		} catch (ArrayIndexOutOfBoundsException e) {
+
+		}
 	}
 
 	/**
@@ -615,6 +631,29 @@
 		assertTrue("Incorrect lastIndexOf returned for null: "
 				+ tVector.lastIndexOf(null, 45),
 				tVector.lastIndexOf(null, 45) == 40);
+
+		assertEquals(-1, tVector.lastIndexOf("Test 98", -1));
+		assertEquals(-1, tVector.lastIndexOf("Test 98", 0));
+		try {
+			assertEquals(-1, tVector.lastIndexOf("Test 98", 1000));
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+		}
+		try {
+			assertEquals(-1, tVector.lastIndexOf("Test 98", Integer.MAX_VALUE));
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+		}
+		try {
+			tVector.lastIndexOf("Test 98", tVector.size());
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+		}
+		try {
+			tVector.indexOf("Test 98", Integer.MIN_VALUE);
+			fail("should throw ArrayIndexOutOfBoundsException");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
 	}
 
 	/**

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java?view=diff&rev=546363&r1=546362&r2=546363
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java
Mon Jun 11 20:21:37 2007
@@ -140,7 +140,7 @@
      * 
      * @see java.sql.SQLInput#readBoolean()
      */
-    public boolean readBoolean() throws SQLException, NotImplementedException {
+    public boolean readBoolean() throws SQLException {
         if(readPosition >= attributes.length) {
             throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$
         }
@@ -378,7 +378,7 @@
      * 
      * @see java.sql.SQLInput#wasNull()
      */
-    public boolean wasNull() throws SQLException, NotImplementedException {
+    public boolean wasNull() throws SQLException {
         if (readPosition > attributes.length) {
             throw new SQLException(Messages.getString("sql.35")); //$NON-NLS-1$
         }



Mime
View raw message