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

io.odysz.transact.sql.parts.select.OrderyList Maven / Gradle / Ivy

package io.odysz.transact.sql.parts.select;

import java.util.ArrayList;
import java.util.stream.Collectors;

import io.odysz.semantics.ISemantext;
import io.odysz.transact.sql.parts.AbsPart;


public class OrderyList extends AbsPart {
	private ArrayList orders;

	public OrderyList(ArrayList orderList) {
		orders = orderList;
	}

	@Override
	public String sql(ISemantext sctx) {
		return orders.stream().map(e -> parse(e))
				.filter(e -> e != null)
				.collect(Collectors.joining(", ", "order by ", ""));
	}
	
	protected String parse(String[] orderby) {
		if (orderby.length > 1 && orderby[1] != null)
			return orderby[0] + " " + asc(orderby[1]);
		else return orderby[0] + " asc";
	}

	private String asc(String asc) {
		return asc != null && asc.toLowerCase().trim().equals("desc") ?
				"desc" : "asc";
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy