Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create the common interface HasProperties to unify access to properies #908

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:artifactId: neo4j-cypher-dsl

// This will be next version and also the one that will be put into the manual for the main branch
:neo4j-cypher-dsl-version: 2024.0.3-SNAPSHOT
:neo4j-cypher-dsl-version: 2024.1.0-SNAPSHOT
// This is the latest released version, used only in the readme
:neo4j-cypher-dsl-version-latest: 2024.0.2

Expand Down
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, PropertyAccessor {

/**
* Creates a condition that checks whether this {@code expression} includes all elements of {@code rhs}.
Expand Down Expand Up @@ -482,19 +482,29 @@ 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);
}

/**
* 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 2024.1.0
*/
@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,76 @@
/*
* 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 has properties.
*
* @author Andreas Berger
* @author Michael J. Simons
* @since 2024.1.0
*/
@API(status = STABLE, since = "2024.1.0")
public interface PropertyAccessor {

/**
* Creates a new {@link Property} associated with this element. This property can be used as a lookup in
* other expressions. It does not add a value to the property.
* <p>
* Note: The element 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 element
*/
@NotNull @Contract(pure = true)
default Property property(@NotNull String name) {
return property(new String[] { name });
}

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

/**
* Creates a new {@link Property} associated with this element. 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 element 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 element
*/
@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, PropertyAccessor {

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