From e69b8fe9a1b3580cff33423c874fa21f59db65d9 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 18 Jul 2016 15:06:52 +0300 Subject: [PATCH] diff: move trivial implementation inside interface --- .../iterables/ChangeDiffIterableBase.java | 6 +-- .../comparison/iterables/DiffIterable.java | 8 +++- .../iterables/DiffIterableBase.java | 42 ------------------- .../iterables/FairDiffIterableWrapper.java | 2 +- .../InvertedDiffIterableWrapper.java | 2 +- 5 files changed, 11 insertions(+), 49 deletions(-) delete mode 100644 platform/diff-impl/src/com/intellij/diff/comparison/iterables/DiffIterableBase.java diff --git a/platform/diff-impl/src/com/intellij/diff/comparison/iterables/ChangeDiffIterableBase.java b/platform/diff-impl/src/com/intellij/diff/comparison/iterables/ChangeDiffIterableBase.java index c21bbea0c563..5cb9899fbcaa 100644 --- a/platform/diff-impl/src/com/intellij/diff/comparison/iterables/ChangeDiffIterableBase.java +++ b/platform/diff-impl/src/com/intellij/diff/comparison/iterables/ChangeDiffIterableBase.java @@ -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 changes() { - return new MyIterator() { + return new Iterator() { @NotNull private final ChangeIterable myIterable = createChangeIterable(); @Override @@ -62,7 +62,7 @@ abstract class ChangeDiffIterableBase extends DiffIterableBase { @NotNull @Override public Iterator unchanged() { - return new MyIterator() { + return new Iterator() { @NotNull private final ChangeIterable myIterable = createChangeIterable(); int lastIndex1 = 0; diff --git a/platform/diff-impl/src/com/intellij/diff/comparison/iterables/DiffIterable.java b/platform/diff-impl/src/com/intellij/diff/comparison/iterables/DiffIterable.java index ee429e6ff60b..28f27a729b9b 100644 --- a/platform/diff-impl/src/com/intellij/diff/comparison/iterables/DiffIterable.java +++ b/platform/diff-impl/src/com/intellij/diff/comparison/iterables/DiffIterable.java @@ -36,8 +36,12 @@ public interface DiffIterable { Iterator unchanged(); @NotNull - Iterable iterateChanges(); + default Iterable iterateChanges() { + return this::changes; + } @NotNull - Iterable iterateUnchanged(); + default Iterable iterateUnchanged() { + return this::unchanged; + } } diff --git a/platform/diff-impl/src/com/intellij/diff/comparison/iterables/DiffIterableBase.java b/platform/diff-impl/src/com/intellij/diff/comparison/iterables/DiffIterableBase.java deleted file mode 100644 index a0f882d7455a..000000000000 --- a/platform/diff-impl/src/com/intellij/diff/comparison/iterables/DiffIterableBase.java +++ /dev/null @@ -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 iterateUnchanged() { - return this::unchanged; - } - - @NotNull - @Override - public Iterable iterateChanges() { - return this::changes; - } - - protected static abstract class MyIterator implements Iterator { - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - } -} diff --git a/platform/diff-impl/src/com/intellij/diff/comparison/iterables/FairDiffIterableWrapper.java b/platform/diff-impl/src/com/intellij/diff/comparison/iterables/FairDiffIterableWrapper.java index 541dd258a680..ec4c8032085f 100644 --- a/platform/diff-impl/src/com/intellij/diff/comparison/iterables/FairDiffIterableWrapper.java +++ b/platform/diff-impl/src/com/intellij/diff/comparison/iterables/FairDiffIterableWrapper.java @@ -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) { diff --git a/platform/diff-impl/src/com/intellij/diff/comparison/iterables/InvertedDiffIterableWrapper.java b/platform/diff-impl/src/com/intellij/diff/comparison/iterables/InvertedDiffIterableWrapper.java index eb90d653ddb7..c1f5c7d2bb46 100644 --- a/platform/diff-impl/src/com/intellij/diff/comparison/iterables/InvertedDiffIterableWrapper.java +++ b/platform/diff-impl/src/com/intellij/diff/comparison/iterables/InvertedDiffIterableWrapper.java @@ -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) {