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

com.sap.cds.ql.cqn.CqnReference Maven / Gradle / Ivy

There is a newer version: 3.8.0
Show newest version
/************************************************************************
 * © 2019-2023 SAP SE or an SAP affiliate company. All rights reserved. *
 ************************************************************************/
package com.sap.cds.ql.cqn;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.sap.cds.JSONizable;

public interface CqnReference extends CqnToken {

	/**
	 * Returns the segments of this ref.
	 *
	 * @return the ref segments
	 */
	List segments();

	default Stream stream() {
		return segments().stream();
	}

	default String path() {
		return stream().map(Segment::id).collect(Collectors.joining("."));
	}

	default int size() {
		return segments().size();
	}

	Optional alias();

	/**
	 * Returns the first segment of this ref.
	 *
	 * @return the first segment
	 */
	default Segment rootSegment() {
		return segments().get(0);
	}

	/**
	 * Returns the last segment of this ref.
	 *
	 * @return the last segment
	 */
	default Segment targetSegment() {
		return segments().get(size() - 1);
	}

	default String firstSegment() {
		return rootSegment().id();
	}

	default String lastSegment() {
		return targetSegment().id();
	}

	interface Segment extends JSONizable {

		Optional filter();

		String id();

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy