COLLETION-699 spaces instead of tabs

spaces instead of tabs
This commit is contained in:
Dennis Goermann 2019-05-22 18:40:49 +02:00
parent b118b89436
commit a2b8f33229
2 changed files with 262 additions and 262 deletions

View File

@ -47,120 +47,120 @@ import org.apache.commons.collections4.iterators.PairingIterator.Entry;
*/
public class PairingIterator<F, S> implements Iterator<Entry<F, S>> {
private final Iterator<F> firstIterator;
private final Iterator<S> secondIterator;
private final Iterator<F> firstIterator;
private final Iterator<S> secondIterator;
/**
* Constructs a new <code>PairingIterator</code> that will provide a
* {@link Entry} containing the child iterator elements.
*
* @param firstIterator the first iterator
* @param secondIterator the second iterator
*/
public PairingIterator(Iterator<F> firstIterator, Iterator<S> secondIterator) {
this.firstIterator = firstIterator;
this.secondIterator = secondIterator;
}
/**
* Constructs a new <code>PairingIterator</code> that will provide a
* {@link Entry} containing the child iterator elements.
*
* @param firstIterator the first iterator
* @param secondIterator the second iterator
*/
public PairingIterator(Iterator<F> firstIterator, Iterator<S> 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<F, S> 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<F, S>(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<F, S> 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<F, S>(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 <F> the type of the first element
* @param <S> the type of the second element
*/
public static class Entry<F, S> {
private final F firstValue;
private final S secondValue;
/**
* Contains two values of different generic types.
*
* @param <F> the type of the first element
* @param <S> the type of the second element
*/
public static class Entry<F, S> {
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 + "]";
}
}
}
}

View File

@ -34,208 +34,208 @@ import org.junit.Test;
*/
public class PairingIteratorTest extends AbstractIteratorTest<Entry<String, String>> {
public PairingIteratorTest(String testName) {
super(testName);
}
public PairingIteratorTest(String testName) {
super(testName);
}
@Test
public void testNullValuesBoth() {
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(null, null);
@Test
public void testNullValuesBoth() {
final PairingIterator<String, String> 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<String> firstList = Arrays.asList(new String[] { "A" });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(null, firstList.iterator());
@Test
public void testNullValueFirst() {
final List<String> firstList = Arrays.asList(new String[] { "A" });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(null, firstList.iterator());
Assert.assertTrue(pairingIterator.hasNext());
Assert.assertTrue(pairingIterator.hasNext());
Entry<String, String> next = pairingIterator.next();
Assert.assertEquals(null, next.getFirstValue());
Assert.assertEquals("A", next.getSecondValue());
}
Entry<String, String> next = pairingIterator.next();
Assert.assertEquals(null, next.getFirstValue());
Assert.assertEquals("A", next.getSecondValue());
}
@Test
public void testNullValueSecond() {
final List<String> firstList = Arrays.asList(new String[] { "A" });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(firstList.iterator(), null);
@Test
public void testNullValueSecond() {
final List<String> firstList = Arrays.asList(new String[] { "A" });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(firstList.iterator(), null);
Assert.assertTrue(pairingIterator.hasNext());
Assert.assertTrue(pairingIterator.hasNext());
Entry<String, String> next = pairingIterator.next();
Assert.assertEquals("A", next.getFirstValue());
Assert.assertEquals(null, next.getSecondValue());
}
Entry<String, String> next = pairingIterator.next();
Assert.assertEquals("A", next.getFirstValue());
Assert.assertEquals(null, next.getSecondValue());
}
@Test
public void testTwoIteratorsWithBothTwoElements() {
final List<String> firstList = Arrays.asList(new String[] { "A1", "A2" });
final List<String> secondList = Arrays.asList(new String[] { "B1", "B2" });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(firstList.iterator(),
secondList.iterator());
@Test
public void testTwoIteratorsWithBothTwoElements() {
final List<String> firstList = Arrays.asList(new String[] { "A1", "A2" });
final List<String> secondList = Arrays.asList(new String[] { "B1", "B2" });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(firstList.iterator(),
secondList.iterator());
Assert.assertTrue(pairingIterator.hasNext());
Assert.assertTrue(pairingIterator.hasNext());
Entry<String, String> next = pairingIterator.next();
Assert.assertEquals("A1", next.getFirstValue());
Assert.assertEquals("B1", next.getSecondValue());
Entry<String, String> 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<String> firstList = Arrays.asList(new String[] { "A1", "A2", "A3" });
final List<String> secondList = Arrays.asList(new String[] { "B1", "B2" });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(firstList.iterator(),
secondList.iterator());
@Test
public void testTwoIteratorsWithDifferentSize() {
final List<String> firstList = Arrays.asList(new String[] { "A1", "A2", "A3" });
final List<String> secondList = Arrays.asList(new String[] { "B1", "B2" });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(firstList.iterator(),
secondList.iterator());
Assert.assertTrue(pairingIterator.hasNext());
Assert.assertTrue(pairingIterator.hasNext());
Entry<String, String> next = pairingIterator.next();
Assert.assertEquals("A1", next.getFirstValue());
Assert.assertEquals("B1", next.getSecondValue());
Entry<String, String> 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<String> firstList = Arrays.asList(new String[] { "A1", });
final List<String> secondList = Arrays.asList(new String[] { "B1", "B2" });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(firstList.iterator(),
secondList.iterator());
@Test
public void testTwoIteratorsWithDifferentSize2() {
final List<String> firstList = Arrays.asList(new String[] { "A1", });
final List<String> secondList = Arrays.asList(new String[] { "B1", "B2" });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(firstList.iterator(),
secondList.iterator());
Assert.assertTrue(pairingIterator.hasNext());
Assert.assertTrue(pairingIterator.hasNext());
Entry<String, String> next = pairingIterator.next();
Assert.assertEquals("A1", next.getFirstValue());
Assert.assertEquals("B1", next.getSecondValue());
Entry<String, String> 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<String> firstList = Arrays.asList(new String[] { null, "A2" });
final List<String> secondList = Arrays.asList(new String[] { "B1", null });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(firstList.iterator(),
secondList.iterator());
@Test
public void testTwoIteratorsWithNullValues() {
final List<String> firstList = Arrays.asList(new String[] { null, "A2" });
final List<String> secondList = Arrays.asList(new String[] { "B1", null });
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(firstList.iterator(),
secondList.iterator());
Assert.assertTrue(pairingIterator.hasNext());
Assert.assertTrue(pairingIterator.hasNext());
Entry<String, String> next = pairingIterator.next();
Assert.assertEquals(null, next.getFirstValue());
Assert.assertEquals("B1", next.getSecondValue());
Entry<String, String> 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<String> firstList = new ArrayList<>();
firstList.add("A1");
final Iterator<String> leftIterator = firstList.iterator();
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(leftIterator, null);
@Test
public void testRemoveWithOneNullIterator() {
final List<String> firstList = new ArrayList<>();
firstList.add("A1");
final Iterator<String> leftIterator = firstList.iterator();
final PairingIterator<String, String> 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<String> secondList = new ArrayList<>();
secondList.add("A1");
final Iterator<String> rightIterator = secondList.iterator();
final PairingIterator<String, String> pairingIterator = new PairingIterator<>(null, rightIterator);
@Test
public void testRemoveWithOneNullIterator2() {
final List<String> secondList = new ArrayList<>();
secondList.add("A1");
final Iterator<String> rightIterator = secondList.iterator();
final PairingIterator<String, String> 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<String, String> entry1 = new Entry<>(firstValue, secondValue);
final Entry<String, String> entry2 = new Entry<>(secondValue, firstValue);
@Test
public void testEntryEquals_notEquals() {
final String firstValue = "A";
final String secondValue = "B";
final Entry<String, String> entry1 = new Entry<>(firstValue, secondValue);
final Entry<String, String> 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<String, String> entry1 = new Entry<>(firstValue, secondValue);
final Entry<String, String> entry2 = new Entry<>(secondValue, firstValue);
@Test
public void testEntryEquals_equals() {
final String firstValue = "A";
final String secondValue = "A";
final Entry<String, String> entry1 = new Entry<>(firstValue, secondValue);
final Entry<String, String> 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<String, String> entry1 = new Entry<>(firstValue, secondValue);
@Test
public void testEntryEquals_equalsSameInstance() {
final String firstValue = "A";
final String secondValue = "A";
final Entry<String, String> entry1 = new Entry<>(firstValue, secondValue);
Assert.assertEquals(entry1, entry1);
}
Assert.assertEquals(entry1, entry1);
}
@Override
public Iterator<Entry<String, String>> makeEmptyIterator() {
return new PairingIterator<String, String>(IteratorUtils.<String>emptyIterator(),
IteratorUtils.<String>emptyIterator());
}
@Override
public Iterator<Entry<String, String>> makeEmptyIterator() {
return new PairingIterator<String, String>(IteratorUtils.<String>emptyIterator(),
IteratorUtils.<String>emptyIterator());
}
@Override
public Iterator<Entry<String, String>> makeObject() {
final List<String> firstList = new ArrayList<>();
firstList.add("A1");
firstList.add("A2");
firstList.add("A3");
final List<String> secondList = new ArrayList<>();
secondList.add("B1");
secondList.add("B2");
return new PairingIterator<>(firstList.iterator(), secondList.iterator());
}
@Override
public Iterator<Entry<String, String>> makeObject() {
final List<String> firstList = new ArrayList<>();
firstList.add("A1");
firstList.add("A2");
firstList.add("A3");
final List<String> secondList = new ArrayList<>();
secondList.add("B1");
secondList.add("B2");
return new PairingIterator<>(firstList.iterator(), secondList.iterator());
}
}