Added equals, hashCode and toString to sequences.
This commit is contained in:
@@ -52,4 +52,36 @@ public class ByteSequence implements NumberSequence<Byte> {
|
||||
public ByteIterator iterator() {
|
||||
return new ByteSequenceIterator(start, end, increment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (increment > 0) {
|
||||
return start + ".." + end + " step " + increment;
|
||||
}
|
||||
else {
|
||||
return start + " downTo " + end + " step " + -increment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ByteSequence bytes = (ByteSequence) o;
|
||||
|
||||
if (end != bytes.end) return false;
|
||||
if (increment != bytes.increment) return false;
|
||||
if (start != bytes.start) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) start;
|
||||
result = 31 * result + (int) end;
|
||||
result = 31 * result + increment;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,4 +52,36 @@ public class CharacterSequence implements NumberSequence<Character> {
|
||||
public CharIterator iterator() {
|
||||
return new CharacterSequenceIterator(start, end, increment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (increment > 0) {
|
||||
return start + ".." + end + " step " + increment;
|
||||
}
|
||||
else {
|
||||
return start + " downTo " + end + " step " + -increment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
CharacterSequence that = (CharacterSequence) o;
|
||||
|
||||
if (end != that.end) return false;
|
||||
if (increment != that.increment) return false;
|
||||
if (start != that.start) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) start;
|
||||
result = 31 * result + (int) end;
|
||||
result = 31 * result + increment;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,4 +52,41 @@ public class DoubleSequence implements NumberSequence<Double> {
|
||||
public DoubleIterator iterator() {
|
||||
return new DoubleSequenceIterator(start, end, increment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (increment > 0) {
|
||||
return start + ".." + end + " step " + increment;
|
||||
}
|
||||
else {
|
||||
return start + " downTo " + end + " step " + -increment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
DoubleSequence doubles = (DoubleSequence) o;
|
||||
|
||||
if (Double.compare(doubles.end, end) != 0) return false;
|
||||
if (Double.compare(doubles.increment, increment) != 0) return false;
|
||||
if (Double.compare(doubles.start, start) != 0) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
temp = start != +0.0d ? Double.doubleToLongBits(start) : 0L;
|
||||
result = (int) (temp ^ (temp >>> 32));
|
||||
temp = end != +0.0d ? Double.doubleToLongBits(end) : 0L;
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = increment != +0.0d ? Double.doubleToLongBits(increment) : 0L;
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,4 +52,36 @@ public class FloatSequence implements NumberSequence<Float> {
|
||||
public FloatIterator iterator() {
|
||||
return new FloatSequenceIterator(start, end, increment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (increment > 0) {
|
||||
return start + ".." + end + " step " + increment;
|
||||
}
|
||||
else {
|
||||
return start + " downTo " + end + " step " + -increment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
FloatSequence floats = (FloatSequence) o;
|
||||
|
||||
if (Float.compare(floats.end, end) != 0) return false;
|
||||
if (Float.compare(floats.increment, increment) != 0) return false;
|
||||
if (Float.compare(floats.start, start) != 0) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (start != +0.0f ? Float.floatToIntBits(start) : 0);
|
||||
result = 31 * result + (end != +0.0f ? Float.floatToIntBits(end) : 0);
|
||||
result = 31 * result + (increment != +0.0f ? Float.floatToIntBits(increment) : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,4 +52,36 @@ public class IntSequence implements NumberSequence<Integer> {
|
||||
public IntIterator iterator() {
|
||||
return new IntSequenceIterator(start, end, increment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (increment > 0) {
|
||||
return start + ".." + end + " step " + increment;
|
||||
}
|
||||
else {
|
||||
return start + " downTo " + end + " step " + -increment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
IntSequence sequence = (IntSequence) o;
|
||||
|
||||
if (end != sequence.end) return false;
|
||||
if (increment != sequence.increment) return false;
|
||||
if (start != sequence.start) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = start;
|
||||
result = 31 * result + end;
|
||||
result = 31 * result + increment;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,4 +52,36 @@ public class LongSequence implements NumberSequence<Long> {
|
||||
public LongIterator iterator() {
|
||||
return new LongSequenceIterator(start, end, increment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (increment > 0) {
|
||||
return start + ".." + end + " step " + increment;
|
||||
}
|
||||
else {
|
||||
return start + " downTo " + end + " step " + -increment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
LongSequence longs = (LongSequence) o;
|
||||
|
||||
if (end != longs.end) return false;
|
||||
if (increment != longs.increment) return false;
|
||||
if (start != longs.start) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) (start ^ (start >>> 32));
|
||||
result = 31 * result + (int) (end ^ (end >>> 32));
|
||||
result = 31 * result + (int) (increment ^ (increment >>> 32));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,4 +52,36 @@ public class ShortSequence implements NumberSequence<Short> {
|
||||
public ShortIterator iterator() {
|
||||
return new ShortSequenceIterator(start, end, increment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (increment > 0) {
|
||||
return start + ".." + end + " step " + increment;
|
||||
}
|
||||
else {
|
||||
return start + " downTo " + end + " step " + -increment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ShortSequence shorts = (ShortSequence) o;
|
||||
|
||||
if (end != shorts.end) return false;
|
||||
if (increment != shorts.increment) return false;
|
||||
if (start != shorts.start) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (int) start;
|
||||
result = 31 * result + (int) end;
|
||||
result = 31 * result + increment;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user