/** * Retains only the elements in this collection that are contained in the * specified collection * * @param c the collection to use as reference * @return true if this collection changed as a result of the call */ @Override public boolean retainAll(Collection<?> c) { boolean result; Iterator<?> iter; Object o; result = false; iter = iterator(); while (iter.hasNext()) { o = iter.next(); if (!c.contains(o)) { result = remove(o) || result; } } m_RecalcHashCode = result; return result; }
/** * Retains only the elements in this collection that are contained in the * specified collection * * @param c the collection to use as reference * @return true if this collection changed as a result of the call */ @Override public boolean retainAll(Collection<?> c) { boolean result; Iterator<?> iter; Object o; result = false; iter = iterator(); while (iter.hasNext()) { o = iter.next(); if (!c.contains(o)) { result = remove(o) || result; } } m_RecalcHashCode = result; return result; }
/** * Returns an array containing all of the elements in this collection; the * runtime type of the returned array is that of the specified array. * * @param a the array into which the elements of this collection are to be * stored * @return an array containing the elements of this collection */ @Override public <T> T[] toArray(T[] a) { T[] result; Iterator<T> iter; Vector<T> list; int i; list = new Vector<T>(); iter = Utils.<Iterator<T>> cast(iterator()); while (iter.hasNext()) { list.add(iter.next()); } if (Array.getLength(a) != list.size()) { result = Utils.<T[]> cast(Array.newInstance(a.getClass() .getComponentType(), list.size())); } else { result = a; } for (i = 0; i < list.size(); i++) { result[i] = list.get(i); } return result; }
/** * Returns an array containing all of the elements in this collection; the * runtime type of the returned array is that of the specified array. * * @param a the array into which the elements of this collection are to be * stored * @return an array containing the elements of this collection */ @Override public <T> T[] toArray(T[] a) { T[] result; Iterator<T> iter; Vector<T> list; int i; list = new Vector<T>(); iter = Utils.<Iterator<T>> cast(iterator()); while (iter.hasNext()) { list.add(iter.next()); } if (Array.getLength(a) != list.size()) { result = Utils.<T[]> cast(Array.newInstance(a.getClass() .getComponentType(), list.size())); } else { result = a; } for (i = 0; i < list.size(); i++) { result[i] = list.get(i); } return result; }
/** * tests whether all the string the Trie got built with can be retrieved * again (tests building and retrieval via iterator). */ public void testCorrectBuild() { // retrieve data Iterator<String> iter = m_Trie.iterator(); HashSet<String> set = new HashSet<String>(); while (iter.hasNext()) set.add(iter.next()); // correct size? assertEquals( "size() does not reflect number of added strings", m_Data.length, m_Trie.size()); // different size? assertEquals( "Iterator returns different number of strings", m_Data.length, set.size()); // different elements? for (int i = 0; i < m_Data.length; i++) { if (!set.contains(m_Data[i])) fail("Cannot find string '" + m_Data[i] + "'"); } }
/** * tests whether all the string the Trie got built with can be retrieved * again (tests building and retrieval via iterator). */ public void testCorrectBuild() { // retrieve data Iterator<String> iter = m_Trie.iterator(); HashSet<String> set = new HashSet<String>(); while (iter.hasNext()) set.add(iter.next()); // correct size? assertEquals( "size() does not reflect number of added strings", m_Data.length, m_Trie.size()); // different size? assertEquals( "Iterator returns different number of strings", m_Data.length, set.size()); // different elements? for (int i = 0; i < m_Data.length; i++) { if (!set.contains(m_Data[i])) fail("Cannot find string '" + m_Data[i] + "'"); } }