From a2b8f33229be2da04425e39e84bf594297b1d0d2 Mon Sep 17 00:00:00 2001 From: Dennis Goermann Date: Wed, 22 May 2019 18:40:49 +0200 Subject: [PATCH] COLLETION-699 spaces instead of tabs spaces instead of tabs --- .../iterators/PairingIterator.java | 206 ++++++------ .../iterators/PairingIteratorTest.java | 318 +++++++++--------- 2 files changed, 262 insertions(+), 262 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/iterators/PairingIterator.java b/src/main/java/org/apache/commons/collections4/iterators/PairingIterator.java index eaf656f90..4b95884ef 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/PairingIterator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/PairingIterator.java @@ -47,120 +47,120 @@ import org.apache.commons.collections4.iterators.PairingIterator.Entry; */ public class PairingIterator implements Iterator> { - private final Iterator firstIterator; - private final Iterator secondIterator; + private final Iterator firstIterator; + private final Iterator secondIterator; - /** - * Constructs a new PairingIterator that will provide a - * {@link Entry} containing the child iterator elements. - * - * @param firstIterator the first iterator - * @param secondIterator the second iterator - */ - public PairingIterator(Iterator firstIterator, Iterator secondIterator) { - this.firstIterator = firstIterator; - this.secondIterator = secondIterator; - } + /** + * Constructs a new PairingIterator that will provide a + * {@link Entry} containing the child iterator elements. + * + * @param firstIterator the first iterator + * @param secondIterator the second iterator + */ + public PairingIterator(Iterator firstIterator, Iterator secondIterator) { + this.firstIterator = firstIterator; + this.secondIterator = secondIterator; + } - /** - * Returns {@code true} if one of the child iterators has remaining elements. - */ - @Override - public boolean hasNext() { - return (null != firstIterator && firstIterator.hasNext()) - || (null != secondIterator && secondIterator.hasNext()); - } + /** + * Returns {@code true} if one of the child iterators has remaining elements. + */ + @Override + public boolean hasNext() { + return (null != firstIterator && firstIterator.hasNext()) + || (null != secondIterator && secondIterator.hasNext()); + } - /** - * Returns the next {@link Entry} with the next values of the child iterators. - * - * @return a {@link Entry} with the next values of child iterators - * @throws NoSuchElementException if no child iterator has any more elements - */ - @Override - public Entry next() throws NoSuchElementException { - if (!hasNext()) { - throw new NoSuchElementException(); - } - final F firstValue = null != firstIterator && firstIterator.hasNext() ? firstIterator.next() : null; - final S secondValue = null != secondIterator && secondIterator.hasNext() ? secondIterator.next() : null; - return new Entry(firstValue, secondValue); - } + /** + * Returns the next {@link Entry} with the next values of the child iterators. + * + * @return a {@link Entry} with the next values of child iterators + * @throws NoSuchElementException if no child iterator has any more elements + */ + @Override + public Entry next() throws NoSuchElementException { + if (!hasNext()) { + throw new NoSuchElementException(); + } + final F firstValue = null != firstIterator && firstIterator.hasNext() ? firstIterator.next() : null; + final S secondValue = null != secondIterator && secondIterator.hasNext() ? secondIterator.next() : null; + return new Entry(firstValue, secondValue); + } - /** - * Removes the last returned values of the child iterators. - */ - @Override - public void remove() { - if (firstIterator != null) { - firstIterator.remove(); - } - if (secondIterator != null) { - secondIterator.remove(); - } - } + /** + * Removes the last returned values of the child iterators. + */ + @Override + public void remove() { + if (firstIterator != null) { + firstIterator.remove(); + } + if (secondIterator != null) { + secondIterator.remove(); + } + } - /** - * Contains two values of different generic types. - * - * @param the type of the first element - * @param the type of the second element - */ - public static class Entry { - private final F firstValue; - private final S secondValue; + /** + * Contains two values of different generic types. + * + * @param the type of the first element + * @param the type of the second element + */ + public static class Entry { + private final F firstValue; + private final S secondValue; - /** - * Constructs a new {@link Entry} of two generic values. - * - * @param firstValue the first value - * @param secondValue the second value - */ - Entry(F firstValue, S secondValue) { - this.firstValue = firstValue; - this.secondValue = secondValue; - } + /** + * Constructs a new {@link Entry} of two generic values. + * + * @param firstValue the first value + * @param secondValue the second value + */ + Entry(F firstValue, S secondValue) { + this.firstValue = firstValue; + this.secondValue = secondValue; + } - /** - * Returns the first value. - * - * @return the first value - */ - public F getFirstValue() { - return firstValue; - } + /** + * Returns the first value. + * + * @return the first value + */ + public F getFirstValue() { + return firstValue; + } - /** - * Returns the second value. - * - * @return the second value - */ - public S getSecondValue() { - return secondValue; - } + /** + * Returns the second value. + * + * @return the second value + */ + public S getSecondValue() { + return secondValue; + } - @Override - public int hashCode() { - return Objects.hash(firstValue, secondValue); - } + @Override + public int hashCode() { + return Objects.hash(firstValue, secondValue); + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Entry other = (Entry) obj; - return Objects.equals(firstValue, other.firstValue) && Objects.equals(secondValue, other.secondValue); - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Entry other = (Entry) obj; + return Objects.equals(firstValue, other.firstValue) && Objects.equals(secondValue, other.secondValue); + } - @Override - public String toString() { - return "Entry [firstValue=" + firstValue + ", secondValue=" + secondValue + "]"; - } + @Override + public String toString() { + return "Entry [firstValue=" + firstValue + ", secondValue=" + secondValue + "]"; + } - } + } } diff --git a/src/test/java/org/apache/commons/collections4/iterators/PairingIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/PairingIteratorTest.java index ca9121600..d0ca7e119 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/PairingIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/PairingIteratorTest.java @@ -34,208 +34,208 @@ import org.junit.Test; */ public class PairingIteratorTest extends AbstractIteratorTest> { - public PairingIteratorTest(String testName) { - super(testName); - } + public PairingIteratorTest(String testName) { + super(testName); + } - @Test - public void testNullValuesBoth() { - final PairingIterator pairingIterator = new PairingIterator<>(null, null); + @Test + public void testNullValuesBoth() { + final PairingIterator pairingIterator = new PairingIterator<>(null, null); - Assert.assertFalse(pairingIterator.hasNext()); - try { - pairingIterator.next(); - fail(); + Assert.assertFalse(pairingIterator.hasNext()); + try { + pairingIterator.next(); + fail(); - } catch (NoSuchElementException e) { - Assert.assertNotNull(e); - } - } + } catch (NoSuchElementException e) { + Assert.assertNotNull(e); + } + } - @Test - public void testNullValueFirst() { - final List firstList = Arrays.asList(new String[] { "A" }); - final PairingIterator pairingIterator = new PairingIterator<>(null, firstList.iterator()); + @Test + public void testNullValueFirst() { + final List firstList = Arrays.asList(new String[] { "A" }); + final PairingIterator pairingIterator = new PairingIterator<>(null, firstList.iterator()); - Assert.assertTrue(pairingIterator.hasNext()); + Assert.assertTrue(pairingIterator.hasNext()); - Entry next = pairingIterator.next(); - Assert.assertEquals(null, next.getFirstValue()); - Assert.assertEquals("A", next.getSecondValue()); - } + Entry next = pairingIterator.next(); + Assert.assertEquals(null, next.getFirstValue()); + Assert.assertEquals("A", next.getSecondValue()); + } - @Test - public void testNullValueSecond() { - final List firstList = Arrays.asList(new String[] { "A" }); - final PairingIterator pairingIterator = new PairingIterator<>(firstList.iterator(), null); + @Test + public void testNullValueSecond() { + final List firstList = Arrays.asList(new String[] { "A" }); + final PairingIterator pairingIterator = new PairingIterator<>(firstList.iterator(), null); - Assert.assertTrue(pairingIterator.hasNext()); + Assert.assertTrue(pairingIterator.hasNext()); - Entry next = pairingIterator.next(); - Assert.assertEquals("A", next.getFirstValue()); - Assert.assertEquals(null, next.getSecondValue()); - } + Entry next = pairingIterator.next(); + Assert.assertEquals("A", next.getFirstValue()); + Assert.assertEquals(null, next.getSecondValue()); + } - @Test - public void testTwoIteratorsWithBothTwoElements() { - final List firstList = Arrays.asList(new String[] { "A1", "A2" }); - final List secondList = Arrays.asList(new String[] { "B1", "B2" }); - final PairingIterator pairingIterator = new PairingIterator<>(firstList.iterator(), - secondList.iterator()); + @Test + public void testTwoIteratorsWithBothTwoElements() { + final List firstList = Arrays.asList(new String[] { "A1", "A2" }); + final List secondList = Arrays.asList(new String[] { "B1", "B2" }); + final PairingIterator pairingIterator = new PairingIterator<>(firstList.iterator(), + secondList.iterator()); - Assert.assertTrue(pairingIterator.hasNext()); + Assert.assertTrue(pairingIterator.hasNext()); - Entry next = pairingIterator.next(); - Assert.assertEquals("A1", next.getFirstValue()); - Assert.assertEquals("B1", next.getSecondValue()); + Entry next = pairingIterator.next(); + Assert.assertEquals("A1", next.getFirstValue()); + Assert.assertEquals("B1", next.getSecondValue()); - Assert.assertTrue(pairingIterator.hasNext()); - next = pairingIterator.next(); - Assert.assertEquals("A2", next.getFirstValue()); - Assert.assertEquals("B2", next.getSecondValue()); + Assert.assertTrue(pairingIterator.hasNext()); + next = pairingIterator.next(); + Assert.assertEquals("A2", next.getFirstValue()); + Assert.assertEquals("B2", next.getSecondValue()); - Assert.assertFalse(pairingIterator.hasNext()); - } + Assert.assertFalse(pairingIterator.hasNext()); + } - @Test - public void testTwoIteratorsWithDifferentSize() { - final List firstList = Arrays.asList(new String[] { "A1", "A2", "A3" }); - final List secondList = Arrays.asList(new String[] { "B1", "B2" }); - final PairingIterator pairingIterator = new PairingIterator<>(firstList.iterator(), - secondList.iterator()); + @Test + public void testTwoIteratorsWithDifferentSize() { + final List firstList = Arrays.asList(new String[] { "A1", "A2", "A3" }); + final List secondList = Arrays.asList(new String[] { "B1", "B2" }); + final PairingIterator pairingIterator = new PairingIterator<>(firstList.iterator(), + secondList.iterator()); - Assert.assertTrue(pairingIterator.hasNext()); + Assert.assertTrue(pairingIterator.hasNext()); - Entry next = pairingIterator.next(); - Assert.assertEquals("A1", next.getFirstValue()); - Assert.assertEquals("B1", next.getSecondValue()); + Entry next = pairingIterator.next(); + Assert.assertEquals("A1", next.getFirstValue()); + Assert.assertEquals("B1", next.getSecondValue()); - Assert.assertTrue(pairingIterator.hasNext()); + Assert.assertTrue(pairingIterator.hasNext()); - next = pairingIterator.next(); - Assert.assertEquals("A2", next.getFirstValue()); - Assert.assertEquals("B2", next.getSecondValue()); + next = pairingIterator.next(); + Assert.assertEquals("A2", next.getFirstValue()); + Assert.assertEquals("B2", next.getSecondValue()); - Assert.assertTrue(pairingIterator.hasNext()); - next = pairingIterator.next(); - Assert.assertEquals("A3", next.getFirstValue()); - Assert.assertEquals(null, next.getSecondValue()); + Assert.assertTrue(pairingIterator.hasNext()); + next = pairingIterator.next(); + Assert.assertEquals("A3", next.getFirstValue()); + Assert.assertEquals(null, next.getSecondValue()); - Assert.assertFalse(pairingIterator.hasNext()); - } + Assert.assertFalse(pairingIterator.hasNext()); + } - @Test - public void testTwoIteratorsWithDifferentSize2() { - final List firstList = Arrays.asList(new String[] { "A1", }); - final List secondList = Arrays.asList(new String[] { "B1", "B2" }); - final PairingIterator pairingIterator = new PairingIterator<>(firstList.iterator(), - secondList.iterator()); + @Test + public void testTwoIteratorsWithDifferentSize2() { + final List firstList = Arrays.asList(new String[] { "A1", }); + final List secondList = Arrays.asList(new String[] { "B1", "B2" }); + final PairingIterator pairingIterator = new PairingIterator<>(firstList.iterator(), + secondList.iterator()); - Assert.assertTrue(pairingIterator.hasNext()); + Assert.assertTrue(pairingIterator.hasNext()); - Entry next = pairingIterator.next(); - Assert.assertEquals("A1", next.getFirstValue()); - Assert.assertEquals("B1", next.getSecondValue()); + Entry next = pairingIterator.next(); + Assert.assertEquals("A1", next.getFirstValue()); + Assert.assertEquals("B1", next.getSecondValue()); - Assert.assertTrue(pairingIterator.hasNext()); + Assert.assertTrue(pairingIterator.hasNext()); - next = pairingIterator.next(); - Assert.assertEquals(null, next.getFirstValue()); - Assert.assertEquals("B2", next.getSecondValue()); + next = pairingIterator.next(); + Assert.assertEquals(null, next.getFirstValue()); + Assert.assertEquals("B2", next.getSecondValue()); - Assert.assertFalse(pairingIterator.hasNext()); - } + Assert.assertFalse(pairingIterator.hasNext()); + } - @Test - public void testTwoIteratorsWithNullValues() { - final List firstList = Arrays.asList(new String[] { null, "A2" }); - final List secondList = Arrays.asList(new String[] { "B1", null }); - final PairingIterator pairingIterator = new PairingIterator<>(firstList.iterator(), - secondList.iterator()); + @Test + public void testTwoIteratorsWithNullValues() { + final List firstList = Arrays.asList(new String[] { null, "A2" }); + final List secondList = Arrays.asList(new String[] { "B1", null }); + final PairingIterator pairingIterator = new PairingIterator<>(firstList.iterator(), + secondList.iterator()); - Assert.assertTrue(pairingIterator.hasNext()); + Assert.assertTrue(pairingIterator.hasNext()); - Entry next = pairingIterator.next(); - Assert.assertEquals(null, next.getFirstValue()); - Assert.assertEquals("B1", next.getSecondValue()); + Entry next = pairingIterator.next(); + Assert.assertEquals(null, next.getFirstValue()); + Assert.assertEquals("B1", next.getSecondValue()); - Assert.assertTrue(pairingIterator.hasNext()); - next = pairingIterator.next(); - Assert.assertEquals("A2", next.getFirstValue()); - Assert.assertEquals(null, next.getSecondValue()); + Assert.assertTrue(pairingIterator.hasNext()); + next = pairingIterator.next(); + Assert.assertEquals("A2", next.getFirstValue()); + Assert.assertEquals(null, next.getSecondValue()); - Assert.assertFalse(pairingIterator.hasNext()); - } + Assert.assertFalse(pairingIterator.hasNext()); + } - @Test - public void testRemoveWithOneNullIterator() { - final List firstList = new ArrayList<>(); - firstList.add("A1"); - final Iterator leftIterator = firstList.iterator(); - final PairingIterator pairingIterator = new PairingIterator<>(leftIterator, null); + @Test + public void testRemoveWithOneNullIterator() { + final List firstList = new ArrayList<>(); + firstList.add("A1"); + final Iterator leftIterator = firstList.iterator(); + final PairingIterator pairingIterator = new PairingIterator<>(leftIterator, null); - pairingIterator.next(); - pairingIterator.remove(); - Assert.assertTrue(firstList.isEmpty()); - } + pairingIterator.next(); + pairingIterator.remove(); + Assert.assertTrue(firstList.isEmpty()); + } - @Test - public void testRemoveWithOneNullIterator2() { - final List secondList = new ArrayList<>(); - secondList.add("A1"); - final Iterator rightIterator = secondList.iterator(); - final PairingIterator pairingIterator = new PairingIterator<>(null, rightIterator); + @Test + public void testRemoveWithOneNullIterator2() { + final List secondList = new ArrayList<>(); + secondList.add("A1"); + final Iterator rightIterator = secondList.iterator(); + final PairingIterator pairingIterator = new PairingIterator<>(null, rightIterator); - pairingIterator.next(); - pairingIterator.remove(); - Assert.assertTrue(secondList.isEmpty()); - } + pairingIterator.next(); + pairingIterator.remove(); + Assert.assertTrue(secondList.isEmpty()); + } - @Test - public void testEntryEquals_notEquals() { - final String firstValue = "A"; - final String secondValue = "B"; - final Entry entry1 = new Entry<>(firstValue, secondValue); - final Entry entry2 = new Entry<>(secondValue, firstValue); + @Test + public void testEntryEquals_notEquals() { + final String firstValue = "A"; + final String secondValue = "B"; + final Entry entry1 = new Entry<>(firstValue, secondValue); + final Entry entry2 = new Entry<>(secondValue, firstValue); - Assert.assertNotEquals(entry1, entry2); - } + Assert.assertNotEquals(entry1, entry2); + } - @Test - public void testEntryEquals_equals() { - final String firstValue = "A"; - final String secondValue = "A"; - final Entry entry1 = new Entry<>(firstValue, secondValue); - final Entry entry2 = new Entry<>(secondValue, firstValue); + @Test + public void testEntryEquals_equals() { + final String firstValue = "A"; + final String secondValue = "A"; + final Entry entry1 = new Entry<>(firstValue, secondValue); + final Entry entry2 = new Entry<>(secondValue, firstValue); - Assert.assertEquals(entry1, entry2); - } + Assert.assertEquals(entry1, entry2); + } - @Test - public void testEntryEquals_equalsSameInstance() { - final String firstValue = "A"; - final String secondValue = "A"; - final Entry entry1 = new Entry<>(firstValue, secondValue); + @Test + public void testEntryEquals_equalsSameInstance() { + final String firstValue = "A"; + final String secondValue = "A"; + final Entry entry1 = new Entry<>(firstValue, secondValue); - Assert.assertEquals(entry1, entry1); - } + Assert.assertEquals(entry1, entry1); + } - @Override - public Iterator> makeEmptyIterator() { - return new PairingIterator(IteratorUtils.emptyIterator(), - IteratorUtils.emptyIterator()); - } + @Override + public Iterator> makeEmptyIterator() { + return new PairingIterator(IteratorUtils.emptyIterator(), + IteratorUtils.emptyIterator()); + } - @Override - public Iterator> makeObject() { - final List firstList = new ArrayList<>(); - firstList.add("A1"); - firstList.add("A2"); - firstList.add("A3"); - final List secondList = new ArrayList<>(); - secondList.add("B1"); - secondList.add("B2"); - return new PairingIterator<>(firstList.iterator(), secondList.iterator()); - } + @Override + public Iterator> makeObject() { + final List firstList = new ArrayList<>(); + firstList.add("A1"); + firstList.add("A2"); + firstList.add("A3"); + final List secondList = new ArrayList<>(); + secondList.add("B1"); + secondList.add("B2"); + return new PairingIterator<>(firstList.iterator(), secondList.iterator()); + } }