On Thu, Oct 30, 2008 at 3:37 AM, <[EMAIL PROTECTED]> wrote:
> Author: xor
> Date: 2008-10-29 19:37:09 +0000 (Wed, 29 Oct 2008)
> New Revision: 23181
>
> Modified:
> trunk/freenet/src/freenet/support/DoublyLinkedList.java
> trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java
> trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java
>
> trunk/freenet/src/freenet/support/UpdatableSortedLinkedListWithForeignIndex.java
> Log:
> Add contains() functions.
>
> Modified: trunk/freenet/src/freenet/support/DoublyLinkedList.java
> ===================================================================
> --- trunk/freenet/src/freenet/support/DoublyLinkedList.java 2008-10-29
> 19:26:30 UTC (rev 23180)
> +++ trunk/freenet/src/freenet/support/DoublyLinkedList.java 2008-10-29
> 19:37:09 UTC (rev 23181)
> @@ -47,7 +47,13 @@
> /** Get a [EMAIL PROTECTED] Enumeration} of [EMAIL PROTECTED]
> DoublyLinkedList.Item}. */
> Enumeration elements(); // for consistency w/ typical Java API
>
> +
> /**
> + * Returns true if the passed item is contained in the list.
> + */
> + public boolean contains(DoublyLinkedList.Item<T> item);
> +
> + /**
> * Returns the first item.
> * @return the item at the head of the list, or <code>null</code> if
> empty
> */
>
> Modified: trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java
> ===================================================================
> --- trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java 2008-10-29
> 19:26:30 UTC (rev 23180)
> +++ trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java 2008-10-29
> 19:37:09 UTC (rev 23181)
> @@ -116,6 +116,14 @@
> return forwardElements();
> }
>
> + public boolean contains(DoublyLinkedList.Item<T> item) {
> + for(T i : this) {
> + if(i == item)
use .equals() ?
> + return true;
> + }
> + return false;
> + }
> +
> /**
> * [EMAIL PROTECTED]
> */
>
> Modified: trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java
> ===================================================================
> --- trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java
> 2008-10-29 19:26:30 UTC (rev 23180)
> +++ trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java
> 2008-10-29 19:37:09 UTC (rev 23181)
> @@ -218,6 +218,13 @@
> }
>
> /**
> + * @return Does the list contain that item?
> + */
> + public synchronized boolean contains(UpdatableSortedLinkedListItem item)
> {
> + return list.contains(item);
> + }
> +
> + /**
> * @return Is the list empty?
> */
> public synchronized boolean isEmpty() {
>
> Modified:
> trunk/freenet/src/freenet/support/UpdatableSortedLinkedListWithForeignIndex.java
> ===================================================================
> ---
> trunk/freenet/src/freenet/support/UpdatableSortedLinkedListWithForeignIndex.java
> 2008-10-29 19:26:30 UTC (rev 23180)
> +++
> trunk/freenet/src/freenet/support/UpdatableSortedLinkedListWithForeignIndex.java
> 2008-10-29 19:37:09 UTC (rev 23181)
> @@ -50,6 +50,10 @@
> public synchronized boolean containsKey(Object key) {
> return map.containsKey(key);
> }
> +
> + public synchronized boolean
> contains(IndexableUpdatableSortedLinkedListItem item) {
> + return containsKey(item.indexValue());
> + }
Searching on a sorted list can return early, something like this:
for ( Item t : list ) {
if ( t.equals( item ) ) return true;
if ( item > t ) return false;
}
return false;
>
> /**
> * Remove an element from the list by its key.
>
> _______________________________________________
> cvs mailing list
> [EMAIL PROTECTED]
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
>
_______________________________________________
Devl mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl