Author: markt Date: Mon Jul 15 12:58:44 2013 New Revision: 1503217 URL: http://svn.apache.org/r1503217 Log: Implement first collection operation for EL 3.0.
Added: tomcat/trunk/java/org/apache/el/stream/ tomcat/trunk/java/org/apache/el/stream/Optional.java (with props) tomcat/trunk/java/org/apache/el/stream/Stream.java (with props) tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java (with props) tomcat/trunk/test/org/apache/el/stream/ tomcat/trunk/test/org/apache/el/stream/TestCollectionOperations.java (with props) Modified: tomcat/trunk/java/org/apache/el/ExpressionFactoryImpl.java Modified: tomcat/trunk/java/org/apache/el/ExpressionFactoryImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/ExpressionFactoryImpl.java?rev=1503217&r1=1503216&r2=1503217&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/el/ExpressionFactoryImpl.java (original) +++ tomcat/trunk/java/org/apache/el/ExpressionFactoryImpl.java Mon Jul 15 12:58:44 2013 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.el; import javax.el.ELContext; @@ -25,6 +24,7 @@ import javax.el.ValueExpression; import org.apache.el.lang.ELSupport; import org.apache.el.lang.ExpressionBuilder; +import org.apache.el.stream.StreamELResolverImpl; import org.apache.el.util.MessageFactory; @@ -80,7 +80,6 @@ public class ExpressionFactoryImpl exten @Override public ELResolver getStreamELResolver() { - // TODO Implement a streamELResolver - return null; + return new StreamELResolverImpl(); } } Added: tomcat/trunk/java/org/apache/el/stream/Optional.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/stream/Optional.java?rev=1503217&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/el/stream/Optional.java (added) +++ tomcat/trunk/java/org/apache/el/stream/Optional.java Mon Jul 15 12:58:44 2013 @@ -0,0 +1,21 @@ +/* + * 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.el.stream; + +public class Optional { + +} Propchange: tomcat/trunk/java/org/apache/el/stream/Optional.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/java/org/apache/el/stream/Stream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/stream/Stream.java?rev=1503217&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/el/stream/Stream.java (added) +++ tomcat/trunk/java/org/apache/el/stream/Stream.java Mon Jul 15 12:58:44 2013 @@ -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.el.stream; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class Stream { + + private final Iterator<?> iterator; + + public Stream(Iterator<?> iterator) { + this.iterator = iterator; + } + + + public List<Object> toList() { + List<Object> result = new ArrayList<>(); + while (iterator.hasNext()) { + result.add(iterator.next()); + } + return result; + } +} Propchange: tomcat/trunk/java/org/apache/el/stream/Stream.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java?rev=1503217&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java (added) +++ tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java Mon Jul 15 12:58:44 2013 @@ -0,0 +1,76 @@ +/* + * 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.el.stream; + +import java.beans.FeatureDescriptor; +import java.util.Collection; +import java.util.Iterator; + +import javax.el.ELContext; +import javax.el.ELResolver; + +public class StreamELResolverImpl extends ELResolver { + + @Override + public Object getValue(ELContext context, Object base, Object property) { + return null; + } + + @Override + public Class<?> getType(ELContext context, Object base, Object property) { + return null; + } + + @Override + public void setValue(ELContext context, Object base, Object property, + Object value) { + // NO-OP + } + + @Override + public boolean isReadOnly(ELContext context, Object base, Object property) { + return false; + } + + @Override + public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, + Object base) { + return null; + } + + @Override + public Class<?> getCommonPropertyType(ELContext context, Object base) { + return null; + } + + @Override + public Object invoke(ELContext context, Object base, Object method, + Class<?>[] paramTypes, Object[] params) { + + if ("stream".equals(method) && params.length == 0) { + if (base.getClass().isArray()) { + // TODO handle array source + } else if (base instanceof Collection) { + context.setPropertyResolved(true); + return new Stream(((Collection<?>) base).iterator()); + } + } + + // Not for handling by this resolver + return null; + } +} Propchange: tomcat/trunk/java/org/apache/el/stream/StreamELResolverImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/org/apache/el/stream/TestCollectionOperations.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/stream/TestCollectionOperations.java?rev=1503217&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/el/stream/TestCollectionOperations.java (added) +++ tomcat/trunk/test/org/apache/el/stream/TestCollectionOperations.java Mon Jul 15 12:58:44 2013 @@ -0,0 +1,41 @@ +/* + * 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.el.stream; + +import java.util.ArrayList; +import java.util.List; + +import javax.el.ELProcessor; + +import org.junit.Assert; +import org.junit.Test; + +public class TestCollectionOperations { + + @Test + public void testToList01() { + ELProcessor processor = new ELProcessor(); + Object result = processor.getValue("['a','b','c'].stream().toList()", + List.class); + List<String> expected = new ArrayList<>(3); + expected.add("a"); + expected.add("b"); + expected.add("c"); + + Assert.assertEquals(expected, result); + } +} Propchange: tomcat/trunk/test/org/apache/el/stream/TestCollectionOperations.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org