svn commit: r17705 - trunk/src/argouml-app/src/org/argouml/util/CollectionUtil.java
Bob Tarling <[email protected]>
| Newsgroups | gmane.comp.lang.uml.argouml.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: bobtarling
Date: 2009-12-23 08:43:29-0800
New Revision: 17705
Modified:
trunk/src/argouml-app/src/org/argouml/util/CollectionUtil.java
Log:
New utility method
Modified: trunk/src/argouml-app/src/org/argouml/util/CollectionUtil.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/src/org/argouml/util/CollectionUtil.java?view=diff&pathrev=17705&r1=17704&r2=17705
==============================================================================
--- trunk/src/argouml-app/src/org/argouml/util/CollectionUtil.java (original)
+++ trunk/src/argouml-app/src/org/argouml/util/CollectionUtil.java 2009-12-23 08:43:29-0800
@@ -1,3 +1,16 @@
+/* $Id$
+ *******************************************************************************
+ * Copyright (c) 2009 Contributors - see below
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Bob Tarling
+ *******************************************************************************
+ */
+
// $Id$
// Copyright (c) 1996-2006 The Regents of the University of California. All
// Rights Reserved. Permission to use, copy, modify, and distribute this
@@ -69,4 +82,29 @@
}
return getFirstItem(c);
}
+
+ /**
+ * Get the index position of an element in a collection
+ *
+ * @param c The Collection.
+ * @param elem the element to find the index of
+ * @return the element index
+ */
+ public static int indexOf(
+ final Collection c,
+ final Object elem) {
+ if (c instanceof List) {
+ return ((List) c).indexOf(elem);
+ } else {
+ int index = 0;
+ for (Object element : c) {
+ if (element == elem) {
+ return index;
+ } else {
+ ++index;
+ }
+ }
+ return -1;
+ }
+ }
}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2432657
To unsubscribe from this discussion, e-mail: [[email protected]].