package com.jaregu.database.queries.ext;

import static com.jaregu.database.queries.ext.OrderBy.empty;

import java.util.List;

import com.jaregu.database.queries.dialect.Orderable;

public interface OrderableSearch extends Orderable {

	OrderBy getOrderBy();

	void setOrderBy(OrderBy properties);

	default boolean hasSortProperties() {
		return getOrderBy() != null && !getOrderBy().isEmpty();
	}

	@Override
	default List<String> getOrderByItems() {
		return getOrderBy().getOrderByItems();
	}

	default void clearSortProperties() {
		setOrderBy(empty());
	}

	default void addSortProperty(OrderByProperty property) {
		setOrderBy((getOrderBy() != null ? getOrderBy() : empty()).add(property));
	}

	default void addSort(String property) {
		setOrderBy((getOrderBy() != null ? getOrderBy() : empty()).add(property));
	}

	default void addSortAsc(String property) {
		setOrderBy((getOrderBy() != null ? getOrderBy() : empty()).addAsc(property));
	}

	default void addSortDesc(String property) {
		setOrderBy((getOrderBy() != null ? getOrderBy() : empty()).addDesc(property));
	}
}

@@ -97,16 +97,46 @@
 empty;%0A%0A
+import java.util.Collections;%0A
 import j
@@ -502,24 +502,73 @@
 By()
-.getOrderByItems
+ != null ? getOrderBy().getOrderByItems() : Collections.emptyList
 ();%0A

Fix NPE possibility