public static AnyValue reverse( AnyValue original ) { if ( original instanceof TextValue ) { return ((TextValue) original).reverse(); } else if ( original instanceof ListValue ) { return ((ListValue) original).reverse(); } else { throw new CypherTypeException( "Expected a string or a list; consider converting it to a string with toString() or creating a list.", null ); } }
@Test void shouldHandleEmptyList() { // Given ListValue inner = EMPTY_LIST; // When ListValue reverse = inner.reverse(); // Then assertEquals( inner, reverse ); assertEquals( inner.hashCode(), reverse.hashCode() ); assertArrayEquals( inner.asArray(), reverse.asArray() ); }
@Test void shouldHandleSingleItemList() { // Given ListValue inner = list( longValue( 5L ) ); // When ListValue reverse = inner.reverse(); // Then assertEquals( inner, reverse ); assertEquals( inner.hashCode(), reverse.hashCode() ); assertArrayEquals( inner.asArray(), reverse.asArray() ); }
@Test void shouldReverseList() { // Given ListValue inner = list( longValue( 5L ), longValue( 6L ), longValue( 7L ) ); // When ListValue reverse = inner.reverse(); // Then ListValue expected = list( longValue( 7L ), longValue( 6L ), longValue( 5L ) ); assertEquals( expected, reverse ); assertEquals( expected.hashCode(), reverse.hashCode() ); assertArrayEquals( expected.asArray(), reverse.asArray() ); } }
public static AnyValue reverse( AnyValue original ) { if ( original instanceof TextValue ) { return ((TextValue) original).reverse(); } else if ( original instanceof ListValue ) { return ((ListValue) original).reverse(); } else { throw new CypherTypeException( "Expected a string or a list; consider converting it to a string with toString() or creating a list.", null ); } }