All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jaregu.database.queries.ext.OrderBy Maven / Gradle / Ivy

Go to download

Java based SQL templating project. Store your queries in *.sql files and build queries for execution. Supports simple expressions and conditional clauses and interface proxying for java-sql bridge.

There is a newer version: 1.4.1
Show newest version
package com.jaregu.database.queries.ext;

import java.util.AbstractList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class OrderBy {

	public static OrderByList empty() {
		return new OrderByList(Collections.emptyList());
	}

	public static OrderByList of(List orderByItems) {
		return new OrderByList(orderByItems);
	}

	public static OrderByList asc(String property) {
		return new OrderByList(Collections.singletonList(property));
	}

	public static OrderByList desc(String property) {
		return new OrderByList(Collections.singletonList(property));
	}

	public static class OrderByList extends AbstractList implements List {

		private List orderByItems;

		public OrderByList(List orderByItems) {
			this.orderByItems = Collections.unmodifiableList(orderByItems);
		}

		public OrderByList asc(String property) {
			return with(property);
		}

		public OrderByList desc(String property) {
			return with(property + " " + SortOrder.DESC);
		}

		private OrderByList with(String property) {
			return new OrderByList(
					Stream.concat(orderByItems.stream(), Stream.of(property)).collect(Collectors.toList()));
		}

		@Override
		public String get(int index) {
			return orderByItems.get(index);
		}

		@Override
		public int size() {
			return orderByItems.size();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy