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 ShortRange implements Range<Short>, Progression<Short> {
023 public static final ShortRange EMPTY = new ShortRange((short) 1, (short) 0);
024
025 private final short start;
026 private final short end;
027
028 public ShortRange(short start, short end) {
029 this.start = start;
030 this.end = end;
031 }
032
033 @Override
034 public boolean contains(Short item) {
035 return start <= item && item <= end;
036 }
037
038 public boolean contains(short item) {
039 return start <= item && item <= end;
040 }
041
042 @Override
043 public Short getStart() {
044 return start;
045 }
046
047 @Override
048 public Short getEnd() {
049 return end;
050 }
051
052 @Override
053 public Integer getIncrement() {
054 return 1;
055 }
056
057 @Override
058 public ShortIterator iterator() {
059 return new ShortProgressionIterator(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 ShortRange range = (ShortRange) o;
077 return end == range.end && start == range.start;
078 }
079
080 @Override
081 public int hashCode() {
082 int result = (int) start;
083 result = 31 * result + end;
084 return result;
085 }
086 }