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
017 package jet;
018
019 import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver;
020
021 @AssertInvisibleInResolver
022 public final class DoubleRange implements Range<Double>, Progression<Double> {
023 public static final DoubleRange EMPTY = new DoubleRange(1, 0);
024
025 private final double start;
026 private final double end;
027
028 public DoubleRange(double start, double end) {
029 this.start = start;
030 this.end = end;
031 }
032
033 @Override
034 public boolean contains(Double item) {
035 return start <= item && item <= end;
036 }
037
038 public boolean contains(double item) {
039 return start <= item && item <= end;
040 }
041
042 @Override
043 public Double getStart() {
044 return start;
045 }
046
047 @Override
048 public Double getEnd() {
049 return end;
050 }
051
052 @Override
053 public Double getIncrement() {
054 return 1.0;
055 }
056
057 @Override
058 public DoubleIterator iterator() {
059 return new DoubleProgressionIterator(start, end, 1.0);
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 DoubleRange range = (DoubleRange) o;
077
078 return Double.compare(range.end, end) == 0 && Double.compare(range.start, start) == 0;
079 }
080
081 @Override
082 public int hashCode() {
083 int result;
084 long temp;
085 temp = start != +0.0d ? Double.doubleToLongBits(start) : 0L;
086 result = (int) (temp ^ (temp >>> 32));
087 temp = end != +0.0d ? Double.doubleToLongBits(end) : 0L;
088 result = 31 * result + (int) (temp ^ (temp >>> 32));
089 return result;
090 }
091 }