This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new 61720baea CAY-2858 Redesign Collection and Map Property API
61720baea is described below

commit 61720baea923a627fcb29cbdeb280674c4be2e27
Author: Nikita Timofeev <[email protected]>
AuthorDate: Mon Jun 17 15:17:15 2024 +0400

    CAY-2858 Redesign Collection and Map Property API
---
 RELEASE-NOTES.txt                                  |   1 +
 .../cayenne/exp/property/CollectionProperty.java   | 121 +++++++++++++++++++--
 .../apache/cayenne/exp/property/MapProperty.java   |  83 ++++++++++++++
 .../cayenne/exp/property/ListPropertyTest.java     |  75 +++++++++++--
 .../cayenne/exp/property/MapPropertyTest.java      |  16 +--
 .../cayenne/exp/property/SetPropertyTest.java      |   2 +-
 6 files changed, 269 insertions(+), 29 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index f7769100d..e917a361f 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -71,6 +71,7 @@ CAY-2845 Deprecate DataObject in favour of Persistent
 CAY-2849 Switch documentation to `hugo-asciidoctorj-extension`
 CAY-2856 Upgrade Gradle to 8.8
 CAY-2857 Java 22 support
+CAY-2858 Redesign Collection and Map Property API
 
 Bug Fixes:
 
diff --git 
a/cayenne/src/main/java/org/apache/cayenne/exp/property/CollectionProperty.java 
b/cayenne/src/main/java/org/apache/cayenne/exp/property/CollectionProperty.java
index 8cd1e3103..53d4f75f7 100644
--- 
a/cayenne/src/main/java/org/apache/cayenne/exp/property/CollectionProperty.java
+++ 
b/cayenne/src/main/java/org/apache/cayenne/exp/property/CollectionProperty.java
@@ -65,42 +65,44 @@ public abstract class CollectionProperty<V extends 
Persistent, E extends Collect
 
     /**
      * @return An expression representing equality to a value.
+     * @deprecated since 5.0 in favour of {@link #containsValue(V)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression contains(V value) {
-        return ExpressionFactory.matchExp(getExpression(), value);
+        return containsValue(value);
     }
 
-
     /**
-     * @return An expression representing inequality to a value.
+     * @return An expression representing equality to a value.
+     * @deprecated since 5.0 in favour of {@link #notContainsValue(V)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression notContains(V value) {
-        return ExpressionFactory.noMatchExp(getExpression(), value);
+        return notContainsValue(value);
     }
 
-    // TODO: move all *contains* methods to RelationshipProperty once Property 
class is removed
-
     /**
      * @return An expression for finding objects with values in the given set.
+     * @deprecated since 5.0 in favour of {@link #containsValues(V...)}
      */
