Skip to content

Commit

Permalink
Create the common interface HasProperties to unify access to proper…
Browse files Browse the repository at this point in the history
…ties
  • Loading branch information
Andy2003 committed Jan 26, 2024
1 parent c21dd25 commit 91857ac
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final Property property(String... names) {

@NotNull
@Override
public final Property property(Expression lookup) {
public final Property property(@NotNull Expression lookup) {
return InternalPropertyImpl.create(this, lookup);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @since 1.0
*/
@API(status = STABLE, since = "1.0")
public interface Expression extends Visitable {
public interface Expression extends Visitable, HasProperties {

/**
* Creates a condition that checks whether this {@code expression} includes all elements of {@code rhs}.
Expand Down Expand Up @@ -482,19 +482,34 @@ default SortItem sorted(SortItem.Direction direction) {
return SortItem.create(this, direction);
}

/**
* Assumes that this expressions refers to a container of some type allowing to reference properties from it.
* Note: The expression does not track property creation and there is no possibility to enumerate all properties
* that have been created for it.
*
* @param names At least one non empty name. If multiple names are specified, the expression creates a nested property like {@code this.name1.name2}.
*
* @return a new {@link Property} associated with this expression
* @since 2021.0.0
*/
@NotNull @Contract(pure = true)
@Override @NotNull
default Property property(String... names) {

return InternalPropertyImpl.create(this, names);
}

@Override @NotNull
default Property property(@NotNull String name) {
return InternalPropertyImpl.create(this, name);
}

/**
* Creates a new {@link Property} associated with this property container. This property can be used as a lookup in
* other expressions. It does not add a value to the property.
* <p>
* The new {@link Property} object is a dynamic lookup, based on the {@code expression} passed to this method. The
* expression can be example another property, a function result or a Cypher parameter. A property defined in such a way will
* render as {@code p[expression]}.
* <p>
* Note: The property container does not track property creation and there is no possibility to enumerate all
* properties that have been created for this property container.
*
* @param lookup the expression that is evaluated to lookup this property.
* @return a new {@link Property} associated with this named container
* @since 2023.9.4
*/
@Override @NotNull
default Property property(@NotNull Expression lookup) {
return InternalPropertyImpl.create(this, lookup);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2019-2024 "Neo4j,"
* Neo4j Sweden AB [https://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.cypherdsl.core;

import static org.apiguardian.api.API.Status.STABLE;

import org.apiguardian.api.API;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

/**
* This interface represents an element that can be for example an identifiable part of the {@code WITH} clause.
* It has been introduced to circumvent the absence of union types in Java
* and to avoid an overload of {@link StatementBuilder#with(String...)} or other expressions with an {@code Object...}
* parameter. This type here allows passing {@link Named named things}. {@link AliasedExpression aliased expression},
* {@link SymbolicName symobolic names} into a pipeline.
* <p>
* There should be no need to implement this on your own.
*
* @author Andreas Berger
* @since 2023.9.4
*/
@API(status = STABLE, since = "2023.9.4")
public interface HasProperties {

/**
* Creates a new {@link Property} associated with this property container. This property can be used as a lookup in
* other expressions. It does not add a value to the property.
* <p>
* Note: The property container does not track property creation and there is no possibility to enumerate all
* properties that have been created for this property container.
*
* @param name property name, must not be {@literal null} or empty.
* @return a new {@link Property} associated with this named container
* @since 2023.9.4
*/
@NotNull @Contract(pure = true)
Property property(@NotNull String name);

/**
* @param names a list of nested property names
* @return a new {@link Property} associated with this named container
* @see #property(String)
* @since 2023.9.4
*/
@NotNull @Contract(pure = true)
Property property(String... names);

/**
* Creates a new {@link Property} associated with this property container. This property can be used as a lookup in
* other expressions. It does not add a value to the property.
* <p>
* The new {@link Property} object is a dynamic lookup, based on the {@code expression} passed to this method. The
* expression can be example another property, a function result or a Cypher parameter. A property defined in such a way will
* render as {@code p[expression]}.
* <p>
* Note: The property container does not track property creation and there is no possibility to enumerate all
* properties that have been created for this property container.
*
* @param lookup the expression that is evaluated to lookup this property.
* @return a new {@link Property} associated with this named container
* @since 2023.9.4
*/
@NotNull @Contract(pure = true)
Property property(@NotNull Expression lookup);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,46 +35,7 @@
* @since 1.1
*/
@API(status = STABLE, since = "1.1")
public interface PropertyContainer extends Named {

/**
* Creates a new {@link Property} associated with this property container. This property can be used as a lookup in
* other expressions. It does not add a value to the property.
* <p>
* Note: The property container does not track property creation and there is no possibility to enumerate all
* properties that have been created for this property container.
*
* @param name property name, must not be {@literal null} or empty.
* @return a new {@link Property} associated with this named container
*/
@NotNull @Contract(pure = true)
Property property(@NotNull String name);

/**
* @param names a list of nested property names
* @return a new {@link Property} associated with this named container
* @see #property(String)
*/
@NotNull @Contract(pure = true)
Property property(String... names);

/**
* Creates a new {@link Property} associated with this property container. This property can be used as a lookup in
* other expressions. It does not add a value to the property.
* <p>
* The new {@link Property} object is a dynamic lookup, based on the {@code expression} passed to this method. The
* expression can be example another property, a function result or a Cypher parameter. A property defined in such a way will
* render as {@code p[expression]}.
* <p>
* Note: The property container does not track property creation and there is no possibility to enumerate all
* properties that have been created for this property container.
*
* @param lookup the expression that is evaluated to lookup this property.
* @return a new {@link Property} associated with this named container
* @since 2021.0.0
*/
@NotNull @Contract(pure = true)
Property property(Expression lookup);
public interface PropertyContainer extends Named, HasProperties {

/**
* Creates an {@link Operation} mutating the properties of this container to a new value. The container does not
Expand Down

0 comments on commit 91857ac

Please sign in to comment.