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 2011/11/07 14:36:34 UTC

svn commit: r1198733 [3/13] - in /incubator/jena/Scratch/AFS/Dev/trunk: src-archive/riot/comms/ src-archive/riot/comms/client/ src-archive/riot/comms/server0/ src-archive/riot/comms/server1/nio/ src-archive/riot/comms/server1/socket/ src-archive/riot/c...

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/rdfs.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/rdfs.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/rdfs.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/rdfs.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,104 +16,104 @@
  * limitations under the License.
  */
 
-package dev;
-
-import java.util.Iterator;
-
-import arq.cmdline.CmdMain;
-
-import com.hp.hpl.jena.rdf.model.InfModel;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.RDFNode;
-import com.hp.hpl.jena.rdf.model.StmtIterator;
-import com.hp.hpl.jena.reasoner.Reasoner;
-import com.hp.hpl.jena.reasoner.ReasonerRegistry;
-import com.hp.hpl.jena.sparql.util.Utils;
-import com.hp.hpl.jena.util.FileManager;
-
-/** Apply RDFS reasoning to data and schema */
-
-public class rdfs extends CmdMain
-{
-    public static void main(String[] argv)
-    {
-        new rdfs(argv).mainRun() ;
-    }
-    
-    private rdfs(String[] argv)
-    {
-        super(argv) ;
-        super.add("simple", false) ;
-        super.add("schema", true) ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        Model modelSchema = ModelFactory.createDefaultModel() ;
-        Model modelData = ModelFactory.createDefaultModel() ;
-
-        for ( Iterator<?> iter = super.getValues("schema").iterator(); iter.hasNext() ; )
-        {
-            String filename = (String)iter.next();
-            FileManager.get().readModel(modelSchema, filename) ;
-        }
-
-        for ( Iterator<?> iter = super.getPositional().iterator(); iter.hasNext() ; )
-        {
-            String filename = (String)iter.next();
-            FileManager.get().readModel(modelData, filename) ;
-        }
-
-        Reasoner reasoner = null ;
-        if ( super.contains("simple") )
-        {
-            System.out.println("# Simple") ;
-            reasoner = ReasonerRegistry.getRDFSSimpleReasoner() ;
-        }
-        else
-            reasoner = ReasonerRegistry.getRDFSReasoner() ;
-        
-        
-        
-        // Fetch the rule set and create the reasoner
-//        BuiltinRegistry.theRegistry.register(new Deduce());
-//        Map prefixes = new HashMap();
-//        List rules = loadRules((String)cl.getItem(0), prefixes);
-//        Reasoner reasoner = new GenericRuleReasoner(rules);
-        
-        System.out.println("# Schema") ;
-        modelSchema.write(System.out, "TTL") ;
-        System.out.println() ;
-        
-        System.out.println("# Data") ;
-        modelData.write(System.out, "TTL") ;
-        System.out.println() ;
-        
-        InfModel infModel = ModelFactory.createInfModel(reasoner, modelSchema, modelData) ;
-        infModel.prepare();
-        
-        System.out.println("# Find") ;
-        StmtIterator sIter = infModel.listStatements(infModel.createResource("http://example/x"), null, (RDFNode)null) ;
-        while(sIter.hasNext())
-            System.out.println(sIter.nextStatement()) ;
-        System.out.println() ;
-        
-        System.out.println("# Deductions") ;
-        Model deductions = infModel.getDeductionsModel() ;
-        deductions.write(System.out, "TTL") ;
-        System.out.println() ;
-
-        System.out.println("# All") ;
-        infModel.write(System.out, "TTL") ;
-        System.out.println() ;
-    }
-
-
-    @Override
-    protected String getCommandName()
-    {
-        return Utils.className(this) ;
-    } 
+package dev;
+
+import java.util.Iterator;
+
+import arq.cmdline.CmdMain;
+
+import com.hp.hpl.jena.rdf.model.InfModel;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.reasoner.Reasoner;
+import com.hp.hpl.jena.reasoner.ReasonerRegistry;
+import com.hp.hpl.jena.sparql.util.Utils;
+import com.hp.hpl.jena.util.FileManager;
+
+/** Apply RDFS reasoning to data and schema */
+
+public class rdfs extends CmdMain
+{
+    public static void main(String[] argv)
+    {
+        new rdfs(argv).mainRun() ;
+    }
+    
+    private rdfs(String[] argv)
+    {
+        super(argv) ;
+        super.add("simple", false) ;
+        super.add("schema", true) ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        Model modelSchema = ModelFactory.createDefaultModel() ;
+        Model modelData = ModelFactory.createDefaultModel() ;
+
+        for ( Iterator<?> iter = super.getValues("schema").iterator(); iter.hasNext() ; )
+        {
+            String filename = (String)iter.next();
+            FileManager.get().readModel(modelSchema, filename) ;
+        }
+
+        for ( Iterator<?> iter = super.getPositional().iterator(); iter.hasNext() ; )
+        {
+            String filename = (String)iter.next();
+            FileManager.get().readModel(modelData, filename) ;
+        }
+
+        Reasoner reasoner = null ;
+        if ( super.contains("simple") )
+        {
+            System.out.println("# Simple") ;
+            reasoner = ReasonerRegistry.getRDFSSimpleReasoner() ;
+        }
+        else
+            reasoner = ReasonerRegistry.getRDFSReasoner() ;
+        
+        
+        
+        // Fetch the rule set and create the reasoner
+//        BuiltinRegistry.theRegistry.register(new Deduce());
+//        Map prefixes = new HashMap();
+//        List rules = loadRules((String)cl.getItem(0), prefixes);
+//        Reasoner reasoner = new GenericRuleReasoner(rules);
+        
+        System.out.println("# Schema") ;
+        modelSchema.write(System.out, "TTL") ;
+        System.out.println() ;
+        
+        System.out.println("# Data") ;
+        modelData.write(System.out, "TTL") ;
+        System.out.println() ;
+        
+        InfModel infModel = ModelFactory.createInfModel(reasoner, modelSchema, modelData) ;
+        infModel.prepare();
+        
+        System.out.println("# Find") ;
+        StmtIterator sIter = infModel.listStatements(infModel.createResource("http://example/x"), null, (RDFNode)null) ;
+        while(sIter.hasNext())
+            System.out.println(sIter.nextStatement()) ;
+        System.out.println() ;
+        
+        System.out.println("# Deductions") ;
+        Model deductions = infModel.getDeductionsModel() ;
+        deductions.write(System.out, "TTL") ;
+        System.out.println() ;
+
+        System.out.println("# All") ;
+        infModel.write(System.out, "TTL") ;
+        System.out.println() ;
+    }
+
+
+    @Override
+    protected String getCommandName()
+    {
+        return Utils.className(this) ;
+    } 
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/rules.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/rules.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/rules.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/rules.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,121 +16,121 @@
  * limitations under the License.
  */
 
-package dev;
-
-import java.io.BufferedReader ;
-import java.io.File ;
-import java.util.HashMap ;
-import java.util.Iterator ;
-import java.util.List ;
-import java.util.Map ;
-
-import arq.cmdline.ArgDecl ;
-import arq.cmdline.CmdMain ;
-
-import com.hp.hpl.jena.rdf.model.InfModel ;
-import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.rdf.model.ModelFactory ;
-import com.hp.hpl.jena.reasoner.Reasoner ;
-import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner ;
-import com.hp.hpl.jena.reasoner.rulesys.Rule ;
-import com.hp.hpl.jena.sparql.util.Utils ;
-import com.hp.hpl.jena.util.FileManager ;
-import com.hp.hpl.jena.util.FileUtils ;
-
-/** Apply a rule set */
-
-public class rules extends CmdMain
-{
-    ArgDecl argRules = new ArgDecl(ArgDecl.HasValue, "rules", "rule") ;
-    
-    public static void main(String[] argv)
-    {
-        new rules(argv).mainRun() ;
-    }
-    
-    private rules(String[] argv)
-    {
-        super(argv) ;
-        super.add("rules", true) ;
-    }
-
-    @Override
-    protected void exec()
-    {
-        try
-        {
-            Model modelData = ModelFactory.createDefaultModel() ;
-
-            for ( Iterator<?> iter = super.getPositional().iterator(); iter.hasNext() ; )
-            {
-                String filename = (String)iter.next();
-                FileManager.get().readModel(modelData, filename) ;
-            }
-
-            if ( super.getValues(argRules).size() != 0 )
-            {
-                System.err.println("Exactly one rules file") ;
-                System.exit(1) ;
-            }
-
-            String rulesFile = super.getValue(argRules) ;
-
-            Map<String, String> prefixes = new HashMap<String, String>();
-            List<Rule> rules = loadRules(rulesFile, prefixes) ;
-            Reasoner reasoner = new GenericRuleReasoner(rules);
-
-            InfModel infModel = ModelFactory.createInfModel(reasoner, modelData) ;
-            infModel.prepare();
-
-            System.out.println("# Deductions") ;
-            Model deductions = infModel.getDeductionsModel() ;
-            deductions.write(System.out, "TTL") ;
-            System.out.println() ;
-
-            System.out.println("# All") ;
-            infModel.write(System.out, "TTL") ;
-            System.out.println() ;
-        } catch (Exception ex)
-        {
-            ex.printStackTrace();
-        }
-    }
-
-    /**
-     * Load a set of rule definitions including processing of
-     * comment lines and any initial prefix definition lines.
-     * Also notes the prefix definitions for adding to a later inf model.
-     */
-    public static List<Rule> loadRules(String filename, Map<String, String> prefixes) {
-        String fname = filename;
-        if (fname.startsWith("file:///")) {
-            fname = File.separator + fname.substring(8);
-        } else if (fname.startsWith("file:/")) {
-            fname = File.separator + fname.substring(6);
-        } else if (fname.startsWith("file:")) {
-            fname = fname.substring(5);
-        }
-
-        BufferedReader src = FileUtils.openResourceFile(fname);
-        return loadRules(src, prefixes);
-    }
-    
-    /**
-     * Load a set of rule definitions including processing of
-     * comment lines and any initial prefix definition lines.
-     * Also notes the prefix definitions for adding to a later inf model.
-     */
-    public static List<Rule> loadRules(BufferedReader src, Map<String, String> prefixes) {
-        Rule.Parser parser = Rule.rulesParserFromReader(src);
-        List<Rule> rules = Rule.parseRules(parser);
-        prefixes.putAll(parser.getPrefixMap());
-        return rules;
-    }
-
-    @Override
-    protected String getCommandName()
-    {
-        return Utils.className(this) ;
-    } 
+package dev;
+
+import java.io.BufferedReader ;
+import java.io.File ;
+import java.util.HashMap ;
+import java.util.Iterator ;
+import java.util.List ;
+import java.util.Map ;
+
+import arq.cmdline.ArgDecl ;
+import arq.cmdline.CmdMain ;
+
+import com.hp.hpl.jena.rdf.model.InfModel ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.reasoner.Reasoner ;
+import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner ;
+import com.hp.hpl.jena.reasoner.rulesys.Rule ;
+import com.hp.hpl.jena.sparql.util.Utils ;
+import com.hp.hpl.jena.util.FileManager ;
+import com.hp.hpl.jena.util.FileUtils ;
+
+/** Apply a rule set */
+
+public class rules extends CmdMain
+{
+    ArgDecl argRules = new ArgDecl(ArgDecl.HasValue, "rules", "rule") ;
+    
+    public static void main(String[] argv)
+    {
+        new rules(argv).mainRun() ;
+    }
+    
+    private rules(String[] argv)
+    {
+        super(argv) ;
+        super.add("rules", true) ;
+    }
+
+    @Override
+    protected void exec()
+    {
+        try
+        {
+            Model modelData = ModelFactory.createDefaultModel() ;
+
+            for ( Iterator<?> iter = super.getPositional().iterator(); iter.hasNext() ; )
+            {
+                String filename = (String)iter.next();
+                FileManager.get().readModel(modelData, filename) ;
+            }
+
+            if ( super.getValues(argRules).size() != 0 )
+            {
+                System.err.println("Exactly one rules file") ;
+                System.exit(1) ;
+            }
+
+            String rulesFile = super.getValue(argRules) ;
+
+            Map<String, String> prefixes = new HashMap<String, String>();
+            List<Rule> rules = loadRules(rulesFile, prefixes) ;
+            Reasoner reasoner = new GenericRuleReasoner(rules);
+
+            InfModel infModel = ModelFactory.createInfModel(reasoner, modelData) ;
+            infModel.prepare();
+
+            System.out.println("# Deductions") ;
+            Model deductions = infModel.getDeductionsModel() ;
+            deductions.write(System.out, "TTL") ;
+            System.out.println() ;
+
+            System.out.println("# All") ;
+            infModel.write(System.out, "TTL") ;
+            System.out.println() ;
+        } catch (Exception ex)
+        {
+            ex.printStackTrace();
+        }
+    }
+
+    /**
+     * Load a set of rule definitions including processing of
+     * comment lines and any initial prefix definition lines.
+     * Also notes the prefix definitions for adding to a later inf model.
+     */
+    public static List<Rule> loadRules(String filename, Map<String, String> prefixes) {
+        String fname = filename;
+        if (fname.startsWith("file:///")) {
+            fname = File.separator + fname.substring(8);
+        } else if (fname.startsWith("file:/")) {
+            fname = File.separator + fname.substring(6);
+        } else if (fname.startsWith("file:")) {
+            fname = fname.substring(5);
+        }
+
+        BufferedReader src = FileUtils.openResourceFile(fname);
+        return loadRules(src, prefixes);
+    }
+    
+    /**
+     * Load a set of rule definitions including processing of
+     * comment lines and any initial prefix definition lines.
+     * Also notes the prefix definitions for adding to a later inf model.
+     */
+    public static List<Rule> loadRules(BufferedReader src, Map<String, String> prefixes) {
+        Rule.Parser parser = Rule.rulesParserFromReader(src);
+        List<Rule> rules = Rule.parseRules(parser);
+        prefixes.putAll(parser.getPrefixMap());
+        return rules;
+    }
+
+    @Override
+    protected String getCommandName()
+    {
+        return Utils.className(this) ;
+    } 
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/Table.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/Table.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/Table.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/Table.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/TableArray.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/TableArray.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/TableArray.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/TableArray.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/TableStream.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/TableStream.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/TableStream.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/table/TableStream.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/libmisc/CodecUTF8.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/libmisc/CodecUTF8.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/libmisc/CodecUTF8.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/libmisc/CodecUTF8.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ArrayOps.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ArrayOps.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ArrayOps.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ArrayOps.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,268 +16,268 @@
  * limitations under the License.
  */
 
-package migrate.lib;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.openjena.atlas.iterator.IteratorArray;
-import org.openjena.atlas.lib.Bytes;
-
-/** Utilities for working with arrays including especially for working with a slice in a larger array. 
- *  This avoids the need to copy/move data outside the slice. 
- *  Slice starts a zero.
- *  Shift up extends the slice, moving elements into the area above the slice.
- *  Shift down introduces nulls at the top of the slice array.
- * @see Bytes for operations 
- */
-public class ArrayOps
-{
-    static boolean Checking = true ;
-    public static final boolean NullOut =  true ;
-
-//    /** Check a zero-based array slice */ 
-//    public static <T> void checkSlice(T[] array, int idx, int length)
-//    {
-//        if ( length > array.length )        error("Bad length") ;
-//        if ( idx >= length )                error("Index out of bounds of slice") ;
-//        if ( idx < 0  )                     error("Negative index for slice") ;
-//    }
-    
-    // -- Variable slice
-    
-    // insert(array, slice, int idx) ;
-    // shiftUp(array, slice, idx) 
-    // shiftUp(array, slice, idx) -> Slice.
-    
-    // Repeat for int[] and long[]
-
-    
-    /** Insert an element at a specific index
-     * @param <T>
-     * @param array
-     * @param idx
-     * @param item
-     */
-    public static <T> void insert(T[] array, int idx, T item)
-    {
-        insert(array, idx, item, array.length) ;
-    }
-    
-    /** Insert an element at a specific index, given a active area of 'length' elements.
-     * @param <T>
-     * @param array
-     * @param idx
-     * @param item
-     * @param length
-     */
-    public static <T> void insert(T[] array, int idx, T item, int length)
-    {
-        // Can insert one beyond the array slice.
-        if ( Checking ) 
-        {
-            if ( length > array.length )    error("Bad slice") ;
-            if ( idx > length )             error("No room for insert") ;
-            if ( idx >= array.length )      error("Out of bounds") ;
-            if ( idx < 0  )                 error("Negative index for insert") ;
-        }
-        
-        // Shuffle up one place
-        if ( idx < length )
-            shiftUp(array, idx, length) ;
-        array[idx] = item ;
-    }
-
-    /** Delete at a specific index, given a active area of 'length' elements of the array
-     * @param <T>
-     * @param array
-     * @param idx
-     * @param length
-     * @return Element at slot idx
-     */
-    public static <T> T delete(T[] array, int idx, int length)
-    {
-        T rc = array[idx] ;
-        // Shuffle down one place
-        shiftDown(array, idx, length) ;
-        return rc ;
-    }
-    
-    /** Delete at a specific index
-     * @param <T>
-     * @param array
-     * @param idx
-     * @return Element at slot idx
-     */
-    public static <T> T delete(T[] array, int idx)
-    { return delete(array, idx, array.length) ; }
-
-    
-    /**
-     * Clear the array. 
-     * @param array
-     */
-    public static <T> void clear(T[] array)
-    {
-        clear(array, 0) ;
-    }
-    
-    public static <T> void clear(T[] array, int idx)
-    {
-        clear(array, idx, array.length-idx) ;
-    }
-
-    public static <T> void clear(T[] array, int idx, int num)
-    {
-        num = adjustLength(array, idx, num) ;
-
-        for ( int i = 0 ; i < num ; i++ )
-            array[idx+i] = null ;
-    }
-    
-    /** Copy the byte array (not the contents
-     * @param bytes     THe array to copy from
-     */
-    public static byte[] copyOf(byte[] bytes)
-    {
-        // Java6: Arrays.copyOf(bytes, bytes.length)
-        return copyOf(bytes, 0, bytes.length) ;
-//        byte[] newByteArray = new byte[bytes.length] ;
-//        System.arraycopy(bytes, 0, newByteArray, 0, bytes.length) ;
-//        return newByteArray ;
-    }
-    
-    /** Copy of the byte array, start from given point
-     * @param bytes     THe array to copy from
-     * @param start     Starting point.
-     */
-    public static byte[] copyOf(byte[] bytes, int start)
-    {
-        // Java6: Arrays.copyOf(bytes, bytes.length)
-        return copyOf(bytes, start, bytes.length-start) ;
-    }
-    
-    /** Copy of the byte array, start from given point */
-    public static byte[] copyOf(byte[] bytes, int start, int length)
-    {
-        byte[] newByteArray = new byte[length] ;
-        System.arraycopy(bytes, start, newByteArray, 0, length) ;
-        return newByteArray ;
-    }
-
-    /** Truncate a length of from idx of delta to the array length at most */
-    private static <T> int adjustLength(T[] array, int idx, int num)
-    {
-        if ( num+idx <= array.length )
-            return num ;
-        // Overshoot amount.
-        int x = (num+idx)-array.length ;
-        return num-x ;
-    }
-    
-    /** Shift up one place, opening up idx, given an array up to 'length' elements.
-     *  Increases the active length by 1.
-     *
-     */ 
-    public static <T> void shiftUp(T[] array, int idx, int length)    { shiftUpN(array, idx, 1, length) ; }
-
-    /** Shift up N places - increases the active length by N - truncates and eleemnts dropp off the top. */
-    
-    public static <T> void shiftUpN(T[] array, int idx, int places, int length)
-    {
-        //System.out.printf("shiftUpN(,idx=%d,places=%d,length=%d)\n", idx, places, length);
-        if ( places == 0 )
-            return ;
-        
-        if ( places < 0 )
-            error("Negative shift up") ;
-        
-        if ( idx+places > array.length )
-            error("out of bounds: "+(idx+places)) ;
-            
-        int lengthToMove = length-idx-places+1 ;  // Move from idx+1 to the end of slice.
-        
-        if ( length+places > array.length )
-        {
-            //System.out.println("Correct: "+lengthToMove+" => "+(array.length - idx - places)) ;
-            lengthToMove = array.length - idx - places ;
-        }
-
-        if ( lengthToMove < 0 )
-            error("Negative slice") ;
-        
-        if ( lengthToMove > 0 )
-        {
-            //System.out.printf("arraycopy(,src=%d, dst=%d, length=%d)\n", idx, idx+places, lengthToMove);
-            // If equals, no copy needed
-            System.arraycopy(array, idx, array, idx+places, lengthToMove) ;
-        }
-        
-        if ( NullOut )
-            clear(array, idx, places) ;
-    }
-
-    public static <T> void shiftDown(T[] array, int idx, int length)
-    { shiftDownN(array, idx, 1, length) ; }
-
-    public static <T> void shiftDownN(T[] array, int idx, int places, int length)
-    {
-        if ( Checking )
-        {
-            if ( places < 0 )   error("Negative shift down") ;
-            if ( idx+places > length )
-                error("Out of bounds: "+idx) ;
-        }
-        
-        if ( places == 0 )
-            return ;
-        
-        System.arraycopy(array, idx+places, array, idx, length-idx-places) ;
-        if ( NullOut )
-            clear(array, length-places, places) ;
-    }
-
-    // ----
-    
-    public static <T> IteratorArray<T> iterator(T[] array)
-    {
-        return IteratorArray.create(array) ;
-    }
-    
-    public static <T> String toString(T[] array)
-    {
-        return Arrays.asList(array).toString();
-    }
-    
-    public static <T> void print(T[] array)
-    {
-        System.out.println(toString(array)) ;
-    }
-    
-    public static void print(int[] array)
-    {
-        List<Integer> x = new ArrayList<Integer>(array.length) ;
-        for ( int i : array )
-            x.add(i) ;
-        System.out.println(x) ;
-    }
-    
-    public static void print(long[] array)
-    {
-        List<Long> x = new ArrayList<Long>(array.length) ;
-        for ( long i : array )
-            x.add(i) ;
-        System.out.println(x) ;
-    }
-
-    // ----
-    
-    private static void error(String msg)
-    { throw new ArrayException(msg) ; }
-    
-    public static class ArrayException extends RuntimeException
-    { 
-        public ArrayException(String msg) { super(msg) ; }
-    }
+package migrate.lib;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.openjena.atlas.iterator.IteratorArray;
+import org.openjena.atlas.lib.Bytes;
+
+/** Utilities for working with arrays including especially for working with a slice in a larger array. 
+ *  This avoids the need to copy/move data outside the slice. 
+ *  Slice starts a zero.
+ *  Shift up extends the slice, moving elements into the area above the slice.
+ *  Shift down introduces nulls at the top of the slice array.
+ * @see Bytes for operations 
+ */
+public class ArrayOps
+{
+    static boolean Checking = true ;
+    public static final boolean NullOut =  true ;
+
+//    /** Check a zero-based array slice */ 
+//    public static <T> void checkSlice(T[] array, int idx, int length)
+//    {
+//        if ( length > array.length )        error("Bad length") ;
+//        if ( idx >= length )                error("Index out of bounds of slice") ;
+//        if ( idx < 0  )                     error("Negative index for slice") ;
+//    }
+    
+    // -- Variable slice
+    
+    // insert(array, slice, int idx) ;
+    // shiftUp(array, slice, idx) 
+    // shiftUp(array, slice, idx) -> Slice.
+    
+    // Repeat for int[] and long[]
+
+    
+    /** Insert an element at a specific index
+     * @param <T>
+     * @param array
+     * @param idx
+     * @param item
+     */
+    public static <T> void insert(T[] array, int idx, T item)
+    {
+        insert(array, idx, item, array.length) ;
+    }
+    
+    /** Insert an element at a specific index, given a active area of 'length' elements.
+     * @param <T>
+     * @param array
+     * @param idx
+     * @param item
+     * @param length
+     */
+    public static <T> void insert(T[] array, int idx, T item, int length)
+    {
+        // Can insert one beyond the array slice.
+        if ( Checking ) 
+        {
+            if ( length > array.length )    error("Bad slice") ;
+            if ( idx > length )             error("No room for insert") ;
+            if ( idx >= array.length )      error("Out of bounds") ;
+            if ( idx < 0  )                 error("Negative index for insert") ;
+        }
+        
+        // Shuffle up one place
+        if ( idx < length )
+            shiftUp(array, idx, length) ;
+        array[idx] = item ;
+    }
+
+    /** Delete at a specific index, given a active area of 'length' elements of the array
+     * @param <T>
+     * @param array
+     * @param idx
+     * @param length
+     * @return Element at slot idx
+     */
+    public static <T> T delete(T[] array, int idx, int length)
+    {
+        T rc = array[idx] ;
+        // Shuffle down one place
+        shiftDown(array, idx, length) ;
+        return rc ;
+    }
+    
+    /** Delete at a specific index
+     * @param <T>
+     * @param array
+     * @param idx
+     * @return Element at slot idx
+     */
+    public static <T> T delete(T[] array, int idx)
+    { return delete(array, idx, array.length) ; }
+
+    
+    /**
+     * Clear the array. 
+     * @param array
+     */
+    public static <T> void clear(T[] array)
+    {
+        clear(array, 0) ;
+    }
+    
+    public static <T> void clear(T[] array, int idx)
+    {
+        clear(array, idx, array.length-idx) ;
+    }
+
+    public static <T> void clear(T[] array, int idx, int num)
+    {
+        num = adjustLength(array, idx, num) ;
+
+        for ( int i = 0 ; i < num ; i++ )
+            array[idx+i] = null ;
+    }
+    
+    /** Copy the byte array (not the contents
+     * @param bytes     THe array to copy from
+     */
+    public static byte[] copyOf(byte[] bytes)
+    {
+        // Java6: Arrays.copyOf(bytes, bytes.length)
+        return copyOf(bytes, 0, bytes.length) ;
+//        byte[] newByteArray = new byte[bytes.length] ;
+//        System.arraycopy(bytes, 0, newByteArray, 0, bytes.length) ;
+//        return newByteArray ;
+    }
+    
+    /** Copy of the byte array, start from given point
+     * @param bytes     THe array to copy from
+     * @param start     Starting point.
+     */
+    public static byte[] copyOf(byte[] bytes, int start)
+    {
+        // Java6: Arrays.copyOf(bytes, bytes.length)
+        return copyOf(bytes, start, bytes.length-start) ;
+    }
+    
+    /** Copy of the byte array, start from given point */
+    public static byte[] copyOf(byte[] bytes, int start, int length)
+    {
+        byte[] newByteArray = new byte[length] ;
+        System.arraycopy(bytes, start, newByteArray, 0, length) ;
+        return newByteArray ;
+    }
+
+    /** Truncate a length of from idx of delta to the array length at most */
+    private static <T> int adjustLength(T[] array, int idx, int num)
+    {
+        if ( num+idx <= array.length )
+            return num ;
+        // Overshoot amount.
+        int x = (num+idx)-array.length ;
+        return num-x ;
+    }
+    
+    /** Shift up one place, opening up idx, given an array up to 'length' elements.
+     *  Increases the active length by 1.
+     *
+     */ 
+    public static <T> void shiftUp(T[] array, int idx, int length)    { shiftUpN(array, idx, 1, length) ; }
+
+    /** Shift up N places - increases the active length by N - truncates and eleemnts dropp off the top. */
+    
+    public static <T> void shiftUpN(T[] array, int idx, int places, int length)
+    {
+        //System.out.printf("shiftUpN(,idx=%d,places=%d,length=%d)\n", idx, places, length);
+        if ( places == 0 )
+            return ;
+        
+        if ( places < 0 )
+            error("Negative shift up") ;
+        
+        if ( idx+places > array.length )
+            error("out of bounds: "+(idx+places)) ;
+            
+        int lengthToMove = length-idx-places+1 ;  // Move from idx+1 to the end of slice.
+        
+        if ( length+places > array.length )
+        {
+            //System.out.println("Correct: "+lengthToMove+" => "+(array.length - idx - places)) ;
+            lengthToMove = array.length - idx - places ;
+        }
+
+        if ( lengthToMove < 0 )
+            error("Negative slice") ;
+        
+        if ( lengthToMove > 0 )
+        {
+            //System.out.printf("arraycopy(,src=%d, dst=%d, length=%d)\n", idx, idx+places, lengthToMove);
+            // If equals, no copy needed
+            System.arraycopy(array, idx, array, idx+places, lengthToMove) ;
+        }
+        
+        if ( NullOut )
+            clear(array, idx, places) ;
+    }
+
+    public static <T> void shiftDown(T[] array, int idx, int length)
+    { shiftDownN(array, idx, 1, length) ; }
+
+    public static <T> void shiftDownN(T[] array, int idx, int places, int length)
+    {
+        if ( Checking )
+        {
+            if ( places < 0 )   error("Negative shift down") ;
+            if ( idx+places > length )
+                error("Out of bounds: "+idx) ;
+        }
+        
+        if ( places == 0 )
+            return ;
+        
+        System.arraycopy(array, idx+places, array, idx, length-idx-places) ;
+        if ( NullOut )
+            clear(array, length-places, places) ;
+    }
+
+    // ----
+    
+    public static <T> IteratorArray<T> iterator(T[] array)
+    {
+        return IteratorArray.create(array) ;
+    }
+    
+    public static <T> String toString(T[] array)
+    {
+        return Arrays.asList(array).toString();
+    }
+    
+    public static <T> void print(T[] array)
+    {
+        System.out.println(toString(array)) ;
+    }
+    
+    public static void print(int[] array)
+    {
+        List<Integer> x = new ArrayList<Integer>(array.length) ;
+        for ( int i : array )
+            x.add(i) ;
+        System.out.println(x) ;
+    }
+    
+    public static void print(long[] array)
+    {
+        List<Long> x = new ArrayList<Long>(array.length) ;
+        for ( long i : array )
+            x.add(i) ;
+        System.out.println(x) ;
+    }
+
+    // ----
+    
+    private static void error(String msg)
+    { throw new ArrayException(msg) ; }
+    
+    public static class ArrayException extends RuntimeException
+    { 
+        public ArrayException(String msg) { super(msg) ; }
+    }
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteArray.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteArray.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteArray.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteArray.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,189 +16,189 @@
  * limitations under the License.
  */
 
-package migrate.lib;
-
-import java.util.Iterator ;
-import java.util.NoSuchElementException ;
-
-import org.openjena.atlas.AtlasException ;
-
-
-/** An expanding byte array.
- *  Like a byte[] but it can grow. 
- */
-public final class ByteArray //implements java.lang.Iterable<Byte>
-{
-    private int length ;
-    private byte[] bytes ;
-    
-    /** Allocate size bytes of active space */ 
-    public ByteArray(int size)
-    { 
-        this(size, size) ;
-    }
-    
-    /** Allocate empty array (may have a few bytes for expansion) */ 
-    public ByteArray()
-    { this(0, 8) ; }
-    
-    /** Allocate an array with a hint to sufficient space for growth */
-    public ByteArray(int size, int initialAllocation)
-    {
-        bytes = new byte[initialAllocation] ;
-        length = size ;
-    }
-    
-    /** Return a byte */
-    public byte get(int idx)
-    {
-        check(idx) ;
-        return bytes[idx] ;
-    }
-
-    /** Set a byte */
-    public void set(int idx, byte b)
-    {
-        if ( idx == length)
-        {
-            add(b) ;
-            return ;
-        }
-        
-        check(idx) ;
-    
-        bytes[idx] = b ;
-    }
-
-    /** add a byte to the end of the array */
-    public void add(byte b)
-    {
-        if ( length == bytes.length )
-            realloc(8) ;
-        bytes[length] = b ;
-        length++ ;
-    }
-    
-    /** add bytes to the end of the array */
-    public void add(byte[] b)
-    { add(b, 0, b.length) ; }
-
-    /** add bytes to the end of the array */
-    public void add(byte[] b, int start, int len)
-    {
-        if ( length+len >= bytes.length )
-            realloc(len) ;
-        System.arraycopy(bytes, length, b, start, len) ;
-    }
-
-    
-    /** add copy ByteArray bytes to the end of the array */
-    public void add(ByteArray b)
-    {
-        add(b.bytes, 0, b.length) ;
-    }
-    
-    private void realloc(int minGrowth)
-    {
-        int currLen = bytes.length ;
-        int newLen = currLen+currLen/2+1 ;
-        if ( newLen-currLen < minGrowth )
-            newLen = currLen + minGrowth ; 
-        
-        byte[] bytes2 = new byte[newLen] ;
-        System.arraycopy(bytes, 0, bytes2, 0, currLen) ;
-        // length still the same.
-    }
-
-    /** Current length */
-    public int length() { return length ; }
-    
-    /** Current max size without reallocation */
-    public int currentAlloc() { return bytes.length ; }
-
-    public void ensure(int size)
-    {
-        if ( size < bytes.length )
-            realloc(bytes.length-size) ;
-    }
-    
-    private final void check(int idx)
-    {
-        if ( idx < 0 || idx > length)
-            throw new AtlasException(String.format("Out of bounds %d [0, %d]", idx, length)) ;
-    }
-
-    // Don't encourage iterators - boxing overhead.
-    //@Override
-    public Iterator<Byte> iterator()
-    {
-        return new IteratorByteArray(bytes, 0, length) ;
-    }
-
-    static class IteratorByteArray implements Iterator<Byte>
-    {
-        private int idx ;
-        private byte[] bytes ;
-        private int finishIdx ;
-        
-        public IteratorByteArray(byte[] bytes, int start, int finish)
-        {
-            if ( start < 0 )
-                throw new IllegalArgumentException("Start: "+start) ;
-
-            if ( start > finish )
-                throw new IllegalArgumentException("Start >= finish: "+start+" >= "+finish) ;
-
-            // Instead: truncate to array length          
-            //        if ( finish > array.length )
-            //            throw new IllegalArgumentException("Finish outside array") ;
-            //        
-            // Instead: immediate end iterator                
-            //        if ( start >= array.length )
-            //            throw new IllegalArgumentException("Start outside array") ;
-
-            this.bytes = bytes ;
-            idx = start ;
-            finishIdx = finish ;
-            if ( idx < 0 )
-                idx = 0 ;
-            if ( finishIdx > bytes.length ) 
-                finishIdx = bytes.length ;
-        }
-
-    //@Override
-    @Override
-    public boolean hasNext()
-    {
-//        if ( idx < 0 )
-//            return false ;
-        if ( idx >= finishIdx )
-            return false ;
-        return true ;
-    }
-
-    public byte current()
-    {
-        if ( idx >= finishIdx )
-            throw new NoSuchElementException() ;
-        return bytes[idx] ;
-    }
-    
-    //@Override
-    @Override
-    public Byte next()
-    {
-        if ( ! hasNext() )
-            throw new NoSuchElementException() ; 
-        return bytes[idx++] ;
-    }
-
-    //@Override
-    @Override
-    public void remove()
-    { throw new UnsupportedOperationException("IterBytes") ; }
-        
-    }
-
-    
+package migrate.lib;
+
+import java.util.Iterator ;
+import java.util.NoSuchElementException ;
+
+import org.openjena.atlas.AtlasException ;
+
+
+/** An expanding byte array.
+ *  Like a byte[] but it can grow. 
+ */
+public final class ByteArray //implements java.lang.Iterable<Byte>
+{
+    private int length ;
+    private byte[] bytes ;
+    
+    /** Allocate size bytes of active space */ 
+    public ByteArray(int size)
+    { 
+        this(size, size) ;
+    }
+    
+    /** Allocate empty array (may have a few bytes for expansion) */ 
+    public ByteArray()
+    { this(0, 8) ; }
+    
+    /** Allocate an array with a hint to sufficient space for growth */
+    public ByteArray(int size, int initialAllocation)
+    {
+        bytes = new byte[initialAllocation] ;
+        length = size ;
+    }
+    
+    /** Return a byte */
+    public byte get(int idx)
+    {
+        check(idx) ;
+        return bytes[idx] ;
+    }
+
+    /** Set a byte */
+    public void set(int idx, byte b)
+    {
+        if ( idx == length)
+        {
+            add(b) ;
+            return ;
+        }
+        
+        check(idx) ;
+    
+        bytes[idx] = b ;
+    }
+
+    /** add a byte to the end of the array */
+    public void add(byte b)
+    {
+        if ( length == bytes.length )
+            realloc(8) ;
+        bytes[length] = b ;
+        length++ ;
+    }
+    
+    /** add bytes to the end of the array */
+    public void add(byte[] b)
+    { add(b, 0, b.length) ; }
+
+    /** add bytes to the end of the array */
+    public void add(byte[] b, int start, int len)
+    {
+        if ( length+len >= bytes.length )
+            realloc(len) ;
+        System.arraycopy(bytes, length, b, start, len) ;
+    }
+
+    
+    /** add copy ByteArray bytes to the end of the array */
+    public void add(ByteArray b)
+    {
+        add(b.bytes, 0, b.length) ;
+    }
+    
+    private void realloc(int minGrowth)
+    {
+        int currLen = bytes.length ;
+        int newLen = currLen+currLen/2+1 ;
+        if ( newLen-currLen < minGrowth )
+            newLen = currLen + minGrowth ; 
+        
+        byte[] bytes2 = new byte[newLen] ;
+        System.arraycopy(bytes, 0, bytes2, 0, currLen) ;
+        // length still the same.
+    }
+
+    /** Current length */
+    public int length() { return length ; }
+    
+    /** Current max size without reallocation */
+    public int currentAlloc() { return bytes.length ; }
+
+    public void ensure(int size)
+    {
+        if ( size < bytes.length )
+            realloc(bytes.length-size) ;
+    }
+    
+    private final void check(int idx)
+    {
+        if ( idx < 0 || idx > length)
+            throw new AtlasException(String.format("Out of bounds %d [0, %d]", idx, length)) ;
+    }
+
+    // Don't encourage iterators - boxing overhead.
+    //@Override
+    public Iterator<Byte> iterator()
+    {
+        return new IteratorByteArray(bytes, 0, length) ;
+    }
+
+    static class IteratorByteArray implements Iterator<Byte>
+    {
+        private int idx ;
+        private byte[] bytes ;
+        private int finishIdx ;
+        
+        public IteratorByteArray(byte[] bytes, int start, int finish)
+        {
+            if ( start < 0 )
+                throw new IllegalArgumentException("Start: "+start) ;
+
+            if ( start > finish )
+                throw new IllegalArgumentException("Start >= finish: "+start+" >= "+finish) ;
+
+            // Instead: truncate to array length          
+            //        if ( finish > array.length )
+            //            throw new IllegalArgumentException("Finish outside array") ;
+            //        
+            // Instead: immediate end iterator                
+            //        if ( start >= array.length )
+            //            throw new IllegalArgumentException("Start outside array") ;
+
+            this.bytes = bytes ;
+            idx = start ;
+            finishIdx = finish ;
+            if ( idx < 0 )
+                idx = 0 ;
+            if ( finishIdx > bytes.length ) 
+                finishIdx = bytes.length ;
+        }
+
+    //@Override
+    @Override
+    public boolean hasNext()
+    {
+//        if ( idx < 0 )
+//            return false ;
+        if ( idx >= finishIdx )
+            return false ;
+        return true ;
+    }
+
+    public byte current()
+    {
+        if ( idx >= finishIdx )
+            throw new NoSuchElementException() ;
+        return bytes[idx] ;
+    }
+    
+    //@Override
+    @Override
+    public Byte next()
+    {
+        if ( ! hasNext() )
+            throw new NoSuchElementException() ; 
+        return bytes[idx++] ;
+    }
+
+    //@Override
+    @Override
+    public void remove()
+    { throw new UnsupportedOperationException("IterBytes") ; }
+        
+    }
+
+    
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteIO.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteIO.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteIO.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteIO.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,36 +16,36 @@
  * limitations under the License.
  */
 
-package migrate.lib;
-
-import java.nio.ByteBuffer;
-
-public class ByteIO
-{
-    /* Interfaces and implementations for one-byte-at-a-time operations */ 
-    
-    interface ByteSource { public byte get() ; }
-    interface ByteSink { public void put(byte b) ; }
-    
-    static class ByteSinkArray implements ByteSink
-    {
-        private byte[] bytes ;
-        private int idx ;
-        ByteSinkArray(byte[] bytes) { this(bytes, 0) ; }
-        ByteSinkArray(byte[] bytes, int start) { this.bytes = bytes ; this.idx = start ; }
-        @Override
-        public void put(byte b)
-        { bytes[idx++] = b ; }
-    }
-
-    static class ByteSinkBuffer implements ByteSink
-    {
-        private ByteBuffer bytes ;
-        private int idx ;
-        ByteSinkBuffer(ByteBuffer bytes, int start) { this.bytes = bytes ; this.idx = start ; }
-        @Override
-        public void put(byte b)
-        { bytes.put(idx++ , b); }
-    }
-
+package migrate.lib;
+
+import java.nio.ByteBuffer;
+
+public class ByteIO
+{
+    /* Interfaces and implementations for one-byte-at-a-time operations */ 
+    
+    interface ByteSource { public byte get() ; }
+    interface ByteSink { public void put(byte b) ; }
+    
+    static class ByteSinkArray implements ByteSink
+    {
+        private byte[] bytes ;
+        private int idx ;
+        ByteSinkArray(byte[] bytes) { this(bytes, 0) ; }
+        ByteSinkArray(byte[] bytes, int start) { this.bytes = bytes ; this.idx = start ; }
+        @Override
+        public void put(byte b)
+        { bytes[idx++] = b ; }
+    }
+
+    static class ByteSinkBuffer implements ByteSink
+    {
+        private ByteBuffer bytes ;
+        private int idx ;
+        ByteSinkBuffer(ByteBuffer bytes, int start) { this.bytes = bytes ; this.idx = start ; }
+        @Override
+        public void put(byte b)
+        { bytes.put(idx++ , b); }
+    }
+
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/TestSuiteByReflection.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/TestSuiteByReflection.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/TestSuiteByReflection.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/TestSuiteByReflection.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,43 +16,43 @@
  * limitations under the License.
  */
 
-package migrate.lib;
-
-import java.lang.reflect.Method;
-
-import junit.framework.TestSuite;
-
-/** This class provides an indirect way to call a JUnit3 test suite - assumes a static "suite" operation. 
- */ 
-
-public class TestSuiteByReflection extends TestSuite
-{
-    private static TestSuite suiteByReflection(String className)
-    {
-        // Reflection to invoke <class>.suite() and return a TestSuite.
-        Class<?> cmd = null ;
-        try { cmd = Class.forName(className) ; }
-        catch (ClassNotFoundException ex)
-        {
-            return null ; 
-        }
-
-        Method method = null ;
-        try { method = cmd.getMethod("suite", new Class[]{}) ; }
-        catch (NoSuchMethodException ex)
-        {
-            System.err.println("'suite' not found but the class '"+className+"' was") ;
-            return null ;
-        }
-
-        try 
-        {
-            return (TestSuite)method.invoke(null, new Object[]{}) ;
-        } catch (Exception ex)
-        {
-            System.err.println("Failed to invoke static method 'suite'"+ex.getMessage()) ;
-            //ex.printStackTrace(System.err) ;
-        }
-        return null ;
-    }
+package migrate.lib;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestSuite;
+
+/** This class provides an indirect way to call a JUnit3 test suite - assumes a static "suite" operation. 
+ */ 
+
+public class TestSuiteByReflection extends TestSuite
+{
+    private static TestSuite suiteByReflection(String className)
+    {
+        // Reflection to invoke <class>.suite() and return a TestSuite.
+        Class<?> cmd = null ;
+        try { cmd = Class.forName(className) ; }
+        catch (ClassNotFoundException ex)
+        {
+            return null ; 
+        }
+
+        Method method = null ;
+        try { method = cmd.getMethod("suite", new Class[]{}) ; }
+        catch (NoSuchMethodException ex)
+        {
+            System.err.println("'suite' not found but the class '"+className+"' was") ;
+            return null ;
+        }
+
+        try 
+        {
+            return (TestSuite)method.invoke(null, new Object[]{}) ;
+        } catch (Exception ex)
+        {
+            System.err.println("Failed to invoke static method 'suite'"+ex.getMessage()) ;
+            //ex.printStackTrace(System.err) ;
+        }
+        return null ;
+    }
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/VarInteger.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/VarInteger.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/VarInteger.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/VarInteger.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,261 +16,261 @@
  * limitations under the License.
  */
 
-package migrate.lib;
-
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-
-/** Variable length integers for tight packing into byte arrays and ByteBuffers.
- *  Packing is 7bits per byte and is the same format as vints in Lucene. 
- */
-public final class VarInteger
-{
-    public static void main(String ... argv) { varint() ; } 
-    private static void varint()
-    {
-        long[] testValues = {0, 1, 127, 128, 129, (1L<<63)-1} ; // { 0 , 5 , 127, 128 , 0x1000} ;
-        for ( long x : testValues )
-        {
-            VarInteger vint = new VarInteger(x) ;
-            System.out.printf("0x%04X => %s\n", x , vint) ;
-            long z = vint.value() ;
-            System.out.printf("0x%04X => %s ==> 0x%04X\n", x , vint, z) ;
-        }
-    }
-    
-    /* See:
-        http://lucene.apache.org/java/docs/fileformats.html#VInt
-        FYI: src/java/org/apache/lucene/store/IndexInput.java, IndexOutput.java
-          but this code is for ByteBuffers.
-    */
-    
-    /* Encoding
-     * Low to high, 7 bits (low end) per byte.
-     * High bit is 1 for "more" and 0 for last byte.
-     */
-    
-    // Either 1: ByteSink etc.
-    // or 2: ByteBuffer + wrappers (what about OutputStreams?)
-    
-    static final long maxValue = (1L<<63) - 1 ;
- 
-    // The core encoder and decoder could take a ByteSink/ByteSource - that
-    // would be a well-structured way to do it but of extra objects for each
-    // number might become non-trivial.
-    // Currently, works specifically on ByteBuffers.
-    
-    public static byte[] encode(long value)
-    {
-        // Max length is ceiling(63/7) = (63+6)/7 = 9  
-        // Unlikely.
-        if ( value > maxValue )
-            throw new IllegalArgumentException("Too large: "+value) ;
-        int len = calcLength(value) ;
-        byte[] bytes = new byte[len] ;
-        encode(ByteBuffer.wrap(bytes), 0, value) ;
-        return bytes ;
-    }
-    
-    // Relative vs absolute put/get.
-    
-    public static int encode(ByteBuffer bytes, long value) { return encode(bytes, bytes.position(), value) ; }
-    
-    public static int encode(ByteBuffer bytes, int startIdx, long value)
-    {
-        long N = value ;
-        int idx = startIdx ;
-        byte b = 0 ;
-        while (true)
-        {
-            b = (byte)(N&0x7FL) ;
-            N = ( N >>> 7 ) ;
-            if ( N == 0 )
-                break ;
-            bytes.put(idx, (byte) (b | 0x80)) ;
-            idx ++ ;
-        }
-        bytes.put(idx, b) ;
-        return (idx+1)-startIdx ;
-    }
-
-    public static long decode(byte[] bytes, int idx)
-    { return decode(ByteBuffer.wrap(bytes), idx) ; }
-    
-    public static long decode(ByteBuffer bytes)
-    { return decode(bytes, 0) ; }
-    
-    public static long decode(ByteBuffer bytes, int idx)
-    {
-        // Low to high
-        long value = 0 ;
-        int shift = 0 ;
-        
-        while (true)
-        {
-            byte b = bytes.get(idx) ;
-            value |= (b & 0x7FL) << shift ;
-            if ( (b & 0x80) == 0 )
-                  return value ;
-            shift +=  7 ;
-            idx++ ;
-        }
-    }
-    
-    /** Make a VarInteger from the bytes found start from idx */ 
-    public static VarInteger make(ByteBuffer bb, int idx)
-    {
-        int start = idx ;
-        while (true)
-        {
-            byte b = bb.get(idx) ;
-            if ( (b & 0x80) == 0 )
-                  break ;
-            idx++ ;
-        }
-        // points idx at he last bytes
-        int len = idx-start+1 ;
-        byte[] bytes = new byte[len] ;
-        for ( int i = 0 ; i < len ; i++ )
-            bytes[i] = bb.get(start+i) ;
-        return make(bytes) ;
-    }
-    
-    /** Make a VarInteger from the bytes found start from idx */ 
-    public static VarInteger make(byte[] bytes)
-    {
-        return new VarInteger(bytes) ;
-    }
-    
-    private static String toString(byte[] bytes) { return toString(bytes, 0) ; }
-    private static String toString(byte[] bytes, int idx)
-    {
-        StringBuilder buff = new StringBuilder() ;
-        buff.append("[") ;
-        
-        String sep = null ;
-        while(true)
-        {
-            byte b = bytes[idx] ; 
-            if ( sep != null )
-                buff.append(sep) ;
-            else
-                sep = ", " ;
-            buff.append(String.format("%02X", b)) ;
-            if ( b >= 0 )
-                break ;
-            idx++ ;
-        }
-        buff.append("]") ;
-        return buff.toString() ;
-    }
-    
-    public static boolean equals(long value, byte[] bytes) { return equals(value, ByteBuffer.wrap(bytes)) ; }
-    
-    public static boolean equals(long value, ByteBuffer bytes) { return equals(value, bytes, 0) ; }
-    
-    public static boolean equals(long value, ByteBuffer bytes, int idx)
-    {
-        long x = decode(bytes, idx) ;
-        return x == value ;
-    }
-    
-    // ---- Factory
-    
-    // -- Some constants
-    public static VarInteger varint_0 = new VarInteger(0) ;
-    public static VarInteger varint_1 = new VarInteger(1) ;
-    public static VarInteger varint_2 = new VarInteger(2) ;
-
-    /** Return a VarInteger that encodes the value */
-    public static VarInteger valueOf(long value)
-    { 
-        if ( value == 0 ) return varint_0 ;
-        if ( value == 1 ) return varint_1 ;
-        if ( value == 2 ) return varint_2 ;
-        return new VarInteger(value) ;
-    }
-    
-    public static int lengthOf(long value)
-    {
-        return calcLengthTable(value) ;
-    }
-    
-    // ---- The object
-
-    byte[] bytes ;
-    long value = -1 ;
-    
-    private VarInteger(long value)
-    {
-        Integer.valueOf(0) ;
-        if ( value < 0 )
-            throw new IllegalArgumentException("Positive integers only") ;
-        bytes = encode(value) ;
-    }
-    
-    private VarInteger(byte[] bytes)
-    {
-        if ( bytes.length == 0 )
-            throw new IllegalArgumentException("Zero length byte[]") ;
-        this.bytes = bytes ;
-    }
-    
-    public int length()     { return bytes.length ; }
-    public byte[] bytes()   { return bytes ; }
-    
-    public long value()
-    { 
-        if ( value == -1 )
-            value = decode(bytes, 0) ;
-        return value ;
-    }
-    
-    @Override
-    public int hashCode()
-    { return Arrays.hashCode(bytes) ; }
-    
-    @Override
-    public boolean equals(Object other)
-    {
-        if ( ! ( other instanceof VarInteger ) ) return false ;
-        VarInteger vint = (VarInteger)other ;
-        return Arrays.equals(bytes, vint.bytes) ;
-    }
-    
-    @Override
-    public String toString() { return toString(bytes) ; }
-    
-    // Next is the impossible (it's the sign bit) 1L<<63
-    static final long VarIntLengths[] = { 1L<<7 , 1L<<14 , 1L<<21 , 1L<<28 , 1L<<35, 1L<<42, 1L<<49, 1L<<56 } ;
-
-    // By semi-lookup.
-    static int calcLengthTable(long value)
-    {
-        int len = -1 ;
-        for ( int i = 0 ; i < VarIntLengths.length ; i++ )
-        {
-            if ( value < VarIntLengths[i] )
-                return i+1 ; 
-        }
-        //throw new IllegalArgumentException("Value too long: "+value) ;
-        return VarIntLengths.length+1 ;
-    }
-    
-    // By calculation.
-    static int calcLength(long value)
-    {
-        int len = 1 ;   // The byte with high bit zero.
-        long N = value ;
-        byte b = 0 ;
-        while (true)
-        {
-            N >>>= 7 ;
-            if ( N == 0 )
-                break ;
-            len ++ ;
-        }
-        return len ;
-    }
-
+package migrate.lib;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+/** Variable length integers for tight packing into byte arrays and ByteBuffers.
+ *  Packing is 7bits per byte and is the same format as vints in Lucene. 
+ */
+public final class VarInteger
+{
+    public static void main(String ... argv) { varint() ; } 
+    private static void varint()
+    {
+        long[] testValues = {0, 1, 127, 128, 129, (1L<<63)-1} ; // { 0 , 5 , 127, 128 , 0x1000} ;
+        for ( long x : testValues )
+        {
+            VarInteger vint = new VarInteger(x) ;
+            System.out.printf("0x%04X => %s\n", x , vint) ;
+            long z = vint.value() ;
+            System.out.printf("0x%04X => %s ==> 0x%04X\n", x , vint, z) ;
+        }
+    }
+    
+    /* See:
+        http://lucene.apache.org/java/docs/fileformats.html#VInt
+        FYI: src/java/org/apache/lucene/store/IndexInput.java, IndexOutput.java
+          but this code is for ByteBuffers.
+    */
+    
+    /* Encoding
+     * Low to high, 7 bits (low end) per byte.
+     * High bit is 1 for "more" and 0 for last byte.
+     */
+    
+    // Either 1: ByteSink etc.
+    // or 2: ByteBuffer + wrappers (what about OutputStreams?)
+    
+    static final long maxValue = (1L<<63) - 1 ;
+ 
+    // The core encoder and decoder could take a ByteSink/ByteSource - that
+    // would be a well-structured way to do it but of extra objects for each
+    // number might become non-trivial.
+    // Currently, works specifically on ByteBuffers.
+    
+    public static byte[] encode(long value)
+    {
+        // Max length is ceiling(63/7) = (63+6)/7 = 9  
+        // Unlikely.
+        if ( value > maxValue )
+            throw new IllegalArgumentException("Too large: "+value) ;
+        int len = calcLength(value) ;
+        byte[] bytes = new byte[len] ;
+        encode(ByteBuffer.wrap(bytes), 0, value) ;
+        return bytes ;
+    }
+    
+    // Relative vs absolute put/get.
+    
+    public static int encode(ByteBuffer bytes, long value) { return encode(bytes, bytes.position(), value) ; }
+    
+    public static int encode(ByteBuffer bytes, int startIdx, long value)
+    {
+        long N = value ;
+        int idx = startIdx ;
+        byte b = 0 ;
+        while (true)
+        {
+            b = (byte)(N&0x7FL) ;
+            N = ( N >>> 7 ) ;
+            if ( N == 0 )
+                break ;
+            bytes.put(idx, (byte) (b | 0x80)) ;
+            idx ++ ;
+        }
+        bytes.put(idx, b) ;
+        return (idx+1)-startIdx ;
+    }
+
+    public static long decode(byte[] bytes, int idx)
+    { return decode(ByteBuffer.wrap(bytes), idx) ; }
+    
+    public static long decode(ByteBuffer bytes)
+    { return decode(bytes, 0) ; }
+    
+    public static long decode(ByteBuffer bytes, int idx)
+    {
+        // Low to high
+        long value = 0 ;
+        int shift = 0 ;
+        
+        while (true)
+        {
+            byte b = bytes.get(idx) ;
+            value |= (b & 0x7FL) << shift ;
+            if ( (b & 0x80) == 0 )
+                  return value ;
+            shift +=  7 ;
+            idx++ ;
+        }
+    }
+    
+    /** Make a VarInteger from the bytes found start from idx */ 
+    public static VarInteger make(ByteBuffer bb, int idx)
+    {
+        int start = idx ;
+        while (true)
+        {
+            byte b = bb.get(idx) ;
+            if ( (b & 0x80) == 0 )
+                  break ;
+            idx++ ;
+        }
+        // points idx at he last bytes
+        int len = idx-start+1 ;
+        byte[] bytes = new byte[len] ;
+        for ( int i = 0 ; i < len ; i++ )
+            bytes[i] = bb.get(start+i) ;
+        return make(bytes) ;
+    }
+    
+    /** Make a VarInteger from the bytes found start from idx */ 
+    public static VarInteger make(byte[] bytes)
+    {
+        return new VarInteger(bytes) ;
+    }
+    
+    private static String toString(byte[] bytes) { return toString(bytes, 0) ; }
+    private static String toString(byte[] bytes, int idx)
+    {
+        StringBuilder buff = new StringBuilder() ;
+        buff.append("[") ;
+        
+        String sep = null ;
+        while(true)
+        {
+            byte b = bytes[idx] ; 
+            if ( sep != null )
+                buff.append(sep) ;
+            else
+                sep = ", " ;
+            buff.append(String.format("%02X", b)) ;
+            if ( b >= 0 )
+                break ;
+            idx++ ;
+        }
+        buff.append("]") ;
+        return buff.toString() ;
+    }
+    
+    public static boolean equals(long value, byte[] bytes) { return equals(value, ByteBuffer.wrap(bytes)) ; }
+    
+    public static boolean equals(long value, ByteBuffer bytes) { return equals(value, bytes, 0) ; }
+    
+    public static boolean equals(long value, ByteBuffer bytes, int idx)
+    {
+        long x = decode(bytes, idx) ;
+        return x == value ;
+    }
+    
+    // ---- Factory
+    
+    // -- Some constants
+    public static VarInteger varint_0 = new VarInteger(0) ;
+    public static VarInteger varint_1 = new VarInteger(1) ;
+    public static VarInteger varint_2 = new VarInteger(2) ;
+
+    /** Return a VarInteger that encodes the value */
+    public static VarInteger valueOf(long value)
+    { 
+        if ( value == 0 ) return varint_0 ;
+        if ( value == 1 ) return varint_1 ;
+        if ( value == 2 ) return varint_2 ;
+        return new VarInteger(value) ;
+    }
+    
+    public static int lengthOf(long value)
+    {
+        return calcLengthTable(value) ;
+    }
+    
+    // ---- The object
+
+    byte[] bytes ;
+    long value = -1 ;
+    
+    private VarInteger(long value)
+    {
+        Integer.valueOf(0) ;
+        if ( value < 0 )
+            throw new IllegalArgumentException("Positive integers only") ;
+        bytes = encode(value) ;
+    }
+    
+    private VarInteger(byte[] bytes)
+    {
+        if ( bytes.length == 0 )
+            throw new IllegalArgumentException("Zero length byte[]") ;
+        this.bytes = bytes ;
+    }
+    
+    public int length()     { return bytes.length ; }
+    public byte[] bytes()   { return bytes ; }
+    
+    public long value()
+    { 
+        if ( value == -1 )
+            value = decode(bytes, 0) ;
+        return value ;
+    }
+    
+    @Override
+    public int hashCode()
+    { return Arrays.hashCode(bytes) ; }
+    
+    @Override
+    public boolean equals(Object other)
+    {
+        if ( ! ( other instanceof VarInteger ) ) return false ;
+        VarInteger vint = (VarInteger)other ;
+        return Arrays.equals(bytes, vint.bytes) ;
+    }
+    
+    @Override
+    public String toString() { return toString(bytes) ; }
+    
+    // Next is the impossible (it's the sign bit) 1L<<63
+    static final long VarIntLengths[] = { 1L<<7 , 1L<<14 , 1L<<21 , 1L<<28 , 1L<<35, 1L<<42, 1L<<49, 1L<<56 } ;
+
+    // By semi-lookup.
+    static int calcLengthTable(long value)
+    {
+        int len = -1 ;
+        for ( int i = 0 ; i < VarIntLengths.length ; i++ )
+        {
+            if ( value < VarIntLengths[i] )
+                return i+1 ; 
+        }
+        //throw new IllegalArgumentException("Value too long: "+value) ;
+        return VarIntLengths.length+1 ;
+    }
+    
+    // By calculation.
+    static int calcLength(long value)
+    {
+        int len = 1 ;   // The byte with high bit zero.
+        long N = value ;
+        byte b = 0 ;
+        while (true)
+        {
+            N >>>= 7 ;
+            if ( N == 0 )
+                break ;
+            len ++ ;
+        }
+        return len ;
+    }
+
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ZigZagInteger.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ZigZagInteger.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ZigZagInteger.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ZigZagInteger.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,163 +16,163 @@
  * limitations under the License.
  */
 
-package migrate.lib;
-
-import java.nio.ByteBuffer ;
-import java.util.Arrays ;
-
-import org.openjena.atlas.lib.NotImplemented ;
-
-/** ZigZag integers: map signed numbers onto unsigned numbers
- *  that can then be @plainlink{VarInteger} encoded.
- */
-public final class ZigZagInteger
-{
-	/*
-	  http://code.google.com/apis/protocolbuffers/docs/encoding.html
-	  0 => 0
-	  -1 => 1
-	  1 => 2
-	  etc
-	  which is (32 bit)
-	  (n << 1) ^ (n >> 31)
-	  The >> is arthimetic shift
-	  n>>32 is zero for n >= 0
-	  n>>32 is all ones for n < 0
-	*/
-
-	public static byte[] encode(long value)
-	{
-		// TODO
-	    //return null ;
-	    throw new NotImplemented("ZigZagInteger.encode") ;
-	}
-
-	public static int encode(ByteBuffer bytes, long value)
-	{ return -1 ; }
-
-	public static int encode(ByteBuffer bytes, int startIdx, long value)
-	{ return -1 ; }
-
-	public static long decode(byte[] bytes, int idx)
-    { return decode(ByteBuffer.wrap(bytes), idx) ; }
-    
-    public static long decode(ByteBuffer bytes)
-    { return decode(bytes, 0) ; }
-    
-    public static long decode(ByteBuffer bytes, int idx)
-    { return -1 ; }
-	
-/** Make a VarInteger from the bytes found start from idx */ 
-    public static ZigZagInteger make(byte[] bytes)
-    {
-        return new ZigZagInteger(bytes) ;
-    }
-    
-    private static String toString(byte[] bytes) { return toString(bytes, 0) ; }
-    private static String toString(byte[] bytes, int idx)
-    { return null ; }
-
-	public static boolean equals(long value, byte[] bytes) { return equals(value, ByteBuffer.wrap(bytes)) ; }
-    
-    public static boolean equals(long value, ByteBuffer bytes) { return equals(value, bytes, 0) ; }
-    
-    public static boolean equals(long value, ByteBuffer bytes, int idx)
-    {
-        long x = decode(bytes, idx) ;
-        return x == value ;
-    }
-    // ---- Factory
-    
-    // -- Some constants
-    public static ZigZagInteger zigzag_0 = new ZigZagInteger(0) ;
-    public static ZigZagInteger zigzag_1 = new ZigZagInteger(1) ;
-    public static ZigZagInteger zigzag_2 = new ZigZagInteger(2) ;
-    public static ZigZagInteger zigzag_minus_1 = new ZigZagInteger(-1) ;
-
-    /** Return a ZigZagInteger that encodes the value */
-    public static ZigZagInteger valueOf(long value)
-    { 
-        if ( value == 0 ) return zigzag_0 ;
-        if ( value == 1 ) return zigzag_1 ;
-        if ( value == -1 ) return zigzag_minus_1 ;
-        if ( value == 2 ) return zigzag_2 ;
-        return new ZigZagInteger(value) ;
-    }
-    
-    public static int lengthOf(long value)
-    {
-        return calcLengthTable(value) ;
-    }
-    
-    // ---- The object
-
-    byte[] bytes ;
-    long value = -1 ;
-    
-    private ZigZagInteger(long value)
-    {
-        if ( value < 0 )
-            throw new IllegalArgumentException("Positive integers only") ;
-        bytes = encode(value) ;
-    }
-    
-    private ZigZagInteger(byte[] bytes)
-    {
-        if ( bytes.length == 0 )
-            throw new IllegalArgumentException("Zero length byte[]") ;
-        this.bytes = bytes ;
-    }
-    
-    public int length()     { return bytes.length ; }
-    public byte[] bytes()   { return bytes ; }
-    
-    public long value()
-    { 
-        if ( value == -1 )
-            value = decode(bytes, 0) ;
-        return value ;
-    }
-    
-    @Override
-    public int hashCode()
-    { return Arrays.hashCode(bytes) ; }
-    
-    @Override
-    public boolean equals(Object other)
-    {
-        if ( ! ( other instanceof ZigZagInteger ) ) return false ;
-        ZigZagInteger vint = (ZigZagInteger)other ;
-        return Arrays.equals(bytes, vint.bytes) ;
-    }
-    
-    @Override
-    public String toString() { return toString(bytes) ; }
-    
-     // Next is the impossible (it's the sign bit) 1L<<63
-     static final long VarIntLengths[] = { 1L<<7 , 1L<<14 , 1L<<21 , 1L<<28 , 1L<<35, 1L<<42, 1L<<49, 1L<<56 } ;
- 
-     // By semi-lookup.
-     private static int calcLengthTable(long value)
-     {
-         // Convert to VarInteger 
-         value = (value << 1) ^ (value >> 63) ;
-         return VarInteger.calcLengthTable(value) ;
-     }
-     
-//     // By calculation.
-//     private static int calcLength(long value)
-//     {
-//         int len = 1 ;   // The byte with high bit zero.
-//         long N = value ;
-//         byte b = 0 ;
-//         while (true)
-//         {
-//             N >>>= 7 ;
-//             if ( N == 0 )
-//                 break ;
-//             len ++ ;
-//         }
-//         return len ;
-//     }
+package migrate.lib;
+
+import java.nio.ByteBuffer ;
+import java.util.Arrays ;
+
+import org.openjena.atlas.lib.NotImplemented ;
+
+/** ZigZag integers: map signed numbers onto unsigned numbers
+ *  that can then be @plainlink{VarInteger} encoded.
+ */
+public final class ZigZagInteger
+{
+	/*
+	  http://code.google.com/apis/protocolbuffers/docs/encoding.html
+	  0 => 0
+	  -1 => 1
+	  1 => 2
+	  etc
+	  which is (32 bit)
+	  (n << 1) ^ (n >> 31)
+	  The >> is arthimetic shift
+	  n>>32 is zero for n >= 0
+	  n>>32 is all ones for n < 0
+	*/
+
+	public static byte[] encode(long value)
+	{
+		// TODO
+	    //return null ;
+	    throw new NotImplemented("ZigZagInteger.encode") ;
+	}
+
+	public static int encode(ByteBuffer bytes, long value)
+	{ return -1 ; }
+
+	public static int encode(ByteBuffer bytes, int startIdx, long value)
+	{ return -1 ; }
+
+	public static long decode(byte[] bytes, int idx)
+    { return decode(ByteBuffer.wrap(bytes), idx) ; }
+    
+    public static long decode(ByteBuffer bytes)
+    { return decode(bytes, 0) ; }
+    
+    public static long decode(ByteBuffer bytes, int idx)
+    { return -1 ; }
+	
+/** Make a VarInteger from the bytes found start from idx */ 
+    public static ZigZagInteger make(byte[] bytes)
+    {
+        return new ZigZagInteger(bytes) ;
+    }
+    
+    private static String toString(byte[] bytes) { return toString(bytes, 0) ; }
+    private static String toString(byte[] bytes, int idx)
+    { return null ; }
+
+	public static boolean equals(long value, byte[] bytes) { return equals(value, ByteBuffer.wrap(bytes)) ; }
+    
+    public static boolean equals(long value, ByteBuffer bytes) { return equals(value, bytes, 0) ; }
+    
+    public static boolean equals(long value, ByteBuffer bytes, int idx)
+    {
+        long x = decode(bytes, idx) ;
+        return x == value ;
+    }
+    // ---- Factory
+    
+    // -- Some constants
+    public static ZigZagInteger zigzag_0 = new ZigZagInteger(0) ;
+    public static ZigZagInteger zigzag_1 = new ZigZagInteger(1) ;
+    public static ZigZagInteger zigzag_2 = new ZigZagInteger(2) ;
+    public static ZigZagInteger zigzag_minus_1 = new ZigZagInteger(-1) ;
+
+    /** Return a ZigZagInteger that encodes the value */
+    public static ZigZagInteger valueOf(long value)
+    { 
+        if ( value == 0 ) return zigzag_0 ;
+        if ( value == 1 ) return zigzag_1 ;
+        if ( value == -1 ) return zigzag_minus_1 ;
+        if ( value == 2 ) return zigzag_2 ;
+        return new ZigZagInteger(value) ;
+    }
+    
+    public static int lengthOf(long value)
+    {
+        return calcLengthTable(value) ;
+    }
+    
+    // ---- The object
+
+    byte[] bytes ;
+    long value = -1 ;
+    
+    private ZigZagInteger(long value)
+    {
+        if ( value < 0 )
+            throw new IllegalArgumentException("Positive integers only") ;
+        bytes = encode(value) ;
+    }
+    
+    private ZigZagInteger(byte[] bytes)
+    {
+        if ( bytes.length == 0 )
+            throw new IllegalArgumentException("Zero length byte[]") ;
+        this.bytes = bytes ;
+    }
+    
+    public int length()     { return bytes.length ; }
+    public byte[] bytes()   { return bytes ; }
+    
+    public long value()
+    { 
+        if ( value == -1 )
+            value = decode(bytes, 0) ;
+        return value ;
+    }
+    
+    @Override
+    public int hashCode()
+    { return Arrays.hashCode(bytes) ; }
+    
+    @Override
+    public boolean equals(Object other)
+    {
+        if ( ! ( other instanceof ZigZagInteger ) ) return false ;
+        ZigZagInteger vint = (ZigZagInteger)other ;
+        return Arrays.equals(bytes, vint.bytes) ;
+    }
+    
+    @Override
+    public String toString() { return toString(bytes) ; }
+    
+     // Next is the impossible (it's the sign bit) 1L<<63
+     static final long VarIntLengths[] = { 1L<<7 , 1L<<14 , 1L<<21 , 1L<<28 , 1L<<35, 1L<<42, 1L<<49, 1L<<56 } ;
+ 
+     // By semi-lookup.
+     private static int calcLengthTable(long value)
+     {
+         // Convert to VarInteger 
+         value = (value << 1) ^ (value >> 63) ;
+         return VarInteger.calcLengthTable(value) ;
+     }
+     
+//     // By calculation.
+//     private static int calcLength(long value)
+//     {
+//         int len = 1 ;   // The byte with high bit zero.
+//         long N = value ;
+//         byte b = 0 ;
+//         while (true)
+//         {
+//             N >>>= 7 ;
+//             if ( N == 0 )
+//                 break ;
+//             len ++ ;
+//         }
+//         return len ;
+//     }
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple1.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple1.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple1.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple1.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,44 +16,44 @@
  * limitations under the License.
  */
 
-package migrate.lib.tuple;
-
-import org.openjena.atlas.lib.Lib;
-
-public class Tuple1<T> extends ZTuple<T>
-{
-    final T item ;
-
-    protected Tuple1(T item) 
-    {
-        this.item = item ; 
-    }
-    
-    @Override
-    protected final boolean equalElements(ZTuple<?> x)
-    {
-        Tuple1<?> z = (Tuple1<?>)x ;
-        return Lib.equal(z.item, item) ; 
-    }
-    
-    @Override
-    public final T get(int idx)
-    {
-        if ( idx != 0 )
-            throw new TupleException("Out of bounds: "+idx) ;
-        return item ;
-    }
-
-    @Override
-    public final int hashCode()
-    {
-        return Lib.hashCodeObject(item, ZTuple.NulItemHashCode) ;
-    }
-
-    @Override
-    public final int size()
-    {
-        return 1 ;
-    }
-
+package migrate.lib.tuple;
+
+import org.openjena.atlas.lib.Lib;
+
+public class Tuple1<T> extends ZTuple<T>
+{
+    final T item ;
+
+    protected Tuple1(T item) 
+    {
+        this.item = item ; 
+    }
+    
+    @Override
+    protected final boolean equalElements(ZTuple<?> x)
+    {
+        Tuple1<?> z = (Tuple1<?>)x ;
+        return Lib.equal(z.item, item) ; 
+    }
+    
+    @Override
+    public final T get(int idx)
+    {
+        if ( idx != 0 )
+            throw new TupleException("Out of bounds: "+idx) ;
+        return item ;
+    }
+
+    @Override
+    public final int hashCode()
+    {
+        return Lib.hashCodeObject(item, ZTuple.NulItemHashCode) ;
+    }
+
+    @Override
+    public final int size()
+    {
+        return 1 ;
+    }
+
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple2.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple2.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple2.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple2.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,51 +16,51 @@
  * limitations under the License.
  */
 
-package migrate.lib.tuple;
-
-import org.openjena.atlas.lib.Lib;
-
-public class Tuple2<T> extends ZTuple<T>
-{
-    final T item1 ;
-    final T item2 ;
-
-    protected Tuple2(T item1, T item2) 
-    {
-        this.item1 = item1 ; 
-        this.item2 = item2 ; 
-    }
-    
-    @Override
-    protected final boolean equalElements(ZTuple<?> x)
-    {
-        Tuple2<?> x1 = (Tuple2<?>)x ;
-        return Lib.equal(x1.item1, item1) && Lib.equal(x1.item2, item2); 
-    }
-    
-    @Override
-    public final T get(int idx)
-    {
-        switch (idx)
-        {
-            case 0: return item1 ;
-            case 1: return item2 ;
-            default: throw new TupleException("Out of bounds: "+idx) ;
-        }
-    }
-
-    @Override
-    public final int hashCode()
-    {
-        return
-            Lib.hashCodeObject(item1, ZTuple.NulItemHashCode)<<1
-            ^ Lib.hashCodeObject(item2, ZTuple.NulItemHashCode) ; 
-    }
-
-    @Override
-    public final int size()
-    {
-        return 2 ;
-    }
-
+package migrate.lib.tuple;
+
+import org.openjena.atlas.lib.Lib;
+
+public class Tuple2<T> extends ZTuple<T>
+{
+    final T item1 ;
+    final T item2 ;
+
+    protected Tuple2(T item1, T item2) 
+    {
+        this.item1 = item1 ; 
+        this.item2 = item2 ; 
+    }
+    
+    @Override
+    protected final boolean equalElements(ZTuple<?> x)
+    {
+        Tuple2<?> x1 = (Tuple2<?>)x ;
+        return Lib.equal(x1.item1, item1) && Lib.equal(x1.item2, item2); 
+    }
+    
+    @Override
+    public final T get(int idx)
+    {
+        switch (idx)
+        {
+            case 0: return item1 ;
+            case 1: return item2 ;
+            default: throw new TupleException("Out of bounds: "+idx) ;
+        }
+    }
+
+    @Override
+    public final int hashCode()
+    {
+        return
+            Lib.hashCodeObject(item1, ZTuple.NulItemHashCode)<<1
+            ^ Lib.hashCodeObject(item2, ZTuple.NulItemHashCode) ; 
+    }
+
+    @Override
+    public final int size()
+    {
+        return 2 ;
+    }
+
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple3.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple3.java?rev=1198733&r1=1198732&r2=1198733&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple3.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple3.java Mon Nov  7 13:36:30 2011
@@ -1,4 +1,4 @@
-/**
+/*
  * 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
@@ -16,57 +16,57 @@
  * limitations under the License.
  */
 
-package migrate.lib.tuple;
-
-import org.openjena.atlas.lib.Lib;
-
-public class Tuple3<T> extends ZTuple<T>
-{
-    final T item1 ;
-    final T item2 ;
-    final T item3 ;
-
-    protected Tuple3(T item1, T item2, T item3) 
-    {
-        this.item1 = item1 ; 
-        this.item2 = item2 ; 
-        this.item3 = item3 ;
-    }
-    
-    @Override
-    protected final boolean equalElements(ZTuple<?> x)
-    {
-        Tuple3<?> x1 = (Tuple3<?>)x ;
-        return  Lib.equal(x1.item1, item1) && 
-                Lib.equal(x1.item2, item2) &&
-                Lib.equal(x1.item3, item3);
-    }
-    
-    @Override
-    public final T get(int idx)
-    {
-        switch (idx)
-        {
-            case 0: return item1 ;
-            case 1: return item2 ;
-            case 2: return item3 ;
-            default: throw new TupleException("Out of bounds: "+idx) ;
-        }
-    }
-
-    @Override
-    public final int hashCode()
-    {
-        int x = Lib.hashCodeObject(item1, ZTuple.NulItemHashCode) ;
-        x = x<<1 ^ Lib.hashCodeObject(item2, ZTuple.NulItemHashCode) ; 
-        x = x<<1 ^ Lib.hashCodeObject(item3, ZTuple.NulItemHashCode)  ;
-        return x ; 
-    }
-
-    @Override
-    public final int size()
-    {
-        return 3 ;
-    }
-
+package migrate.lib.tuple;
+
+import org.openjena.atlas.lib.Lib;
+
+public class Tuple3<T> extends ZTuple<T>
+{
+    final T item1 ;
+    final T item2 ;
+    final T item3 ;
+
+    protected Tuple3(T item1, T item2, T item3) 
+    {
+        this.item1 = item1 ; 
+        this.item2 = item2 ; 
+        this.item3 = item3 ;
+    }
+    
+    @Override
+    protected final boolean equalElements(ZTuple<?> x)
+    {
+        Tuple3<?> x1 = (Tuple3<?>)x ;
+        return  Lib.equal(x1.item1, item1) && 
+                Lib.equal(x1.item2, item2) &&
+                Lib.equal(x1.item3, item3);
+    }
+    
+    @Override
+    public final T get(int idx)
+    {
+        switch (idx)
+        {
+            case 0: return item1 ;
+            case 1: return item2 ;
+            case 2: return item3 ;
+            default: throw new TupleException("Out of bounds: "+idx) ;
+        }
+    }
+
+    @Override
+    public final int hashCode()
+    {
+        int x = Lib.hashCodeObject(item1, ZTuple.NulItemHashCode) ;
+        x = x<<1 ^ Lib.hashCodeObject(item2, ZTuple.NulItemHashCode) ; 
+        x = x<<1 ^ Lib.hashCodeObject(item3, ZTuple.NulItemHashCode)  ;
+        return x ; 
+    }
+
+    @Override
+    public final int size()
+    {
+        return 3 ;
+    }
+
 }