Introduced sequence classes.

This commit is contained in:
Evgeny Gerashchenko
2013-01-22 23:17:39 +04:00
parent abe7ca21bf
commit 4736b8d6e7
9 changed files with 481 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
/*
* 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;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
@AssertInvisibleInResolver
public class ByteSequence implements NumberSequence<Byte> {
private final byte start;
private final byte end;
private final int increment;
public ByteSequence(byte start, byte end, int increment) {
if (increment == 0) {
throw new IllegalArgumentException("Increment must be non-zero: " + increment);
}
this.start = start;
this.end = end;
this.increment = increment;
}
@Override
public Byte getStart() {
return start;
}
@Override
public Byte getEnd() {
return end;
}
@Override
public Integer getIncrement() {
return increment;
}
@Override
public ByteIterator iterator() {
return new ByteSequenceIterator(start, end, increment);
}
}
+55
View File
@@ -0,0 +1,55 @@
/*
* 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;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
@AssertInvisibleInResolver
public class CharacterSequence implements NumberSequence<Character> {
private final char start;
private final char end;
private final int increment;
public CharacterSequence(char start, char end, int increment) {
if (increment == 0) {
throw new IllegalArgumentException("Increment must be non-zero: " + increment);
}
this.start = start;
this.end = end;
this.increment = increment;
}
@Override
public Character getStart() {
return start;
}
@Override
public Character getEnd() {
return end;
}
@Override
public Integer getIncrement() {
return increment;
}
@Override
public CharIterator iterator() {
return new CharacterSequenceIterator(start, end, increment);
}
}
+55
View File
@@ -0,0 +1,55 @@
/*
* 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;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
@AssertInvisibleInResolver
public class DoubleSequence implements NumberSequence<Double> {
private final double start;
private final double end;
private final double increment;
public DoubleSequence(double start, double end, double increment) {
if (increment == 0.0 || increment == -0.0) {
throw new IllegalArgumentException("Increment must be non-zero: " + increment);
}
this.start = start;
this.end = end;
this.increment = increment;
}
@Override
public Double getStart() {
return start;
}
@Override
public Double getEnd() {
return end;
}
@Override
public Double getIncrement() {
return increment;
}
@Override
public DoubleIterator iterator() {
return new DoubleSequenceIterator(start, end, increment);
}
}
+55
View File
@@ -0,0 +1,55 @@
/*
* 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;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
@AssertInvisibleInResolver
public class FloatSequence implements NumberSequence<Float> {
private final float start;
private final float end;
private final float increment;
public FloatSequence(float start, float end, float increment) {
if (increment == 0.0f || increment == -0.0f) {
throw new IllegalArgumentException("Increment must be non-zero: " + increment);
}
this.start = start;
this.end = end;
this.increment = increment;
}
@Override
public Float getStart() {
return start;
}
@Override
public Float getEnd() {
return end;
}
@Override
public Float getIncrement() {
return increment;
}
@Override
public FloatIterator iterator() {
return new FloatSequenceIterator(start, end, increment);
}
}
+55
View File
@@ -0,0 +1,55 @@
/*
* 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;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
@AssertInvisibleInResolver
public class IntSequence implements NumberSequence<Integer> {
private final int start;
private final int end;
private final int increment;
public IntSequence(int start, int end, int increment) {
if (increment == 0) {
throw new IllegalArgumentException("Increment must be non-zero: " + increment);
}
this.start = start;
this.end = end;
this.increment = increment;
}
@Override
public Integer getStart() {
return start;
}
@Override
public Integer getEnd() {
return end;
}
@Override
public Integer getIncrement() {
return increment;
}
@Override
public IntIterator iterator() {
return new IntSequenceIterator(start, end, increment);
}
}
+55
View File
@@ -0,0 +1,55 @@
/*
* 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;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
@AssertInvisibleInResolver
public class LongSequence implements NumberSequence<Long> {
private final long start;
private final long end;
private final long increment;
public LongSequence(long start, long end, long increment) {
if (increment == 0) {
throw new IllegalArgumentException("Increment must be non-zero: " + increment);
}
this.start = start;
this.end = end;
this.increment = increment;
}
@Override
public Long getStart() {
return start;
}
@Override
public Long getEnd() {
return end;
}
@Override
public Long getIncrement() {
return increment;
}
@Override
public LongIterator iterator() {
return new LongSequenceIterator(start, end, increment);
}
}
+26
View File
@@ -0,0 +1,26 @@
/*
* 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;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
@AssertInvisibleInResolver
public interface NumberSequence<N> extends Iterable<N> {
N getStart();
N getEnd();
Number getIncrement();
}
+55
View File
@@ -0,0 +1,55 @@
/*
* 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;
import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
@AssertInvisibleInResolver
public class ShortSequence implements NumberSequence<Short> {
private final short start;
private final short end;
private final int increment;
public ShortSequence(short start, short end, int increment) {
if (increment == 0) {
throw new IllegalArgumentException("Increment must be non-zero: " + increment);
}
this.start = start;
this.end = end;
this.increment = increment;
}
@Override
public Short getStart() {
return start;
}
@Override
public Short getEnd() {
return end;
}
@Override
public Integer getIncrement() {
return increment;
}
@Override
public ShortIterator iterator() {
return new ShortSequenceIterator(start, end, increment);
}
}