From: aclement Date: Mon, 2 Nov 2009 17:04:48 +0000 (+0000) Subject: 293620: new Arrays iterator X-Git-Tag: V1_6_7~167 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c0fe84f31d4840b90fc1c015c3787f0d675afebf;p=aspectj.git 293620: new Arrays iterator --- diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/Iterators.java b/org.aspectj.matcher/src/org/aspectj/weaver/Iterators.java index ad6a863f7..02672b61b 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/Iterators.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/Iterators.java @@ -14,6 +14,7 @@ package org.aspectj.weaver; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.NoSuchElementException; import java.util.Set; @@ -62,7 +63,8 @@ public final class Iterators { } peek = in.next(); if (!seen.contains(peek)) { - return fresh = true; + fresh = true; + return true; } else { peek = null; // garbage collection } @@ -116,8 +118,89 @@ public final class Iterators { }; } + public static class ArrayIterator implements Iterator { + private ResolvedType[] array; + private int index; + private int len; + private boolean wantGenerics; + private List alreadySeen; // type signatures + + public ArrayIterator(ResolvedType[] array, List alreadySeen, boolean genericsAware) { + assert array != null; + this.array = array; + this.wantGenerics = genericsAware; + this.len = array.length; + this.index = 0; + this.alreadySeen = alreadySeen; + moveToNextNewOne(); + } + + private void moveToNextNewOne() { + while (index < len) { + ResolvedType interfaceType = array[index]; + if (!wantGenerics && (interfaceType.isGenericType() || interfaceType.isParameterizedType())) { + interfaceType = interfaceType.getRawType(); + } + String signature = interfaceType.getSignature(); + if (!alreadySeen.contains(signature)) { + break; + } + index++; + } + } + + public boolean hasNext() { + return index < len; + } + + public ResolvedType next() { + if (index < len) { + ResolvedType oo = array[index++]; + if (!wantGenerics && (oo.isParameterizedType() || oo.isGenericType())) { + oo = oo.getRawType(); + } + alreadySeen.add(oo.getSignature()); + moveToNextNewOne(); + return oo; + } else { + throw new NoSuchElementException(); + } + } + + public void remove() { + throw new UnsupportedOperationException(); + } + } + + public static Iterator array(final ResolvedType[] o, final boolean genericsAware) { + return new Iterator() { + int i = 0; + int len = (o == null) ? 0 : o.length; + + public boolean hasNext() { + return i < len; + } + + public ResolvedType next() { + if (i < len) { + ResolvedType oo = o[i++]; + if (!genericsAware && (oo.isParameterizedType() || oo.isGenericType())) { + return oo.getRawType(); + } + return oo; + } else { + throw new NoSuchElementException(); + } + } + + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + /** - * creates an iterator I based on a base iterator A and a getter G. I returns, in order, forall (i in I), G(i). + * creates an iterator I based on a base iterator A and a getter G. I returns, in order, forall (i in A), G(i). */ public static Iterator mapOver(final Iterator a, final Getter g) { return new Iterator() {