You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/07/27 12:06:33 UTC

[04/11] jena git commit: Host AbortableComparator in its own file.

Host AbortableComparator in its own file.

Also include AbandonSort in AbortableComparator (which is the only
place that uses it).


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/d4c89624
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/d4c89624
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/d4c89624

Branch: refs/heads/master
Commit: d4c8962409859f62e0152b081c4067c1c4e7f0f2
Parents: 5d09cb5
Author: Chris Dollin <eh...@googlemail.com>
Authored: Tue Jul 19 14:32:04 2016 +0100
Committer: Chris Dollin <eh...@googlemail.com>
Committed: Tue Jul 19 14:32:04 2016 +0100

----------------------------------------------------------------------
 .../jena/atlas/data/AbortableComparator.java    | 91 ++++++++++++++++++++
 .../apache/jena/atlas/data/SortedDataBag.java   | 70 ---------------
 2 files changed, 91 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/d4c89624/jena-arq/src/main/java/org/apache/jena/atlas/data/AbortableComparator.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/data/AbortableComparator.java b/jena-arq/src/main/java/org/apache/jena/atlas/data/AbortableComparator.java
new file mode 100644
index 0000000..7be58ec
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/data/AbortableComparator.java
@@ -0,0 +1,91 @@
+/*
+ * 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.jena.atlas.data;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+public final class AbortableComparator<E> implements Comparator<E> 
+{
+	public AbortableComparator(Comparator<? super E> comparator) 
+	{
+		this.baseComparator = comparator;
+	}
+	
+    /**
+        <code>AbandonSort</code> is the exception thrown from
+        <code>AbortableComparator</code> to abandon a sort.
+    */
+	public static class AbandonSort extends RuntimeException 
+    {
+		private static final long serialVersionUID = 1L;
+    }
+	
+	/**
+	    The test for whether the sort has been cancelled is
+	    performed every <code>cancelTestFrequency</code> comparisons.
+	    This reduces the (presumed) overhead of access to a
+	    volatile boolean.    	    
+	*/
+	static final int cancelTestFrequency = 10000;
+	
+	/**
+	    Count of the number of times this comparator has been called.
+	*/
+	int count = 0;
+	
+	protected volatile boolean cancelled;
+	
+	final Comparator<? super E> baseComparator;
+
+	@Override public int compare(E o1, E o2) 
+	{	
+		count += 1;
+		if (count % cancelTestFrequency == 0) 
+		{
+			if (cancelled) throw new AbandonSort();
+		}
+		return baseComparator.compare(o1, o2);
+	}
+	
+	/**
+	    Sort the array <code>e</code> using this comparator
+	 	with the additional ability to abort the sort.
+	*/
+	public boolean abortableSort(E[] e) 
+	{
+		try 
+		{ 
+			Arrays.sort(e, this); 
+		}
+		catch (AbandonSort s) 
+		{ 
+			return true;
+		}
+		return false;
+	}
+	
+	/**
+	    Arrange that the next on-frequency cancellation test
+	    in compare will succeed, aborting the sort. 
+	*/
+	public void cancel() 
+	{
+		cancelled = true;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/d4c89624/jena-arq/src/main/java/org/apache/jena/atlas/data/SortedDataBag.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/data/SortedDataBag.java b/jena-arq/src/main/java/org/apache/jena/atlas/data/SortedDataBag.java
index 68de3f6..9ae78e2 100644
--- a/jena-arq/src/main/java/org/apache/jena/atlas/data/SortedDataBag.java
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/data/SortedDataBag.java
@@ -82,76 +82,6 @@ public class SortedDataBag<E> extends AbstractDataBag<E>
         this.comparator = new AbortableComparator<E>(comparator);
     }
     
-    private static final class AbortableComparator<E> implements Comparator<E> 
-    	{
-    	/**
-    	    The test for whether the sort has been cancelled is
-    	    performed every <code>cancelTestFrequency</code> comparisons.
-    	    This reduces the (presumed) overhead of access to a
-    	    volatile boolean.    	    
-    	*/
-    	static final int cancelTestFrequency = 10000;
-    	
-    	/**
-    	    Count of the number of times this comparator has been called.
-    	*/
-		int count = 0;
-		
-		protected volatile boolean cancelled;
-		
-		final Comparator<? super E> baseComparator;
-		
-		public AbortableComparator(Comparator<? super E> comparator) 
-		{
-			this.baseComparator = comparator;
-		}
-
-		@Override public int compare(E o1, E o2) 
-		{	
-			count += 1;
-			if (count % cancelTestFrequency == 0) 
-			{
-				if (cancelled) throw new AbandonSort();
-			}
-			return baseComparator.compare(o1, o2);
-		}
-		
-		/**
-		    Sort the array <code>e</code> using this comparator
-		 	with the additional ability to abort the sort.
-		*/
-		public boolean abortableSort(E[] e) 
-		{
-			try 
-			{ 
-				Arrays.sort(e, this); 
-			}
-			catch (AbandonSort s) 
-			{ 
-				return true;
-			}
-			return false;
-		}
-		
-		/**
-		    Arrange that the next on-frequency cancellation test
-		    in compare will succeed, aborting the sort. 
-		*/
-		public void cancel() 
-		{
-			cancelled = true;
-		}
-	}
-
-    /**
-        <code>AbandonSort</code> is the exception thrown from
-        <code>AbortableComparator</code> to abandon a sort.
-    */
-	public static class AbandonSort extends RuntimeException 
-    {
-		private static final long serialVersionUID = 1L;
-    }
-    
 	/**
 	    cancel arranges that further comparisons using the supplied
 	    comparator will abandon the sort in progress.