jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1133613 - in /incubator/jena/Jena2/ARQ/trunk: AL-text src-dev/dev/RunARQ.java src-test/org/openjena/atlas/iterator/TestIter.java src/org/openjena/atlas/iterator/Iter.java
Date Thu, 09 Jun 2011 00:25:27 GMT
Author: andy
Date: Thu Jun  9 00:25:27 2011
New Revision: 1133613

URL: http://svn.apache.org/viewvc?rev=1133613&view=rev
Log: (empty)

Added:
    incubator/jena/Jena2/ARQ/trunk/AL-text
Modified:
    incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java
    incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/atlas/iterator/TestIter.java
    incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/Iter.java

Added: incubator/jena/Jena2/ARQ/trunk/AL-text
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/AL-text?rev=1133613&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/AL-text (added)
+++ incubator/jena/Jena2/ARQ/trunk/AL-text Thu Jun  9 00:25:27 2011
@@ -0,0 +1,17 @@
+/**
+ * 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.
+ */

Modified: incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java?rev=1133613&r1=1133612&r2=1133613&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java Thu Jun  9 00:25:27 2011
@@ -107,9 +107,13 @@ public class RunARQ
         System.out.println("DONE") ;
         System.exit(code) ;
     }
+    
 
+    // count(filter)
+    
     public static void main(String[] argv) throws Exception
     {
+        
         arq.qparse.main("--file=Q.arq") ; exit(0) ;
         
         String x = StrUtils.strjoinNL("(join",

Modified: incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/atlas/iterator/TestIter.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/atlas/iterator/TestIter.java?rev=1133613&r1=1133612&r2=1133613&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/atlas/iterator/TestIter.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/atlas/iterator/TestIter.java Thu
Jun  9 00:25:27 2011
@@ -1,5 +1,6 @@
 /*
  * (c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
+ * (c) Copyright 2011 Epimorphics Ltd.
  * All rights reserved.
  * [See end of file]
  */
@@ -20,18 +21,9 @@ import org.junit.Test ;
 public class TestIter
 {
     List<String> data0 = new ArrayList<String>() ;
-    List<String> data1 = new ArrayList<String>() ;
-    {
-        data1.add("a") ;
-    }
-    
-    List<String> data2 = new ArrayList<String>() ;
-    {
-        data2.add("x") ;
-        data2.add("y") ;
-        data2.add("z") ;
-    }
-
+    List<String> data1 = Arrays.asList("a") ;
+    List<String> data2 = Arrays.asList("x","y","z") ;
+ 
     @Test
     public void append_1()
     {
@@ -131,11 +123,101 @@ public class TestIter
         String z = Iter.foldRight(Arrays.asList(x), f1, "X") ;
         assertEquals("X", z) ;
     }
+    
+    Filter<String> filter = new Filter<String>() {
+        public boolean accept(String item)
+        {
+            return item.length() == 1 ;
+        }} ;
+   
+    @Test
+    public void first_01()
+    {
+        Iter<String> iter = Iter.nullIter() ;
+        assertEquals(null, Iter.first(iter, filter)) ;
+    }
+
+    @Test
+    public void first_02()
+    {
+        List<String> data = Arrays.asList( "11", "A", "B", "C") ;
+        assertEquals("A", Iter.first(data, filter)) ;
+    }
+
+    @Test
+    public void first_03()
+    {
+        List<String> data = Arrays.asList( "11", "AA", "BB", "CC") ;
+        assertEquals(null, Iter.first(data, filter)) ;
+    }
+ 
+    @Test
+    public void first_04()
+    {
+        Iter<String> iter = Iter.nullIter() ;
+        assertEquals(-1, Iter.firstIndex(iter, filter)) ;
+    }
+
+    @Test
+    public void first_05()
+    {
+        List<String> data = Arrays.asList( "11", "A", "B", "C") ;
+        assertEquals(1, Iter.firstIndex(data, filter)) ;
+    }
 
+    @Test
+    public void first_06()
+    {
+        List<String> data = Arrays.asList( "11", "AA", "BB", "CC") ;
+        assertEquals(-1, Iter.firstIndex(data, filter)) ;
+    }
+
+    @Test
+    public void last_01()
+    {
+        Iter<String> iter = Iter.nullIter() ;
+        assertEquals(null, Iter.last(iter, filter)) ;
+    }
+
+    @Test
+    public void last_02()
+    {
+        List<String> data = Arrays.asList( "11", "A", "B", "C") ;
+        assertEquals("C", Iter.last(data, filter)) ;
+    }
+
+    @Test
+    public void last_03()
+    {
+        List<String> data = Arrays.asList( "11", "AA", "BB", "CC") ;
+        assertEquals(null, Iter.last(data, filter)) ;
+    }
+ 
+    @Test
+    public void last_04()
+    {
+        Iter<String> iter = Iter.nullIter() ;
+        assertEquals(-1, Iter.lastIndex(iter, filter)) ;
+    }
+
+    @Test
+    public void last_05()
+    {
+        List<String> data = Arrays.asList( "11", "A", "B", "C") ;
+        assertEquals(3, Iter.lastIndex(data, filter)) ;
+    }
+
+    @Test
+    public void last_06()
+    {
+        List<String> data = Arrays.asList( "11", "AA", "BB", "CC") ;
+        assertEquals(-1, Iter.firstIndex(data, filter)) ;
+    }
 }
 
 /*
  * (c) Copyright 2008, 2009 Hewlett-Packard Development Company, LP
+ * (c) Copyright 2011 Epimorphics Ltd.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

Modified: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/Iter.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/Iter.java?rev=1133613&r1=1133612&r2=1133613&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/Iter.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/atlas/iterator/Iter.java Thu Jun  9 00:25:27
2011
@@ -1,6 +1,6 @@
 /*
  * (c) Copyright 2007, 2008, 2009 Hewlett-Packard Development Company, LP
- * (c) Copyright 2010 Epimorphics Ltd.
+ * (c) Copyright 2010, 2011 Epimorphics Ltd.
  * All rights reserved.
  * [See end of file]
  */
@@ -497,6 +497,65 @@ public class Iter<T> implements Iterable
             return iter1 ;
         return Iter.iter(iter1).append(Iter.iter(iter2)) ;
     }
+    
+    public static <T> T first(Iterator<T> iter, Filter<T> filter)
+    {
+        for ( int idx = 0 ; iter.hasNext() ; idx++ )
+        {
+            T t = iter.next();
+            if ( filter.accept(t))
+                return t ;
+                //return idx ;
+        }
+        return null ;
+    }
+
+    public static <T> T first(Collection<T> collection, Filter<T> filter)
+    { return first(collection.iterator(), filter) ; }
+
+    public static <T> int firstIndex(Iterator<T> iter, Filter<T> filter)
+    {
+        for ( int idx = 0 ; iter.hasNext() ; idx++ )
+        {
+            T t = iter.next();
+            if ( filter.accept(t))
+                return idx ;
+        }
+        return -1 ;
+    }
+
+    public static <T> int firstIndex(Collection<T> collection, Filter<T>
filter)
+    { return firstIndex(collection.iterator(), filter) ; }
+
+    public static <T> T last(Iterator<T> iter, Filter<T> filter)
+    {
+        T thing = null ;
+        for ( int idx = 0 ; iter.hasNext() ; idx++ )
+        {
+            T t = iter.next();
+            if ( filter.accept(t))
+                thing = t ;
+        }
+        return thing ;
+    }
+
+    public static <T> T last(Collection<T> collection, Filter<T> filter)
+    { return last(collection.iterator(), filter) ; }
+
+    public static <T> int lastIndex(Iterator<T> iter, Filter<T> filter)
+    {
+        int location = -1 ;
+        for ( int idx = 0 ; iter.hasNext() ; idx++ )
+        {
+            T t = iter.next();
+            if ( filter.accept(t))
+                location = idx  ;
+        }
+        return location ;
+    }
+
+    public static <T> int lastIndex(Collection<T> collection, Filter<T>
filter)
+    { return lastIndex(collection.iterator(), filter) ; }
 
     // ------------------------------------------------------
     // The class.
@@ -519,6 +578,25 @@ public class Iter<T> implements Iterable
         sendToSink(iterator, sink) ;
     }
     
+    public T first(Filter<T> filter)
+    {
+        return first(iterator, filter) ;
+    }
+
+    public int firstIndex(Filter<T> filter)
+    {
+        return firstIndex(iterator, filter) ;
+    }
+
+    public T last(Filter<T> filter)
+    {
+        return last(iterator, filter) ;
+    }
+
+    public int lastIndex(Filter<T> filter)
+    {
+        return lastIndex(iterator, filter) ;
+    }
 
     public Iter<T> filter(Filter<T> filter)
     {
@@ -619,7 +697,7 @@ public class Iter<T> implements Iterable
 
 /*
  * (c) Copyright 2007, 2008, 2009 Hewlett-Packard Development Company, LP
- * (c) Copyright 2010 Epimorphics Ltd.
+ * (c) Copyright 2010, 2011 Epimorphics Ltd.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without



Mime
View raw message