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

com.nhl.link.rest.client.protocol.LrcEntityRequest Maven / Gradle / Ivy

There is a newer version: 2.13
Show newest version
package com.nhl.link.rest.client.protocol;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * A base superlcass of representations of either a root entity request or an
 * entity subrequest.
 * 
 * @since 2.0
 */
public abstract class LrcEntityRequest {

	protected Expression cayenneExp;
	protected Map orderingMap;
	protected long start;
	protected long limit;

	public Optional getCayenneExp() {
		return Optional.ofNullable(cayenneExp);
	}

	public Collection getOrderings() {
		return orderingMap == null ? Collections.emptyList() : orderingMap.values();
	}

	public Optional getLimit() {
		return limit > 0 ? Optional.of(limit) : Optional.empty();
	}

	public Optional getStart() {
		return start > 0 ? Optional.of(start) : Optional.empty();
	}

	protected void setStart(long start) {
		this.start = start;
	}

	protected void setLimit(long limit) {
		this.limit = limit;
	}

	protected void addOrderings(Sort... orderings) {

		if (orderings != null) {
			for (Sort o : orderings) {
				addOrdering(o.getPropertyName(), o);
			}
		}
	}

	protected void addOrdering(String property, Sort sort) {

		if (orderingMap == null) {
			orderingMap = new HashMap<>();
		}
		orderingMap.put(property, sort);
	}

	protected void setCayenneExp(Expression cayenneExp) {
		this.cayenneExp = cayenneExp;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy