001/*
002 * Copyright 2010-2013 JetBrains s.r.o.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package jet;
018
019import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
020
021@AssertInvisibleInResolver
022public final class FloatRange implements Range<Float>, Progression<Float> {
023    public static final FloatRange EMPTY = new FloatRange(1, 0);
024
025    private final float start;
026    private final float end;
027
028    public FloatRange(float start, float end) {
029        this.start = start;
030        this.end = end;
031    }
032
033    @Override
034    public boolean contains(Float item) {
035        return start <= item && item <= end;
036    }
037
038    public boolean contains(float item) {
039        return start <= item && item <= end;
040    }
041
042    @Override
043    public Float getStart() {
044        return start;
045    }
046
047    @Override
048    public Float getEnd() {
049        return end;
050    }
051
052    @Override
053    public Float getIncrement() {
054        return 1.0f;
055    }
056
057    @Override
058    public FloatIterator iterator() {
059        return new FloatProgressionIterator(start, end, 1);
060    }
061
062    @Override
063    public String toString() {
064        return start + ".." + end;
065    }
066
067    @Override
068    public boolean equals(Object o) {
069        if (this == o) {
070            return true;
071        }
072        if (o == null || getClass() != o.getClass()) {
073            return false;
074        }
075
076        FloatRange range = (FloatRange) o;
077
078        return Float.compare(range.end, end) == 0 && Float.compare(range.start, start) == 0;
079    }
080
081    @Override
082    public int hashCode() {
083        int result = (start != +0.0f ? Float.floatToIntBits(start) : 0);
084        result = 31 * result + (end != +0.0f ? Float.floatToIntBits(end) : 0);
085        return result;
086    }
087}