Repository: kafka Updated Branches: refs/heads/trunk e9a72ceab -> 9ffa907d7
MINOR: remove FilteredIterator guozhangwang removing an unused class, FilteredIterator, and its test. Author: Yasuhiro Matsuda <[email protected]> Reviewers: Gwen Shapira Closes #816 from ymatsuda/remove_obsolete_class Project: http://git-wip-us.apache.org/repos/asf/kafka/repo Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/9ffa907d Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/9ffa907d Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/9ffa907d Branch: refs/heads/trunk Commit: 9ffa907d704b424ad05c18d834cfefdc1c7ad22a Parents: e9a72ce Author: Yasuhiro Matsuda <[email protected]> Authored: Tue Jan 26 20:03:50 2016 -0800 Committer: Gwen Shapira <[email protected]> Committed: Tue Jan 26 20:03:50 2016 -0800 ---------------------------------------------------------------------- .../kstream/internals/FilteredIterator.java | 63 ------------- .../kstream/internals/FilteredIteratorTest.java | 94 -------------------- 2 files changed, 157 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kafka/blob/9ffa907d/streams/src/main/java/org/apache/kafka/streams/kstream/internals/FilteredIterator.java ---------------------------------------------------------------------- diff --git a/streams/src/main/java/org/apache/kafka/streams/kstream/internals/FilteredIterator.java b/streams/src/main/java/org/apache/kafka/streams/kstream/internals/FilteredIterator.java deleted file mode 100644 index 54d44f0..0000000 --- a/streams/src/main/java/org/apache/kafka/streams/kstream/internals/FilteredIterator.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.kafka.streams.kstream.internals; - -import java.util.Iterator; - -public abstract class FilteredIterator<T, S> implements Iterator<T> { - - private Iterator<S> inner; - private T nextValue = null; - - public FilteredIterator(Iterator<S> inner) { - this.inner = inner; - - findNext(); - } - - @Override - public boolean hasNext() { - return nextValue != null; - } - - @Override - public T next() { - T value = nextValue; - findNext(); - - return value; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - private void findNext() { - while (inner.hasNext()) { - S item = inner.next(); - nextValue = filter(item); - if (nextValue != null) { - return; - } - } - nextValue = null; - } - - protected abstract T filter(S item); -} http://git-wip-us.apache.org/repos/asf/kafka/blob/9ffa907d/streams/src/test/java/org/apache/kafka/streams/kstream/internals/FilteredIteratorTest.java ---------------------------------------------------------------------- diff --git a/streams/src/test/java/org/apache/kafka/streams/kstream/internals/FilteredIteratorTest.java b/streams/src/test/java/org/apache/kafka/streams/kstream/internals/FilteredIteratorTest.java deleted file mode 100644 index 405c7c9..0000000 --- a/streams/src/test/java/org/apache/kafka/streams/kstream/internals/FilteredIteratorTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.kafka.streams.kstream.internals; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -public class FilteredIteratorTest { - - @Test - public void testFiltering() { - List<Integer> list = Arrays.asList(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5); - - Iterator<String> filtered = new FilteredIterator<String, Integer>(list.iterator()) { - protected String filter(Integer i) { - if (i % 3 == 0) return i.toString(); - return null; - } - }; - - List<String> expected = Arrays.asList("3", "9", "6", "3"); - List<String> result = new ArrayList<String>(); - - while (filtered.hasNext()) { - result.add(filtered.next()); - } - - assertEquals(expected, result); - } - - @Test - public void testEmptySource() { - List<Integer> list = new ArrayList<Integer>(); - - Iterator<String> filtered = new FilteredIterator<String, Integer>(list.iterator()) { - protected String filter(Integer i) { - if (i % 3 == 0) return i.toString(); - return null; - } - }; - - List<String> expected = new ArrayList<String>(); - List<String> result = new ArrayList<String>(); - - while (filtered.hasNext()) { - result.add(filtered.next()); - } - - assertEquals(expected, result); - } - - @Test - public void testNoMatch() { - List<Integer> list = Arrays.asList(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5); - - Iterator<String> filtered = new FilteredIterator<String, Integer>(list.iterator()) { - protected String filter(Integer i) { - if (i % 7 == 0) return i.toString(); - return null; - } - }; - - List<String> expected = new ArrayList<String>(); - List<String> result = new ArrayList<String>(); - - while (filtered.hasNext()) { - result.add(filtered.next()); - } - - assertEquals(expected, result); - } - -}
