From abe7ca21bf5f5e13131b046defe92d68f2c147a9 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 22 Jan 2013 22:54:15 +0400 Subject: [PATCH] Moved primitive iterators to upper level. --- runtime/src/jet/ByteRange.java | 30 ++------------ runtime/src/jet/ByteSequenceIterator.java | 41 +++++++++++++++++++ runtime/src/jet/CharRange.java | 30 ++------------ .../src/jet/CharacterSequenceIterator.java | 41 +++++++++++++++++++ runtime/src/jet/DoubleRange.java | 28 +------------ runtime/src/jet/DoubleSequenceIterator.java | 41 +++++++++++++++++++ runtime/src/jet/FloatRange.java | 28 +------------ runtime/src/jet/FloatSequenceIterator.java | 41 +++++++++++++++++++ runtime/src/jet/IntRange.java | 30 ++------------ runtime/src/jet/IntSequenceIterator.java | 41 +++++++++++++++++++ runtime/src/jet/LongRange.java | 30 ++------------ runtime/src/jet/LongSequenceIterator.java | 41 +++++++++++++++++++ runtime/src/jet/ShortRange.java | 30 ++------------ runtime/src/jet/ShortSequenceIterator.java | 41 +++++++++++++++++++ 14 files changed, 306 insertions(+), 187 deletions(-) create mode 100644 runtime/src/jet/ByteSequenceIterator.java create mode 100644 runtime/src/jet/CharacterSequenceIterator.java create mode 100644 runtime/src/jet/DoubleSequenceIterator.java create mode 100644 runtime/src/jet/FloatSequenceIterator.java create mode 100644 runtime/src/jet/IntSequenceIterator.java create mode 100644 runtime/src/jet/LongSequenceIterator.java create mode 100644 runtime/src/jet/ShortSequenceIterator.java diff --git a/runtime/src/jet/ByteRange.java b/runtime/src/jet/ByteRange.java index 3c391baba41..0fd53125f71 100644 --- a/runtime/src/jet/ByteRange.java +++ b/runtime/src/jet/ByteRange.java @@ -81,9 +81,9 @@ public final class ByteRange implements Range, 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, 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); } } diff --git a/runtime/src/jet/ByteSequenceIterator.java b/runtime/src/jet/ByteSequenceIterator.java new file mode 100644 index 00000000000..9abc993a5fa --- /dev/null +++ b/runtime/src/jet/ByteSequenceIterator.java @@ -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; + } +} diff --git a/runtime/src/jet/CharRange.java b/runtime/src/jet/CharRange.java index bae494ca70e..bd4935161dd 100644 --- a/runtime/src/jet/CharRange.java +++ b/runtime/src/jet/CharRange.java @@ -81,9 +81,9 @@ public final class CharRange implements Range, 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, 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); } } diff --git a/runtime/src/jet/CharacterSequenceIterator.java b/runtime/src/jet/CharacterSequenceIterator.java new file mode 100644 index 00000000000..0f23b279135 --- /dev/null +++ b/runtime/src/jet/CharacterSequenceIterator.java @@ -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; + } +} diff --git a/runtime/src/jet/DoubleRange.java b/runtime/src/jet/DoubleRange.java index 08f14c5c7b8..2f544f3bf30 100644 --- a/runtime/src/jet/DoubleRange.java +++ b/runtime/src/jet/DoubleRange.java @@ -79,9 +79,9 @@ public final class DoubleRange implements Range { 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 { 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; - } - } } diff --git a/runtime/src/jet/DoubleSequenceIterator.java b/runtime/src/jet/DoubleSequenceIterator.java new file mode 100644 index 00000000000..1a7e551e6f8 --- /dev/null +++ b/runtime/src/jet/DoubleSequenceIterator.java @@ -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; + } +} diff --git a/runtime/src/jet/FloatRange.java b/runtime/src/jet/FloatRange.java index 20ffd722c33..506d51ab17a 100644 --- a/runtime/src/jet/FloatRange.java +++ b/runtime/src/jet/FloatRange.java @@ -75,9 +75,9 @@ public final class FloatRange implements Range { 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 { 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; - } - } } diff --git a/runtime/src/jet/FloatSequenceIterator.java b/runtime/src/jet/FloatSequenceIterator.java new file mode 100644 index 00000000000..35bfac98c1f --- /dev/null +++ b/runtime/src/jet/FloatSequenceIterator.java @@ -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; + } +} diff --git a/runtime/src/jet/IntRange.java b/runtime/src/jet/IntRange.java index d426faac162..0a18e42ecab 100644 --- a/runtime/src/jet/IntRange.java +++ b/runtime/src/jet/IntRange.java @@ -81,9 +81,9 @@ public final class IntRange implements Range, 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, 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); } } diff --git a/runtime/src/jet/IntSequenceIterator.java b/runtime/src/jet/IntSequenceIterator.java new file mode 100644 index 00000000000..06e8c8e3229 --- /dev/null +++ b/runtime/src/jet/IntSequenceIterator.java @@ -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; + } +} diff --git a/runtime/src/jet/LongRange.java b/runtime/src/jet/LongRange.java index fa100fa3e84..ac0ef9462be 100644 --- a/runtime/src/jet/LongRange.java +++ b/runtime/src/jet/LongRange.java @@ -82,9 +82,9 @@ public final class LongRange implements Range, 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, 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); } } diff --git a/runtime/src/jet/LongSequenceIterator.java b/runtime/src/jet/LongSequenceIterator.java new file mode 100644 index 00000000000..dd63d0c62fa --- /dev/null +++ b/runtime/src/jet/LongSequenceIterator.java @@ -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; + } +} diff --git a/runtime/src/jet/ShortRange.java b/runtime/src/jet/ShortRange.java index 8153fd3e655..6767df8297b 100644 --- a/runtime/src/jet/ShortRange.java +++ b/runtime/src/jet/ShortRange.java @@ -81,9 +81,9 @@ public final class ShortRange implements Range, 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, 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); } } diff --git a/runtime/src/jet/ShortSequenceIterator.java b/runtime/src/jet/ShortSequenceIterator.java new file mode 100644 index 00000000000..23ec58f15bc --- /dev/null +++ b/runtime/src/jet/ShortSequenceIterator.java @@ -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; + } +}