diff: move trivial implementation inside interface

This commit is contained in:
Aleksey Pivovarov
2016-07-18 15:13:59 +03:00
parent b39787a164
commit e69b8fe9a1
5 changed files with 11 additions and 49 deletions
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
abstract class ChangeDiffIterableBase extends DiffIterableBase {
abstract class ChangeDiffIterableBase implements DiffIterable {
private final int myLength1;
private final int myLength2;
@@ -42,7 +42,7 @@ abstract class ChangeDiffIterableBase extends DiffIterableBase {
@NotNull
@Override
public Iterator<Range> changes() {
return new MyIterator<Range>() {
return new Iterator<Range>() {
@NotNull private final ChangeIterable myIterable = createChangeIterable();
@Override
@@ -62,7 +62,7 @@ abstract class ChangeDiffIterableBase extends DiffIterableBase {
@NotNull
@Override
public Iterator<Range> unchanged() {
return new MyIterator<Range>() {
return new Iterator<Range>() {
@NotNull private final ChangeIterable myIterable = createChangeIterable();
int lastIndex1 = 0;
@@ -36,8 +36,12 @@ public interface DiffIterable {
Iterator<Range> unchanged();
@NotNull
Iterable<Range> iterateChanges();
default Iterable<Range> iterateChanges() {
return this::changes;
}
@NotNull
Iterable<Range> iterateUnchanged();
default Iterable<Range> iterateUnchanged() {
return this::unchanged;
}
}
@@ -1,42 +0,0 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed 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 com.intellij.diff.comparison.iterables;
import com.intellij.diff.util.Range;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
abstract class DiffIterableBase implements DiffIterable {
@NotNull
@Override
public Iterable<Range> iterateUnchanged() {
return this::unchanged;
}
@NotNull
@Override
public Iterable<Range> iterateChanges() {
return this::changes;
}
protected static abstract class MyIterator<T> implements Iterator<T> {
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
}
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
class FairDiffIterableWrapper extends DiffIterableBase implements FairDiffIterable {
class FairDiffIterableWrapper implements FairDiffIterable {
@NotNull private final DiffIterable myIterable;
public FairDiffIterableWrapper(@NotNull DiffIterable iterable) {
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
class InvertedDiffIterableWrapper extends DiffIterableBase {
class InvertedDiffIterableWrapper implements DiffIterable {
@NotNull private final DiffIterable myIterable;
public InvertedDiffIterableWrapper(@NotNull DiffIterable iterable) {