cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1425945 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/exp/Property.java test/java/org/apache/cayenne/exp/PropertyTest.java
Date Wed, 26 Dec 2012 15:13:32 GMT
Author: aadamchik
Date: Wed Dec 26 15:13:31 2012
New Revision: 1425945

URL: http://svn.apache.org/viewvc?rev=1425945&view=rev
Log:
CAY-1784 Improving 'Property' class to handle a few extra common cases

in(Collection)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/PropertyTest.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java?rev=1425945&r1=1425944&r2=1425945&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java
Wed Dec 26 15:13:31 2012
@@ -1,10 +1,9 @@
 package org.apache.cayenne.exp;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.Ordering;
 import org.apache.cayenne.query.PrefetchTreeNode;
 import org.apache.cayenne.query.SortOrder;
@@ -150,7 +149,24 @@ public class Property<E> {
     /**
      * @return An expression for finding objects with values in the given set.
      */
-    public Expression in(E... values) {
+    public Expression in(E firstValue, E... 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(getName(), values);
+    }
+    
+    /**
+     * @return An expression for finding objects with values in the given set.
+     */
+    public Expression in(Collection<E> values) {
         return ExpressionFactory.inExp(getName(), values);
     }
 

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/PropertyTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/PropertyTest.java?rev=1425945&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/PropertyTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/PropertyTest.java
Wed Dec 26 15:13:31 2012
@@ -0,0 +1,39 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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
+ *
+ *    http://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.apache.cayenne.exp;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class PropertyTest extends TestCase {
+
+    public void testIn() {
+        Property<String> p = new Property<String>("x.y");
+
+        Expression e1 = p.in("a");
+        assertEquals("x.y in (\"a\")", e1.toString());
+
+        Expression e2 = p.in("a", "b");
+        assertEquals("x.y in (\"a\", \"b\")", e2.toString());
+
+        Expression e3 = p.in(Arrays.asList("a", "b"));
+        assertEquals("x.y in (\"a\", \"b\")", e3.toString());
+    }
+}



Mime
View raw message