public static <X, Y> Tuple<X, Y> create(X first, Y second) { return new Tuple<X, Y>(first, second); }
/** * Returns the values of the tuple, separated by commas, enclosed in parenthesis. Example: * <code>("Ace", "Spades")</code>. */ @Override public String toString() { StringBuilder builder = new StringBuilder("("); builder.append(String.valueOf(first)); builder.append(", "); builder.append(String.valueOf(second)); extendDescription(builder); return builder.append(')').toString(); }
/** * The heart of {@link #equals(Object)}; the other object is the same class as this object. * * @param other * other tuple to compare * @return true if all values stored in tuple match */ protected boolean isMatch(Object other) { Tuple<?, ?> tuple = (Tuple<?, ?>) other; return isEqual(first, tuple.first) && isEqual(second, tuple.second); } }
@Override public Tuple<Flow<A>, Flow<B>> unzip() { return Tuple.create(firsts(), seconds()); }
/** * Compares this Tuple to another object. Equality is defined by: other object is not null, * is same class as this Tuple, and all values are themselves equal. */ @Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || !(obj.getClass() == getClass())) return false; return isMatch(obj); }
@Test public void not_equal_anything_else() { assertFalse(t.equals("a string")); }
@Test public void tuple_to_string() { assertEquals(t.toString(), "(tapestry, 5)"); }
@Override public Tuple<Flow<A>, Flow<B>> unzip() { return Tuple.create(firsts(), seconds()); }
/** * Compares this Tuple to another object. Equality is defined by: other object is not null, * is same class as this Tuple, and all values are themselves equal. */ @Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || !(obj.getClass() == getClass())) return false; return isMatch(obj); }
@Test void identity_is_equal() { assertTrue(t.equals(t)); }
public static <X, Y> Tuple<X, Y> create(X first, Y second) { return new Tuple<X, Y>(first, second); }
/** * The heart of {@link #equals(Object)}; the other object is the same class as this object. * * @param other * other tuple to compare * @return true if all values stored in tuple match */ protected boolean isMatch(Object other) { Tuple<?, ?> tuple = (Tuple<?, ?>) other; return isEqual(first, tuple.first) && isEqual(second, tuple.second); } }
/** * Returns the values of the tuple, separated by commas, enclosed in parenthesis. Example: * <code>("Ace", "Spades")</code>. */ @Override public String toString() { StringBuilder builder = new StringBuilder("("); builder.append(String.valueOf(first)); builder.append(", "); builder.append(String.valueOf(second)); extendDescription(builder); return builder.append(')').toString(); }
@Test public void not_equal_null() { assertFalse(t.equals(null)); }
@Override public Tuple<String, String> map(Tuple<Integer, String> value) { return Tuple.create(StringUtils.reverse(value.second), String.format("%d-%d", value.first, value.second.length())); }
@Override public Tuple<A, B> get() { return new Tuple<A, B>(aFlow.first(), bFlow.first()); } }
@Test public void first_tuple_from_zipped_flow() { assertEquals(zipped.drop(2).first(), Tuple.create(3, "wilma")); }