# Class FeatureQuery.NamedExpression

Object
NamedExpression

All Implemented Interfaces:
  `Serializable`

Enclosing class:
  `FeatureQuery`

public static final class FeatureQuery.NamedExpression extends Object implements Serializable
An expression to be retrieved by a `Query`, together with the name to assign to it. `NamedExpression` specifies also if the expression should be evaluated exactly once and its value stored, or evaluated every times that the value is requested.

## Analogy with relational databases

A `NamedExpression` instance can be understood as the definition of a column in a SQL database table. In relational database terminology, subset of columns is called projection. A projection is specified by a SQL `SELECT` statement, which maps to `NamedExpression` as below:

`SELECT` `expression` `AS` `alias`

Columns can be given to the `FeatureQuery​.setProjection(NamedExpression[])` method.

Since:
  1.1
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NamedExpression(Expression<? super AbstractFeature, ?> expression)`
  Creates a new stored column with the given expression and no name.
  `NamedExpression(Expression<? super AbstractFeature, ?> expression, String alias)`
  Creates a new stored column with the given expression and the given name.
  `NamedExpression(Expression<? super AbstractFeature, ?> expression, GenericName alias)`
  Creates a new stored column with the given expression and the given name.
  `NamedExpression(Expression<? super AbstractFeature, ?> expression, GenericName alias, FeatureQuery​.ProjectionType type)`
  Creates a new column with the given expression, the given name and the given projection type.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `GenericName`
  `alias()`
  The name to assign to the expression result, or `null` if unspecified.
  `boolean`
  `equals(Object obj)`
  Compares this column with the given object for equality.
  `Expression<? super AbstractFeature, ?>`
  `expression()`
  The literal, value reference or more complex expression to be retrieved by a `Query`.
  `int`
  `hashCode()`
  Returns a hash code value for this column.
  `String`
  `toString()`
  Returns a string representation of this column for debugging purpose.
  `FeatureQuery​.ProjectionType`
  `type()`
  Whether the expression result should be stored or evaluated every times that it is requested.

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### NamedExpression

    public NamedExpression(Expression<? super AbstractFeature, ?> expression)
    Creates a new stored column with the given expression and no name.
    Parameters:
      `expression` - the literal, value reference or expression to be retrieved by a `Query`.

  - ### NamedExpression

    public NamedExpression(Expression<? super AbstractFeature, ?> expression, GenericName alias)
    Creates a new stored column with the given expression and the given name.
    Parameters:
      `expression` - the literal, value reference or expression to be retrieved by a `Query`.
      `alias` - the name to assign to the expression result, or `null` if unspecified.

  - ### NamedExpression

    public NamedExpression(Expression<? super AbstractFeature, ?> expression, String alias)
    Creates a new stored column with the given expression and the given name. This constructor creates a `LocalName` from the given string.
    Parameters:
      `expression` - the literal, value reference or expression to be retrieved by a `Query`.
      `alias` - the name to assign to the expression result, or `null` if unspecified.

  - ### NamedExpression

    public NamedExpression(Expression<? super AbstractFeature, ?> expression, GenericName alias, FeatureQuery.ProjectionType type)
    Creates a new column with the given expression, the given name and the given projection type.
    Parameters:
      `expression` - the literal, value reference or expression to be retrieved by a `Query`.
      `alias` - the name to assign to the expression result, or `null` if unspecified.
      `type` - whether to create a feature `AbstractAttribute` or a feature
      invalid reference

          AbstractOperation

      .
    Since:
      1.4

- ## Method Details

  - ### expression

    public Expression<? super AbstractFeature, ?> expression()
    The literal, value reference or more complex expression to be retrieved by a `Query`. Never `null`.
    Returns:
      the expression (often a literal) for the value to retrieve.
    Since:
      1.5

  - ### alias

    public GenericName alias()
    The name to assign to the expression result, or `null` if unspecified.
    Returns:
      optional name for the expression result.
    Since:
      1.5

  - ### type

    public FeatureQuery.ProjectionType type()
    Whether the expression result should be stored or evaluated every times that it is requested. A stored value will exist as a feature
    invalid reference

        Attribute

    , while a virtual value will exist as a feature
    invalid reference

        Operation

    . The latter are commonly called "computed fields" and are equivalent to SQL `GENERATED ALWAYS` keyword for columns.
    Returns:
      the projection type (stored or computing).
    Since:
      1.5

  - ### hashCode

    public int hashCode()
    Returns a hash code value for this column.
    Overrides:
      `hashCode` in class `Object`
    Returns:
      a hash code value.

  - ### equals

    public boolean equals(Object obj)
    Compares this column with the given object for equality.
    Overrides:
      `equals` in class `Object`
    Parameters:
      `obj` - the object to compare with this column.
    Returns:
      whether the two objects are equal.

  - ### toString

    public String toString()
    Returns a string representation of this column for debugging purpose.
    Overrides:
      `toString` in class `Object`
    Returns:
      a string representation of this column.