-    @SafeVarargs
-    public final Expression contains(V firstValue, V... moreValues) {
-
+    @SuppressWarnings("unchecked")
+    @Deprecated(since = "5.0", forRemoval = true)
+    public Expression contains(V firstValue, V... moreValues) {
         int moreValuesLength = moreValues != null ? moreValues.length : 0;
-
         Object[] values = new Object[moreValuesLength + 1];
         values[0] = firstValue;
 
         if (moreValuesLength > 0) {
             System.arraycopy(moreValues, 0, values, 1, moreValuesLength);
         }
-
         return ExpressionFactory.inExp(getExpression(), values);
     }
 
     /**
      * @return An expression for finding objects with values in the given set.
+     * @deprecated since 5.0 in favour of {@link 
#containsValuesCollection(Collection)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression contains(Collection<V> values) {
         return ExpressionFactory.inExp(getExpression(), values);
     }
@@ -115,7 +117,9 @@ public abstract class CollectionProperty<V extends 
Persistent, E extends Collect
 
     /**
      * @return An expression for finding objects with given id set
+     * @deprecated since 5.0 in favour of  {@link #containsIds(Object...)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression containsId(Object firstId, Object... moreId) {
 
         int moreValuesLength = moreId != null ? moreId.length : 0;
@@ -132,7 +136,9 @@ public abstract class CollectionProperty<V extends 
Persistent, E extends Collect
 
     /**
      * @return An expression for finding objects with given id set.
+     * @deprecated since 5.0 in favour of {@link 
#containsIdsCollection(Collection)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression containsId(Collection<Object> ids) {
         return ExpressionFactory.inExp(getExpression(), ids);
     }
@@ -147,7 +153,9 @@ public abstract class CollectionProperty<V extends 
Persistent, E extends Collect
 
     /**
      * @return An expression for finding objects without given id set.
+     * @deprecated since 5.0 in favour of {@link #notContainsIds(Object...)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression notContainsId(Object firstId, Object... moreId) {
 
         int moreValuesLength = moreId != null ? moreId.length : 0;
@@ -164,21 +172,27 @@ public abstract class CollectionProperty<V extends 
Persistent, E extends Collect
 
     /**
      * @return An expression for finding objects without given id set.
+     * @deprecated since 5.0 in favour of {@link 
#notContainsIdsCollection(Collection)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression notContainsId(Collection<Object> ids) {
         return ExpressionFactory.notInExp(getExpression(), ids);
     }
 
     /**
      * @return An expression for finding objects with values not in the given 
set.
+     * @deprecated since 5.0 in favour of {@link 
#notContainsValuesCollection(Collection)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression notContains(Collection<V> values) {
         return ExpressionFactory.notInExp(getExpression(), values);
     }
 
     /**
      * @return An expression for finding objects with values not in the given 
set.
+     * @deprecated since 5.0 in favour of {@link #notContainsValues(V...)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     @SafeVarargs
     public final Expression notContains(V firstValue, V... moreValues) {
 
@@ -194,6 +208,91 @@ public abstract class CollectionProperty<V extends 
Persistent, E extends Collect
         return ExpressionFactory.notInExp(getExpression(), values);
     }
 
+    /**
+     * @return An expression representing equality to a value.
+     * @since 5.0
+     */
+    public Expression containsValue(V value) {
+        return ExpressionFactory.matchExp(getExpression(), value);
+    }
+
+    /**
+     * @return An expression representing inequality to a value.
+     * @since 5.0
+     */
+    public Expression notContainsValue(V value) {
+        return ExpressionFactory.noMatchExp(getExpression(), value);
+    }
+
+    /**
+     * @return An expression for finding objects with values in the given set.
+     * @since 5.0
+     */
+    @SafeVarargs
+    public final Expression containsValues(V... values) {
+        if(values == null || values.length == 0) {
+            throw new IllegalArgumentException("At least one value is 
expected.");
+        }
+        return ExpressionFactory.inExp(getExpression(), (Object[])values);
+    }
+
+    /**
+     * @return An expression for finding objects with values in the given set.
+     * @since 5.0
+     */
+    public Expression containsValuesCollection(Collection<V> values) {
+        return ExpressionFactory.inExp(getExpression(), values);
+    }
+
+    /**
+     * @return An expression for finding objects with given id set
+     * @since 5.0
+     */
+    public Expression containsIds(Object... ids) {
+        return ExpressionFactory.inExp(getExpression(), ids);
+    }
+
+    /**
+     * @return An expression for finding objects with given id set.
+     * @since 5.0
+     */
+    public Expression containsIdsCollection(Collection<?> ids) {
+        return ExpressionFactory.inExp(getExpression(), ids);
+    }
+
+    /**
+     * @return An expression for finding objects with given id set
+     * @since 5.0
+     */
+    public Expression notContainsIds(Object... ids) {
+        return ExpressionFactory.notInExp(getExpression(), ids);
+    }
+
+    /**
+     * @return An expression for finding objects without given id set.
+     * @since 5.0
+     */
+    public Expression notContainsIdsCollection(Collection<?> ids) {
+        return ExpressionFactory.notInExp(getExpression(), ids);
+    }
+
+    /**
+     * @return An expression for finding objects with values not in the given 
set.
+     * @since 5.0
+     */
+    public Expression notContainsValuesCollection(Collection<V> values) {
+        return ExpressionFactory.notInExp(getExpression(), values);
+    }
+
+    /**
+     * @return An expression for finding objects with values not in the given 
set.
+     * @since 5.0
+     */
+    @SafeVarargs
+    public final Expression notContainsValues(V... values) {
+        return ExpressionFactory.notInExp(getExpression(), (Object[])values);
+    }
+
     /**
      * @return object entity type represented by this property
      */
diff --git 
a/cayenne/src/main/java/org/apache/cayenne/exp/property/MapProperty.java 
b/cayenne/src/main/java/org/apache/cayenne/exp/property/MapProperty.java
index 296148386..63928dc50 100644
--- a/cayenne/src/main/java/org/apache/cayenne/exp/property/MapProperty.java
+++ b/cayenne/src/main/java/org/apache/cayenne/exp/property/MapProperty.java
@@ -90,7 +90,9 @@ public class MapProperty<K, V extends Persistent> extends 
BaseProperty<Map<K, V>
 
     /**
      * @return An expression for finding objects with values in the given set.
+     * @deprecated since 5.0 in favour of {@link #containsValues(V...)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     @SafeVarargs
     public final Expression contains(V firstValue, V... moreValues) {
 
@@ -108,21 +110,52 @@ public class MapProperty<K, V extends Persistent> extends 
BaseProperty<Map<K, V>
 
     /**
      * @return An expression for finding objects with values in the given set.
+     * @since 5.0
      */
+    @SafeVarargs
+    public final Expression containsValues(V... values) {
+        return ExpressionFactory.inExp(getExpression(), (Object[])values);
+    }
+
+    /**
+     * @return An expression for finding objects with values in the given set.
+     * @deprecated since 5.0 in favour of {@link 
#containsValuesCollection(Collection)}
+     */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression contains(Collection<V> values) {
         return ExpressionFactory.inExp(getExpression(), values);
     }
 
+    /**
+     * @return An expression for finding objects with values in the given set.
+     * @since 5.0
+     */
+    public Expression containsValuesCollection(Collection<V> values) {
+        return ExpressionFactory.inExp(getExpression(), values);
+    }
+
     /**
      * @return An expression for finding objects with values not in the given 
set.
+     * @deprecated since 5.0 in favour of {@link 
#notContainsValuesCollection(Collection)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression notContains(Collection<V> values) {
         return ExpressionFactory.notInExp(getExpression(), values);
     }
 
+    /**
+     * @return An expression for finding objects with values in the given set.
+     * @since 5.0
+     */
+    public Expression notContainsValuesCollection(Collection<V> values) {
+        return ExpressionFactory.inExp(getExpression(), values);
+    }
+
     /**
      * @return An expression for finding objects with values not in the given 
set.
+     * @deprecated since 5.0 in favour of {@link #notContainsValues(V...)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     @SafeVarargs
     public final Expression notContains(V firstValue, V... moreValues) {
 
@@ -138,6 +171,15 @@ public class MapProperty<K, V extends Persistent> extends 
BaseProperty<Map<K, V>
         return ExpressionFactory.notInExp(getExpression(), values);
     }
 
+    /**
+     * @return An expression for finding objects with values not in the given 
set.
+     * @since 5.0
+     */
+    @SafeVarargs
+    public final Expression notContainsValues(V... values) {
+        return ExpressionFactory.notInExp(getExpression(), (Object[])values);
+    }
+
     /**
      * @param id object id
      * @return An expression for finding object with given id.
@@ -148,7 +190,9 @@ public class MapProperty<K, V extends Persistent> extends 
BaseProperty<Map<K, V>
 
     /**
      * @return An expression for finding objects with given id set
+     * @deprecated since 5.0 in favour of {@link #containsIds(Object...)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression containsId(Object firstId, Object... moreId) {
 
         int moreValuesLength = moreId != null ? moreId.length : 0;
@@ -163,13 +207,32 @@ public class MapProperty<K, V extends Persistent> extends 
BaseProperty<Map<K, V>
         return ExpressionFactory.inExp(getExpression(), values);
     }
 
+    /**
+     * @return An expression for finding objects with given id set
+     * @since 5.0
+     */
+    public Expression containsIds(Object... ids) {
+        return ExpressionFactory.inExp(getExpression(), ids);
+    }
+
     /**
      * @return An expression for finding objects with given id set.
+     * @deprecated since 5.0 in favour of {@link 
#containsIdsCollection(Collection)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression containsId(Collection<Object> ids) {
         return ExpressionFactory.inExp(getExpression(), ids);
     }
 
+    /**
+     * @return An expression for finding objects with given id set.
+     * @since 5.0
+     */
+    public Expression containsIdsCollection(Collection<?> ids) {
+        return ExpressionFactory.inExp(getExpression(), ids);
+    }
+
+
     /**
      * @param id object id
      * @return An expression for finding object without given id.
@@ -180,7 +243,9 @@ public class MapProperty<K, V extends Persistent> extends 
BaseProperty<Map<K, V>
 
     /**
      * @return An expression for finding objects without given id set.
+     * @deprecated since 5.0 in favour of {@link #notContainsIds(Object...)}
      */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression notContainsId(Object firstId, Object... moreId) {
 
         int moreValuesLength = moreId != null ? moreId.length : 0;
@@ -197,11 +262,29 @@ public class MapProperty<K, V extends Persistent> extends 
BaseProperty<Map<K, V>
 
     /**
      * @return An expression for finding objects without given id set.
+     * @since 5.0
      */
+    public Expression notContainsIds(Object... ids) {
+        return ExpressionFactory.notInExp(getExpression(), ids);
+    }
+
+    /**
+     * @return An expression for finding objects without given id set.
+     * @deprecated since 5.0 in favour of {@link 
#notContainsIdsCollection(Collection)}
+     */
+    @Deprecated(since = "5.0", forRemoval = true)
     public Expression notContainsId(Collection<Object> ids) {
         return ExpressionFactory.notInExp(getExpression(), ids);
     }
 
+    /**
+     * @return An expression for finding objects without given id set.
+     * @since 5.0
+     */
+    public Expression notContainsIdsCollection(Collection<?> ids) {
+        return ExpressionFactory.notInExp(getExpression(), ids);
+    }
+
     /**
      * {@inheritDoc}
      */
diff --git 
a/cayenne/src/test/java/org/apache/cayenne/exp/property/ListPropertyTest.java 
b/cayenne/src/test/java/org/apache/cayenne/exp/property/ListPropertyTest.java
index 27bffe054..6c833cb70 100644
--- 
a/cayenne/src/test/java/org/apache/cayenne/exp/property/ListPropertyTest.java
+++ 
b/cayenne/src/test/java/org/apache/cayenne/exp/property/ListPropertyTest.java
@@ -20,7 +20,8 @@
 package org.apache.cayenne.exp.property;
 
 import java.util.Arrays;
-import java.util.Collection;
+import java.util.List;
+import java.util.Set;
 
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
@@ -79,28 +80,84 @@ public class ListPropertyTest {
     @Test
     public void containsOne() {
         Artist artist = new Artist();
-        Expression exp = property.contains(artist);
+        Expression exp = property.containsValue(artist);
         assertEquals(ExpressionFactory.matchExp("path", artist), exp);
     }
 
     @Test
-    public void containsMany() {
-        Collection<Artist> artists = Arrays.asList(new Artist(), new Artist());
-        Expression exp = property.contains(artists);
+    public void containsArray() {
+        Artist[] artists = {new Artist(), new Artist()};
+        Expression exp = property.containsValues(artists);
+        assertEquals(ExpressionFactory.inExp("path", (Object[])artists), exp);
+    }
+
+    @Test
+    public void containsCollection() {
+        Set<Artist> artists = Set.of(new Artist(), new Artist());
+        Expression exp = property.containsValuesCollection(artists);
         assertEquals(ExpressionFactory.inExp("path", artists), exp);
     }
 
+    @Test
+    public void containsId() {
+        int id = 1;
+        Expression exp = property.containsId(id);
+        assertEquals(ExpressionFactory.matchExp("path", id), exp);
+    }
+
+    @Test
+    public void containsIdsArray() {
+        Object[] ids = {new Artist(), new Artist()};
+        Expression exp = property.containsIds(ids);
+        assertEquals(ExpressionFactory.inExp("path", ids), exp);
+    }
+
+    @Test
+    public void containsIdsCollection() {
+        Set<Integer> ids = Set.of(1, 2, 3);
+        Expression exp = property.containsIdsCollection(ids);
+        assertEquals(ExpressionFactory.inExp("path", ids), exp);
+    }
+
     @Test
     public void notContainsOne() {
         Artist artist = new Artist();
-        Expression exp = property.notContains(artist);
+        Expression exp = property.notContainsValue(artist);
         assertEquals(ExpressionFactory.noMatchExp("path", artist), exp);
     }
 
     @Test
-    public void notContainsMany() {
-        Collection<Artist> artists = Arrays.asList(new Artist(), new Artist());
-        Expression exp = property.notContains(artists);
+    public void notContainsArray() {
+        Artist[] artists = {new Artist(), new Artist()};
+        Expression exp = property.notContainsValues(artists);
+        assertEquals(ExpressionFactory.notInExp("path", (Object[])artists), 
exp);
+    }
+
+    @Test
+    public void notContainsCollection() {
+        List<Artist> artists = Arrays.asList(new Artist(), new Artist());
+        Expression exp = property.notContainsValuesCollection(artists);
         assertEquals(ExpressionFactory.notInExp("path", artists), exp);
     }
+
+    @Test
+    public void notContainsId() {
+        int id = 1;
+        Expression exp = property.notContainsId(id);
+        assertEquals(ExpressionFactory.noMatchExp("path", id), exp);
+    }
+
+    @Test
+    public void notContainsIdsArray() {
+        Object[] ids = {new Artist(), new Artist()};
+        Expression exp = property.notContainsIds(ids);
+        assertEquals(ExpressionFactory.notInExp("path", ids), exp);
+    }
+
+    @Test
+    public void notContainsIdsCollection() {
+        Set<Integer> ids = Set.of(1, 2, 3);
+        Expression exp = property.notContainsIdsCollection(ids);
+        assertEquals(ExpressionFactory.notInExp("path", ids), exp);
+    }
 }
\ No newline at end of file
diff --git 
a/cayenne/src/test/java/org/apache/cayenne/exp/property/MapPropertyTest.java 
b/cayenne/src/test/java/org/apache/cayenne/exp/property/MapPropertyTest.java
index 7195bb5a9..97f9f6dd7 100644
--- a/cayenne/src/test/java/org/apache/cayenne/exp/property/MapPropertyTest.java
+++ b/cayenne/src/test/java/org/apache/cayenne/exp/property/MapPropertyTest.java
@@ -68,7 +68,7 @@ public class MapPropertyTest {
     public void containsManyArray() {
         Artist artist1 = new Artist();
         Artist artist2 = new Artist();
-        Expression exp = property.contains(artist1, artist2);
+        Expression exp = property.containsValues(artist1, artist2);
         assertEquals(ExpressionFactory.inExp("path", Arrays.asList(artist1, 
artist2)), exp);
     }
 
@@ -76,7 +76,7 @@ public class MapPropertyTest {
     public void containsManyCollection() {
         Artist artist1 = new Artist();
         Artist artist2 = new Artist();
-        Expression exp = property.contains(Arrays.asList(artist1, artist2));
+        Expression exp = 
property.containsValuesCollection(Arrays.asList(artist1, artist2));
         assertEquals(ExpressionFactory.inExp("path", Arrays.asList(artist1, 
artist2)), exp);
     }
 
@@ -84,7 +84,7 @@ public class MapPropertyTest {
     public void notContainsManyArray() {
         Artist artist1 = new Artist();
         Artist artist2 = new Artist();
-        Expression exp = property.notContains(artist1, artist2);
+        Expression exp = property.notContainsValues(artist1, artist2);
         assertEquals(ExpressionFactory.notInExp("path", Arrays.asList(artist1, 
artist2)), exp);
     }
 
@@ -92,7 +92,7 @@ public class MapPropertyTest {
     public void notContainsManyCollection() {
         Artist artist1 = new Artist();
         Artist artist2 = new Artist();
-        Expression exp = property.notContains(Arrays.asList(artist1, artist2));
+        Expression exp = 
property.notContainsValuesCollection(Arrays.asList(artist1, artist2));
         assertEquals(ExpressionFactory.notInExp("path", Arrays.asList(artist1, 
artist2)), exp);
     }
 
@@ -104,13 +104,13 @@ public class MapPropertyTest {
 
     @Test
     public void containsManyIdArray() {
-        Expression exp = property.containsId(1, 2, 3);
+        Expression exp = property.containsIds(1, 2, 3);
         assertEquals(ExpressionFactory.exp("path in (1,2,3)"), exp);
     }
 
     @Test
     public void containsManyIdCollection() {
-        Expression exp = property.containsId(Arrays.asList(1, 2, 3));
+        Expression exp = property.containsIdsCollection(Arrays.asList(1, 2, 
3));
         assertEquals(ExpressionFactory.exp("path in (1,2,3)"), exp);
     }
 
@@ -122,13 +122,13 @@ public class MapPropertyTest {
 
     @Test
     public void notContainsManyIdArray() {
-        Expression exp = property.notContainsId(1, 2, 3);
+        Expression exp = property.notContainsIds(1, 2, 3);
         assertEquals(ExpressionFactory.exp("path not in (1,2,3)"), exp);
     }
 
     @Test
     public void notContainsManyIdCollection() {
-        Expression exp = property.notContainsId(Arrays.asList(1, 2, 3));
+        Expression exp = property.notContainsIdsCollection(Arrays.asList(1, 2, 
3));
         assertEquals(ExpressionFactory.exp("path not in (1,2,3)"), exp);
     }
 
diff --git 
a/cayenne/src/test/java/org/apache/cayenne/exp/property/SetPropertyTest.java 
b/cayenne/src/test/java/org/apache/cayenne/exp/property/SetPropertyTest.java
index d9a9c8f96..a0ab0a7ea 100644
--- a/cayenne/src/test/java/org/apache/cayenne/exp/property/SetPropertyTest.java
+++ b/cayenne/src/test/java/org/apache/cayenne/exp/property/SetPropertyTest.java
@@ -75,7 +75,7 @@ public class SetPropertyTest {
     @Test
     public void containsOne() {
         Artist artist = new Artist();
-        Expression exp = property.contains(artist);
+        Expression exp = property.containsValue(artist);
         assertEquals(ExpressionFactory.matchExp("path", artist), exp);
     }
 }
\ No newline at end of file

Reply via email to