sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject [sis] 01/02: Filter : prepare PropertyIsLike filter implementation
Date Tue, 05 Nov 2019 15:18:17 GMT
This is an automated email from the ASF dual-hosted git repository.

jsorel pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit eae5ae15dde246faa007fb37c113954a3c5a0916
Author: jsorel <johann.sorel@geomatys.com>
AuthorDate: Tue Nov 5 11:57:46 2019 +0100

    Filter : prepare PropertyIsLike filter implementation
---
 .../apache/sis/filter/DefaultFilterFactory.java    |  2 +-
 .../java/org/apache/sis/filter/DefaultLike.java    | 96 ++++++++++++++++++++++
 .../org/apache/sis/filter/LikeFunctionTest.java    | 55 +++++++++++++
 .../apache/sis/test/suite/FeatureTestSuite.java    |  1 +
 4 files changed, 153 insertions(+), 1 deletion(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultFilterFactory.java
b/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultFilterFactory.java
index c05af8d..7eeb359 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultFilterFactory.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultFilterFactory.java
@@ -544,7 +544,7 @@ public class DefaultFilterFactory implements FilterFactory2 {
             final String wildcard, final String singleChar,
             final String escape, final boolean isMatchingCase)
     {
-        throw new UnsupportedOperationException("Not supported yet.");
+        return new DefaultLike(expression, pattern, wildcard, singleChar, escape, isMatchingCase);
     }
 
     /**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultLike.java b/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultLike.java
new file mode 100644
index 0000000..42cec1e
--- /dev/null
+++ b/core/sis-feature/src/main/java/org/apache/sis/filter/DefaultLike.java
@@ -0,0 +1,96 @@
+/*
+ * 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.sis.filter;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.opengis.filter.FilterVisitor;
+import org.opengis.filter.PropertyIsLike;
+import org.opengis.filter.expression.Expression;
+
+/**
+ * The {@value #NAME} filter.
+ */
+final class DefaultLike extends Node implements PropertyIsLike {
+
+    private final Expression expression;
+    private final String pattern;
+    private final String wildcard;
+    private final String singleChar;
+    private final String escape;
+    private final boolean matchingCase;
+
+    DefaultLike(Expression expression, String pattern, String wildcard, String singleChar,
String escape, boolean matchingCase) {
+        this.expression = expression;
+        this.pattern = pattern;
+        this.wildcard = wildcard;
+        this.singleChar = singleChar;
+        this.escape = escape;
+        this.matchingCase = matchingCase;
+    }
+
+    @Override
+    protected String getName() {
+        return NAME;
+    }
+
+    @Override
+    protected Collection<?> getChildren() {
+        return Arrays.asList(expression);
+    }
+
+    @Override
+    public Expression getExpression() {
+        return expression;
+    }
+
+    @Override
+    public String getLiteral() {
+        return pattern;
+    }
+
+    @Override
+    public String getWildCard() {
+        return wildcard;
+    }
+
+    @Override
+    public String getSingleChar() {
+        return singleChar;
+    }
+
+    @Override
+    public String getEscape() {
+        return escape;
+    }
+
+    @Override
+    public boolean isMatchingCase() {
+        return matchingCase;
+    }
+
+    @Override
+    public boolean evaluate(Object object) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public Object accept(FilterVisitor visitor, Object extraData) {
+        return visitor.visit(this, extraData);
+    }
+
+}
diff --git a/core/sis-feature/src/test/java/org/apache/sis/filter/LikeFunctionTest.java b/core/sis-feature/src/test/java/org/apache/sis/filter/LikeFunctionTest.java
new file mode 100644
index 0000000..7374ff5
--- /dev/null
+++ b/core/sis-feature/src/test/java/org/apache/sis/filter/LikeFunctionTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.sis.filter;
+
+import org.opengis.filter.FilterFactory;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+import org.junit.Ignore;
+
+
+/**
+ * Tests {@link ComparisonFunction.Like} implementations.
+ *
+ * @author  Johann Sorel (Geomatys)
+ * @version 2.0
+ * @since   2.0
+ * @module
+ */
+public final strictfp class LikeFunctionTest extends TestCase {
+    /**
+     * The factory to use for creating the objects to test.
+     */
+    private final FilterFactory factory;
+
+    /**
+     * Creates a new test case.
+     */
+    public LikeFunctionTest() {
+        factory = new DefaultFilterFactory();
+    }
+
+
+    /**
+     * Tests "Like" (construction, evaluation, serialization, equality).
+     */
+    @Ignore
+    @Test
+    public void testLike() {
+        //todo
+    }
+}
diff --git a/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
b/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
index 0005172..d4581ac 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/test/suite/FeatureTestSuite.java
@@ -58,6 +58,7 @@ import org.junit.runners.Suite;
     org.apache.sis.filter.ArithmeticFunctionTest.class,
     org.apache.sis.filter.ComparisonFunctionTest.class,
     org.apache.sis.filter.BetweenFunctionTest.class,
+    org.apache.sis.filter.LikeFunctionTest.class,
     org.apache.sis.filter.TemporalFunctionTest.class,
     org.apache.sis.filter.SQLMMTest.class,
     org.apache.sis.internal.feature.AttributeConventionTest.class,


Mime
View raw message