UNPKG

@sap/odata-v4

Version:

OData V4.0 server library

165 lines (147 loc) 4.52 kB
'use strict'; /** * Aggregate expression. * @hideconstructor */ class AggregateExpression { constructor() { this._pathSegments = []; this._expression = null; this._standardMethod = null; this._customMethod = null; this._alias = null; this._inlineAggregateExpression = null; this._from = []; } /** * Returns the path prefix and the path segment. * @returns {UriResource[]} a potentially empty Array of path segments (and never <code>null</code>) */ getPathSegments() { return this._pathSegments; } /** * Sets the path prefix and the path segment. * @param {UriResource[]} pathSegments path segments * @returns {AggregateExpression} this aggregate expression * @package */ setPathSegments(pathSegments) { this._pathSegments = pathSegments; return this; } /** * Returns the common expression to be aggregated. * @returns {?Expression} the expression */ getExpression() { return this._expression; } /** * Sets the common expression to be aggregated. * @param {Expression} expression the expression * @returns {AggregateExpression} this aggregate expression * @package */ setExpression(expression) { this._expression = expression; return this; } /** * Returns the standard aggregation method if used. * @returns {?AggregateExpression.StandardMethod} the standard aggregation method or <code>null</code> */ getStandardMethod() { return this._standardMethod; } /** * Sets the standard aggregation method. * @param {AggregateExpression.StandardMethod} standardMethod the standard aggregation method * @returns {AggregateExpression} this aggregate expression * @package */ setStandardMethod(standardMethod) { this._standardMethod = standardMethod; return this; } /** * Returns the name of the custom aggregation method if used. * @returns {?FullQualifiedName} the qualified name of the custom aggregation method or <code>null</code> */ getCustomMethod() { return this._customMethod; } /** * Sets the custom aggregation method. * @param {FullQualifiedName} customMethod the custom aggregation method * @returns {AggregateExpression} this aggregate expression * @package */ setCustomMethod(customMethod) { this._customMethod = customMethod; return this; } /** * Returns the name of the aggregate if an alias name has been set. * @returns {?string} an identifier or <code>null</code> */ getAlias() { return this._alias; } /** * Sets the alias name. * @param {?string} alias the alias name * @returns {AggregateExpression} this aggregate expression * @package */ setAlias(alias) { this._alias = alias; return this; } /** * Returns the inline aggregation expression to be applied to the target of the path if used. * @returns {?AggregateExpression} an aggregation expression or <code>null</code> */ getInlineAggregateExpression() { return this._inlineAggregateExpression; } /** * Sets the inline aggregation expression. * @param {AggregateExpression} aggregateExpression the inline aggregation expression * @returns {AggregateExpression} this aggregate expression * @package */ setInlineAggregateExpression(aggregateExpression) { this._inlineAggregateExpression = aggregateExpression; return this; } /** * Returns the aggregate expressions for <code>from</code>. * @returns {AggregateExpression[]} a (potentially empty) list of aggregate expressions (but never <code>null</code>) */ getFrom() { return this._from; } /** * Add an aggregate expression to <code>from</code>. * @param {AggregateExpression} aggregateExpression the aggregate expression to add * @returns {AggregateExpression} this aggregate expression * @package */ addFrom(aggregateExpression) { this._from.push(aggregateExpression); return this; } } /** Standard aggregation method. * @enum {number} * @readonly */ AggregateExpression.StandardMethod = { SUM: 0, MIN: 1, MAX: 2, AVERAGE: 3, COUNT_DISTINCT: 4 }; module.exports = AggregateExpression;