Moved primitive iterators to upper level.

This commit is contained in:
Evgeny Gerashchenko
2013-01-22 22:54:15 +04:00
parent 88a6cffb34
commit abe7ca21bf
14 changed files with 306 additions and 187 deletions
+3 -27
View File
@@ -81,9 +81,9 @@ public final class ByteRange implements Range<Byte>, ByteIterable {
public ByteIterator step(int step) {
if (step < 0)
return new ByteIteratorImpl(getEnd(), getStart(), step);
return new ByteSequenceIterator(getEnd(), getStart(), step);
else
return new ByteIteratorImpl(getStart(), getEnd(), step);
return new ByteSequenceIterator(getStart(), getEnd(), step);
}
public byte getStart() {
@@ -100,30 +100,6 @@ public final class ByteRange implements Range<Byte>, ByteIterable {
@Override
public ByteIterator iterator() {
return new ByteIteratorImpl(getStart(), getEnd(), 1);
}
private static class ByteIteratorImpl extends ByteIterator {
private byte next;
private final byte end;
private final int increment;
public ByteIteratorImpl(byte start, byte end, int increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public byte nextByte() {
byte value = next;
next += increment;
return value;
}
return new ByteSequenceIterator(getStart(), getEnd(), 1);
}
}
+41
View File
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2013 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 jet;
class ByteSequenceIterator extends ByteIterator {
private byte next;
private final byte end;
private final int increment;
public ByteSequenceIterator(byte start, byte end, int increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public byte nextByte() {
byte value = next;
next += increment;
return value;
}
}
+3 -27
View File
@@ -81,9 +81,9 @@ public final class CharRange implements Range<Character>, CharIterable {
public CharIterator step(int step) {
if (step < 0)
return new CharIteratorImpl(getEnd(), getStart(), step);
return new CharacterSequenceIterator(getEnd(), getStart(), step);
else
return new CharIteratorImpl(getStart(), getEnd(), step);
return new CharacterSequenceIterator(getStart(), getEnd(), step);
}
public char getStart() {
@@ -100,30 +100,6 @@ public final class CharRange implements Range<Character>, CharIterable {
@Override
public CharIterator iterator() {
return new CharIteratorImpl(getStart(), getEnd(), 1);
}
private static class CharIteratorImpl extends CharIterator {
private char next;
private final char end;
private final int increment;
public CharIteratorImpl(char start, char end, int increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public char nextChar() {
char value = next;
next += increment;
return value;
}
return new CharacterSequenceIterator(getStart(), getEnd(), 1);
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2013 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 jet;
class CharacterSequenceIterator extends CharIterator {
private char next;
private final char end;
private final int increment;
public CharacterSequenceIterator(char start, char end, int increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public char nextChar() {
char value = next;
next += increment;
return value;
}
}
+2 -26
View File
@@ -79,9 +79,9 @@ public final class DoubleRange implements Range<Double> {
public DoubleIterator step(double step) {
if (step < 0)
return new DoubleIteratorImpl(getEnd(), getStart(), step);
return new DoubleSequenceIterator(getEnd(), getStart(), step);
else
return new DoubleIteratorImpl(getStart(), getEnd(), step);
return new DoubleSequenceIterator(getStart(), getEnd(), step);
}
public double getStart() {
@@ -95,28 +95,4 @@ public final class DoubleRange implements Range<Double> {
public double getSize() {
return size < 0 ? -size : size;
}
private static class DoubleIteratorImpl extends DoubleIterator {
private double next;
private final double end;
private final double increment;
public DoubleIteratorImpl(double start, double end, double increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public double nextDouble() {
double value = next;
next += increment;
return value;
}
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2013 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 jet;
class DoubleSequenceIterator extends DoubleIterator {
private double next;
private final double end;
private final double increment;
public DoubleSequenceIterator(double start, double end, double increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public double nextDouble() {
double value = next;
next += increment;
return value;
}
}
+2 -26
View File
@@ -75,9 +75,9 @@ public final class FloatRange implements Range<Float> {
public FloatIterator step(float step) {
if (step < 0)
return new FloatIteratorImpl(getEnd(), getStart(), step);
return new FloatSequenceIterator(getEnd(), getStart(), step);
else
return new FloatIteratorImpl(getStart(), getEnd(), step);
return new FloatSequenceIterator(getStart(), getEnd(), step);
}
public float getStart() {
@@ -91,28 +91,4 @@ public final class FloatRange implements Range<Float> {
public float getSize() {
return size < 0 ? -size : size;
}
private static class FloatIteratorImpl extends FloatIterator {
private float next;
private final float end;
private final float increment;
public FloatIteratorImpl(float start, float end, float increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public float nextFloat() {
float value = next;
next += increment;
return value;
}
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2013 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 jet;
class FloatSequenceIterator extends FloatIterator {
private float next;
private final float end;
private final float increment;
public FloatSequenceIterator(float start, float end, float increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public float nextFloat() {
float value = next;
next += increment;
return value;
}
}
+3 -27
View File
@@ -81,9 +81,9 @@ public final class IntRange implements Range<Integer>, IntIterable {
public IntIterator step(int step) {
if (step < 0)
return new IntIteratorImpl(getEnd(), getStart(), step);
return new IntSequenceIterator(getEnd(), getStart(), step);
else
return new IntIteratorImpl(getStart(), getEnd(), step);
return new IntSequenceIterator(getStart(), getEnd(), step);
}
public int getStart() {
@@ -100,30 +100,6 @@ public final class IntRange implements Range<Integer>, IntIterable {
@Override
public IntIterator iterator() {
return new IntIteratorImpl(getStart(), getEnd(), 1);
}
private static class IntIteratorImpl extends IntIterator {
private int next;
private final int end;
private final int increment;
public IntIteratorImpl(int start, int end, int increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public int nextInt() {
int value = next;
next += increment;
return value;
}
return new IntSequenceIterator(getStart(), getEnd(), 1);
}
}
+41
View File
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2013 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 jet;
class IntSequenceIterator extends IntIterator {
private int next;
private final int end;
private final int increment;
public IntSequenceIterator(int start, int end, int increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public int nextInt() {
int value = next;
next += increment;
return value;
}
}
+3 -27
View File
@@ -82,9 +82,9 @@ public final class LongRange implements Range<Long>, LongIterable {
public LongIterator step(long step) {
if (step < 0)
return new LongIteratorImpl(getEnd(), getStart(), step);
return new LongSequenceIterator(getEnd(), getStart(), step);
else
return new LongIteratorImpl(getStart(), getEnd(), step);
return new LongSequenceIterator(getStart(), getEnd(), step);
}
public long getStart() {
@@ -101,30 +101,6 @@ public final class LongRange implements Range<Long>, LongIterable {
@Override
public LongIterator iterator() {
return new LongIteratorImpl(getStart(), getEnd(), 1);
}
private static class LongIteratorImpl extends LongIterator {
private long next;
private final long end;
private final long increment;
public LongIteratorImpl(long start, long end, long increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public long nextLong() {
long value = next;
next += increment;
return value;
}
return new LongSequenceIterator(getStart(), getEnd(), 1);
}
}
+41
View File
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2013 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 jet;
class LongSequenceIterator extends LongIterator {
private long next;
private final long end;
private final long increment;
public LongSequenceIterator(long start, long end, long increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public long nextLong() {
long value = next;
next += increment;
return value;
}
}
+3 -27
View File
@@ -81,9 +81,9 @@ public final class ShortRange implements Range<Short>, ShortIterable {
public ShortIterator step(int step) {
if (step < 0)
return new ShortIteratorImpl(getEnd(), getStart(), step);
return new ShortSequenceIterator(getEnd(), getStart(), step);
else
return new ShortIteratorImpl(getStart(), getEnd(), step);
return new ShortSequenceIterator(getStart(), getEnd(), step);
}
public short getStart() {
@@ -100,30 +100,6 @@ public final class ShortRange implements Range<Short>, ShortIterable {
@Override
public ShortIterator iterator() {
return new ShortIteratorImpl(getStart(), getEnd(), 1);
}
private static class ShortIteratorImpl extends ShortIterator {
private short next;
private final short end;
private final int increment;
public ShortIteratorImpl(short start, short end, int increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public short nextShort() {
short value = next;
next += increment;
return value;
}
return new ShortSequenceIterator(getStart(), getEnd(), 1);
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2013 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 jet;
class ShortSequenceIterator extends ShortIterator {
private short next;
private final short end;
private final int increment;
public ShortSequenceIterator(short start, short end, int increment) {
this.next = start;
this.end = end;
this.increment = increment;
}
@Override
public boolean hasNext() {
return increment > 0 ? next <= end : next >= end;
}
@Override
public short nextShort() {
short value = next;
next += increment;
return value;
}
}