many changes
This commit is contained in:
@@ -1,34 +1,61 @@
|
||||
public class Tuple2<T1, T2> {
|
||||
import java.util.Objects;
|
||||
import be.kuleuven.cs.som.annotate.*;
|
||||
|
||||
|
||||
/**
|
||||
* A tuple implementation
|
||||
*
|
||||
* @param <T1> first element type
|
||||
* @param <T2> second element type
|
||||
*
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Arthur Bols & Leen Dereu
|
||||
*/
|
||||
@Value
|
||||
public class Tuple<T1, T2> {
|
||||
|
||||
|
||||
public final T1 item1;
|
||||
public final T2 item2;
|
||||
|
||||
public Tuple2(T1 x, T2 y) {
|
||||
this.item1 = x;
|
||||
this.item2 = y;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param item1
|
||||
* The first element for this tuple
|
||||
* @param item2
|
||||
* The second element for this tuple
|
||||
*/
|
||||
private Tuple(T1 item1, T2 item2) {
|
||||
|
||||
if (item1 == null)
|
||||
throw new IllegalArgumentException("item1 may not be null");
|
||||
if (item2 == null)
|
||||
throw new IllegalArgumentException("item2 may not be null");
|
||||
|
||||
this.item1 = item1;
|
||||
this.item2 = item2;
|
||||
}
|
||||
|
||||
@Immutable
|
||||
public static <T1, T2> Tuple<T1, T2> create(T1 item1, T2 item2){
|
||||
return new Tuple<>(item1, item2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof Tuple2))
|
||||
return false;
|
||||
final Tuple2<?, ?> other = (Tuple2<?, ?>) obj;
|
||||
if (_1 == null) {
|
||||
if (other._1 != null)
|
||||
return false;
|
||||
} else if (!_1.equals(other._1))
|
||||
return false;
|
||||
if (_2 == null) {
|
||||
if (other._2 != null)
|
||||
return false;
|
||||
} else if (!_2.equals(other._2))
|
||||
return false;
|
||||
return true;
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Tuple)) return false;
|
||||
Tuple<?, ?> tuple = (Tuple<?, ?>) o;
|
||||
return Objects.equals(item1, tuple.item1) &&
|
||||
Objects.equals(item2, tuple.item2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(item1, item2);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user