You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/12/18 14:31:25 UTC
[isis] 02/04: ISIS-2226: indexOf for Can
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 37fd4d127ca573086cbf9ae3e82b6f649e8ad083
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Dec 18 12:43:26 2019 +0100
ISIS-2226: indexOf for Can<T>
---
.../org/apache/isis/commons/collections/Can.java | 21 +++++++++++++++++++++
.../apache/isis/commons/collections/Can_Empty.java | 5 +++++
.../isis/commons/collections/Can_Multiple.java | 5 +++++
.../isis/commons/collections/Can_Singleton.java | 5 +++++
4 files changed, 36 insertions(+)
diff --git a/core/commons/src/main/java/org/apache/isis/commons/collections/Can.java b/core/commons/src/main/java/org/apache/isis/commons/collections/Can.java
index ee7c308..78375ca 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/collections/Can.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/collections/Can.java
@@ -403,6 +403,27 @@ public interface Can<T> extends Iterable<T> {
*/
Can<T> remove(int index);
+ // -- SEARCH
+
+ /**
+ * Returns the index of the first occurrence of the specified element
+ * in this list, or -1 if this list does not contain the element.
+ * More formally, returns the lowest index <tt>i</tt> such that
+ * <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>,
+ * or -1 if there is no such index.
+ *
+ * @param element element to search for
+ * @return the index of the first occurrence of the specified element in
+ * this list, or -1 if this list does not contain the element
+ * @throws ClassCastException if the type of the specified element
+ * is incompatible with this list
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ * @throws NullPointerException if the specified element is null and this
+ * list does not permit null elements
+ * (<a href="Collection.html#optional-restrictions">optional</a>)
+ */
+ int indexOf(T element);
+
// -- EQUALITY
/**
diff --git a/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Empty.java b/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Empty.java
index 6d4ae4c..901f59f 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Empty.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Empty.java
@@ -88,6 +88,11 @@ final class Can_Empty<T> implements Can<T> {
}
@Override
+ public int indexOf(T element) {
+ return -1;
+ }
+
+ @Override
public String toString() {
return "Can[]";
}
diff --git a/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Multiple.java b/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Multiple.java
index dffbc50..99bf1ae 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Multiple.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Multiple.java
@@ -101,6 +101,11 @@ final class Can_Multiple<T> implements Can<T> {
}
@Override
+ public int indexOf(@NonNull T element) {
+ return this.elements.indexOf(element);
+ }
+
+ @Override
public String toString() {
val literal = stream()
.map(s->""+s)
diff --git a/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Singleton.java b/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Singleton.java
index e186cb9..9396845 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Singleton.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/collections/Can_Singleton.java
@@ -92,6 +92,11 @@ final class Can_Singleton<T> implements Can<T> {
}
@Override
+ public int indexOf(@NonNull T element) {
+ return this.element.equals(element) ? 0 : -1;
+ }
+
+ @Override
public String toString() {
return "Can["+element+"]";
}