sonatype-lift[bot] commented on code in PR #1765:
URL: https://github.com/apache/groovy/pull/1765#discussion_r945363680
##########
src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java:
##########
@@ -562,6 +565,181 @@ public static List primitiveArrayToList(Object array) {
return list;
}
+ /**
+ * Allows conversion of arrays into an immutable List view
+ *
+ * @param array an array
+ * @return a List view of the array
+ */
+ public static List primitiveArrayToUnmodifiableList(Object array) {
+ return new ArrayToUnmodifiableListAdapter(array);
+ }
+
+ static class ArrayToUnmodifiableListAdapter implements List {
+ private Object delegate;
+
+ public ArrayToUnmodifiableListAdapter(Object delegate) {
+ Objects.requireNonNull(delegate);
+ this.delegate = delegate;
+ }
+
+ @Override
+ public int size() {
+ return Array.getLength(delegate);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ for (Object next : this) {
+ if (next.equals(o)) return true;
+ }
+ return false;
+ }
+
+ private class Itr implements Iterator {
+ private int idx = 0;
+
+ @Override
+ public boolean hasNext() {
+ return idx < size();
+ }
+
+ @Override
+ public Object next() {
+ return get(idx++);
+ }
+ }
+
+ @Override
+ public Iterator iterator() {
+ return new Itr();
+ }
+
+ @Override
+ public Object get(int index) {
+ Object item = Array.get(delegate, index);
+ if (item != null && item.getClass().isArray() &&
item.getClass().getComponentType().isPrimitive()) {
+ item = primitiveArrayToUnmodifiableList(item);
+ }
+ return item;
+ }
+
+ @Override
+ public int indexOf(Object o) {
+ int idx = 0;
+ boolean found = false;
+ while (!found && idx < size()) {
+ found = get(idx).equals(o);
+ if (!found) idx++;
+ }
+ return found ? idx : -1;
+ }
+
+ @Override
+ public int lastIndexOf(Object o) {
+ int idx = size() - 1;
+ boolean found = false;
+ while (!found && idx >= 0) {
+ found = get(idx).equals(o);
Review Comment:
The **ignoreall** command is active on this PR, all the existing Lift issues
are ignored.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]