Return-Path: X-Original-To: apmail-incubator-jena-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-jena-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9EC5F796D for ; Fri, 30 Sep 2011 15:02:26 +0000 (UTC) Received: (qmail 4265 invoked by uid 500); 30 Sep 2011 15:02:26 -0000 Delivered-To: apmail-incubator-jena-commits-archive@incubator.apache.org Received: (qmail 4242 invoked by uid 500); 30 Sep 2011 15:02:26 -0000 Mailing-List: contact jena-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jena-dev@incubator.apache.org Delivered-To: mailing list jena-commits@incubator.apache.org Received: (qmail 4207 invoked by uid 99); 30 Sep 2011 15:02:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Sep 2011 15:02:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Sep 2011 15:02:22 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F25432388900; Fri, 30 Sep 2011 15:02:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1177690 [1/7] - in /incubator/jena/Scratch/AFS/Dev/trunk: Archive/ src-lib/main/java/libmisc/ src-lib/main/java/migrate/ src-lib/main/java/migrate/lib/ src-lib/main/java/migrate/lib/tuple/ src-lib/main/java/structure/ src-lib/main/java/str... Date: Fri, 30 Sep 2011 15:01:57 -0000 To: jena-commits@incubator.apache.org From: andy@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20110930150201.F25432388900@eris.apache.org> Author: andy Date: Fri Sep 30 15:01:53 2011 New Revision: 1177690 URL: http://svn.apache.org/viewvc?rev=1177690&view=rev Log: (empty) Added: incubator/jena/Scratch/AFS/Dev/trunk/Archive/ incubator/jena/Scratch/AFS/Dev/trunk/Archive/owl-lang.zip (with props) incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/libmisc/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/libmisc/CodecUTF8.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ArrayOps.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteArray.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteIO.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/TestSuiteByReflection.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/VarInteger.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ZigZagInteger.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple1.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple2.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple3.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple4.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/TupleException.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/TupleN.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/ZTuple.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/_Triple.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/OrderedSet.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/avl/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/avl/AVL.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/avl/AvlIterator.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/avl/AvlNode.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/exthash/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/exthash/ExtHashMem.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/radix/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/radix/RadixIndex.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/radix/RadixNode.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/radix/RadixNodeVisitor.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/radix/RadixNodeVisitorBase.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/radix/RadixTree.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/skiplist/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/skiplist/SkipList.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/skiplist/SkipListException.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/skiplist/SkipListIterator.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/skiplist/SkipListNode.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/tree/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/tree/TreeException.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/tree/TreeNode.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/ttree/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/ttree/TTree.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/ttree/TTreeException.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/ttree/TTreeIterator.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/ttree/TTreeNode.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestArrayOps.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestByteArray.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/migrate/lib/TestVarInteger.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/OrderedSetTest.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/OrderedSetTestBase.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/OrderedSetTestFactory.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/OrderedSetTestLib.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/TS_Structure.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/avl/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/avl/TestAVL.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/exthash/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/exthash/ExtHashMemTestBase.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/exthash/TestExtHashMem.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/radix/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/radix/RadixRun.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/radix/TestRadix.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/skiplist/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/skiplist/SkipListTestBase.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/skiplist/TestSkipList.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/tree/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/tree/TestTree.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/ttree/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/ttree/MainTTree.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/structure/ttree/TestTTree.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/test/ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/test/AVLRun.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/test/ExtHashMemRun.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/test/SkipListRun.java incubator/jena/Scratch/AFS/Dev/trunk/src-lib/test/java/test/TTreeRun.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/algebra2/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/algebra2/AlgebraEngine.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/algebra2/Condition.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/algebra2/JoinEngine.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/algebra2/Table.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/hash/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/hash/FnvHashFunction.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/hash/HashFunction.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/hash/HashFunctionBase.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/hash/HashToInt.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/jenaplus/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/jenaplus/TestMRSW.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/ParserSSE.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/TS_SSE.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/TestSSE_Basic.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/TestSSE_Builder.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/TestSSE_Forms.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/io/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/io/TestTokenIO.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/io/TokenInputStream.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/io/TokenInputStreamBase.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/io/TokenInputStreamWrapper.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/io/TokenOutputStream.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/io/TokenOutputStreamWrapper.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/io/TokenOutputStreamWriter.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/lang/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/lang/LangSSE.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/BaseSearchPF.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/DevSearch.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/GooglePF.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/Search.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/SearchBase.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/SearchException.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/SearchGoogle.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/SearchSite.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/SearchWikipedia.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/search/WikipediaPF.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/storage/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/storage/Indirection.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/storage/Sequence.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/storage/varblock/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/storage/varblock/Design.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/storage/varrecord/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/storage/varrecord/TestVarRecordBlock.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/storage/varrecord/VarRecordBuffer.java incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/tools/ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/tools/Memory.java Added: incubator/jena/Scratch/AFS/Dev/trunk/Archive/owl-lang.zip URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/Archive/owl-lang.zip?rev=1177690&view=auto ============================================================================== Binary file - no diff available. Propchange: incubator/jena/Scratch/AFS/Dev/trunk/Archive/owl-lang.zip ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: 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=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/libmisc/CodecUTF8.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/libmisc/CodecUTF8.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,235 @@ +/** + * 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 libmisc; + +import java.io.ByteArrayInputStream ; +import java.io.IOException ; +import java.io.InputStream ; +import java.io.Reader ; +import java.nio.ByteBuffer ; + +import org.junit.Assert ; +import org.junit.Test ; +import org.openjena.atlas.AtlasException ; +import org.openjena.atlas.io.InStreamUTF8 ; +import org.openjena.atlas.io.OutStreamUTF8 ; +import org.openjena.atlas.lib.Bytes ; + +/** Encode chars as UTF-8 - this code exists to remember the process and requirements. + * Normally, done in a stream and is much more improtant. + * @see InStreamUTF8 + * @see OutStreamUTF8 + */ + +public class CodecUTF8 +{ + public static void main(String ... argv) + { + if ( argv.length != 1 ) + { + System.err.println("Usage: main 'string'"); + System.exit(1) ; + } + + + String s = argv[0] ; + + for ( int i = 0 ; i < s.length() ; i++ ) + { + char ch = s.charAt(i) ; + byte[] bytes = toUTF8(ch) ; + System.out.printf("%c =>", ch) ; + for ( int j = 0 ; j < bytes.length ; j++ ) + System.out.printf(" %02X", bytes[j]) ; + System.out.println() ; + } + } + + + // In Modified UTF-8,[15] the null character (U+0000) is encoded as 0xC0,0x80; this is not valid UTF-8[16] + // Char to bytes. + /* http://en.wikipedia.org/wiki/UTF-8 +Bits Last code point Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6 + 7 U+007F 0xxxxxxx + 11 U+07FF 110xxxxx 10xxxxxx + 16 U+FFFF 1110xxxx 10xxxxxx 10xxxxxx + 21 U+1FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + 26 U+3FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + 31 U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + + + /** char to int, where int is value, at the low end of the int, of the UTF-8 encoding. */ + + static public byte[] toUTF8(char ch) + { +// if ( ! Character.isDefined(ch)) +// throw new AtlasException("No such character: "+(int)ch) ; + + if ( ch != 0 && ch <= 127 ) return new byte[] {(byte)ch } ; + if ( ch == 0 ) return new byte[] { (byte)0xC0, (byte)0x80 } ; + + if ( ch <= 0x07FF ) + { + @SuppressWarnings("cast") + final int v = (int)ch ; + // x = low 11 bits yyyyy xxxxxx + // x = 00000yyyyyxxxxxx + //x1 = 110yyyyy x2 = 10xxxxxx + + // Hi 5 bits + int x1 = (v & 0x7C0) >>6 ; //BitsInt.access(ch, 21, 26) ; + x1 = x1 | 0xC0 ; + + int x2 = v&0x3F ; //BitsInt.access(ch, 26, 32) ; + x2 = x2 | 0x80 ; + return new byte[] {(byte)x1, (byte)x2} ; + } + if ( ch <= 0xFFFF ) + { + @SuppressWarnings("cast") + final int v = (int)ch ; + // x = aaaa bbbbbb cccccc + //x1 = 1110aaaa x2 = 10bbbbbb x3 = 10cccccc + int x1 = (v>>12)&0x1F ; + x1 = x1 | 0xE0 ; + + int x2 = (v>>6)&0x3F ; + x2 = x2 | 0x80 ; + + int x3 = v&0x3F ; + x3 = x3 | 0x80 ; + + return new byte[] {(byte)x1, (byte)x2, (byte)x3} ; + } + + + if ( true ) throw new AtlasException() ; + // Not java, where chars are 16 bit. + //if ( ch <= 0x1FFFFF ) ; + //if ( ch <= 0x3FFFFFF ) ; + //if ( ch <= 0x7FFFFFFF ) ; + + return null ; + + } + + /** Encode a char as UTF-8, using Java's built-in encoders - may be slow - this is for testing */ + static public byte[] toUTF8_test(char ch) + { + byte[] bytes = new byte[4] ; + ByteBuffer bb = ByteBuffer.wrap(bytes) ; + String s = ""+ch ; + int len = Bytes.toByteBuffer(s, bb) ; + byte[] bytes2 = new byte[len] ; + for ( int i = 0 ; i < len ; i++ ) + bytes2[i] = bytes[i] ; + return bytes2 ; + } + + /** Encode a char as UTF-8, using Java's built-in encoders - { + e.printStackTrace(); rturn + } +may be slow - this is for testing */ + static public char fromUTF8_test(byte[] x) + { + InputStream in = new ByteArrayInputStream(x) ; + Reader r = new InStreamUTF8(in) ; + try + { + return (char)r.read() ; + } catch (IOException e) { throw new AtlasException(e) ; } + } + + static public char fromUTF8(byte[] x) + { + if ( x == null ) return (char)0 ; + + for ( int i = 0 ; i < x.length ; i++ ) + { + int b = x[i] ; + if ( b == 0xC0 || b == 0xC1 || b >= 0xF5 ) + throw new AtlasException("Bad UTF-8 byte: "+b) ; + } + + // DRY: Stream UTF8. + // Fastpath //if ( (x & 0xE0) == 0xC0 ) + + if ( x.length == 0 ) + return (char)0 ; + //if ( x <= 127 ) + if ( x.length == 1 ) + return (char)x[0] ; + + //if ( x <= 0xFFFF ) + if ( x.length == 2 ) + { + // check: byte 0 is 110aaaaa, byte 1 is 10bbbbbb + + int hi = x[0] & 0x1F ; + int lo = x[1]&0x3F ; + return (char)((hi<<6)|lo) ; + } + // 1110.... => 3 bytes : 16 bits : not outside 16bit chars + //if ( x <= 0xFFFFFF ) + if ( x.length == 3 ) + { + // check: byte 0 is 110aaaaa, byte 1 and 2 are 10bbbbbb +// int b0 = (x>>16) & 0x1F ; +// int b1 = (x>>8) & 0x3F ; +// int b2 = x&0x3F ; + int b0 = x[0] & 0x1F ; + int b1 = x[1] & 0x3F ; + int b2 = x[2] & 0x3F ; + return (char)( (b0<<12) | (b1<<6) | b2 ) ; + } + + throw new AtlasException("Out of range: "+x) ; + } + + + // UTF-8 encoding. + // character '¢' = code point U+00A2 -> C2 A2 + // character '€' = code point U+20AC -> E2 82 AC + + @Test public void utf8_c1() { testChar(' ') ; } + @Test public void utf8_c2() { testChar('¢') ; } + @Test public void utf8_c3() { testChar('€') ; } + @Test public void utf8_c4() { testChar('\uFFFF') ; } + + @Test public void utf8_b1() { testBytes((byte)20) ; } + @Test public void utf8_b2() { testBytes((byte)0xC2, (byte)0xA2) ; } + @Test public void utf8_b3() { testBytes((byte)0xE2, (byte)0x82, (byte)0xAC) ; } + @Test public void utf8_b4() { testBytes((byte)0xE2, (byte)0xBF, (byte)0xBF) ; } + + + private void testChar(char c) + { + byte[] b = toUTF8(c) ; + char c2 = fromUTF8(b) ; + Assert.assertEquals(c, c2) ; + } + + private void testBytes(byte ...b) + { + char c = fromUTF8(b) ; + byte[] b2 = toUTF8(c) ; + Assert.assertArrayEquals(b, b2) ; + } + +} Added: 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=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ArrayOps.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ArrayOps.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,283 @@ +/** + * 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 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 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 + * @param array + * @param idx + * @param item + */ + public static 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 + * @param array + * @param idx + * @param item + * @param length + */ + public static 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 + * @param array + * @param idx + * @param length + * @return Element at slot idx + */ + public static 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 + * @param array + * @param idx + * @return Element at slot idx + */ + public static T delete(T[] array, int idx) + { return delete(array, idx, array.length) ; } + + + /** + * Clear the array. + * @param array + */ + public static void clear(T[] array) + { + clear(array, 0) ; + } + + public static void clear(T[] array, int idx) + { + clear(array, idx, array.length-idx) ; + } + + public static 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 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 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 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 void shiftDown(T[] array, int idx, int length) + { shiftDownN(array, idx, 1, length) ; } + + public static 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 IteratorArray iterator(T[] array) + { + return IteratorArray.create(array) ; + } + + public static String toString(T[] array) + { + return Arrays.asList(array).toString(); + } + + public static void print(T[] array) + { + System.out.println(toString(array)) ; + } + + public static void print(int[] array) + { + List x = new ArrayList(array.length) ; + for ( int i : array ) + x.add(i) ; + System.out.println(x) ; + } + + public static void print(long[] array) + { + List x = new ArrayList(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) ; } + } +} Added: 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=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteArray.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteArray.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,204 @@ +/** + * 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 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 +{ + 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 iterator() + { + return new IteratorByteArray(bytes, 0, length) ; + } + + static class IteratorByteArray implements Iterator + { + 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") ; } + + } + + +} Added: 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=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteIO.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ByteIO.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,51 @@ +/** + * 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 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); } + } + +} Added: 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=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/TestSuiteByReflection.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/TestSuiteByReflection.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,58 @@ +/** + * 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 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 .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 ; + } +} Added: 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=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/VarInteger.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/VarInteger.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,276 @@ +/** + * 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 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 ; + } + +} Added: 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=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ZigZagInteger.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/ZigZagInteger.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,178 @@ +/** + * 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 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 ; +// } +} Added: 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=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple1.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple1.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,59 @@ +/** + * 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 migrate.lib.tuple; + +import org.openjena.atlas.lib.Lib; + +public class Tuple1 extends ZTuple +{ + 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 ; + } + +} Added: 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=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple2.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple2.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,66 @@ +/** + * 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 migrate.lib.tuple; + +import org.openjena.atlas.lib.Lib; + +public class Tuple2 extends ZTuple +{ + 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 ; + } + +} Added: 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=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple3.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple3.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,72 @@ +/** + * 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 migrate.lib.tuple; + +import org.openjena.atlas.lib.Lib; + +public class Tuple3 extends ZTuple +{ + 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 ; + } + +} Added: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple4.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple4.java?rev=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple4.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/Tuple4.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,77 @@ +/** + * 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 migrate.lib.tuple; + +import org.openjena.atlas.lib.Lib; + +public class Tuple4 extends ZTuple +{ + final T item1 ; + final T item2 ; + final T item3 ; + final T item4 ; + + protected Tuple4(T item1, T item2, T item3, T item4) + { + this.item1 = item1 ; + this.item2 = item2 ; + this.item3 = item3 ; + this.item4 = item4 ; + } + + @Override + protected final boolean equalElements(ZTuple x) + { + Tuple4 x1 = (Tuple4)x ; + return Lib.equal(x1.item1, item1) && + Lib.equal(x1.item2, item2) && + Lib.equal(x1.item3, item3) && + Lib.equal(x1.item4, item4) ; + } + + @Override + public final T get(int idx) + { + switch (idx) + { + case 0: return item1 ; + case 1: return item2 ; + case 2: return item3 ; + case 3: return item4 ; + 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) ; + x = x<<1 ^ Lib.hashCodeObject(item4, ZTuple.NulItemHashCode) ; + return x ; + } + + @Override + public final int size() + { + return 4 ; + } + +} Added: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/TupleException.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/TupleException.java?rev=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/TupleException.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/TupleException.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,24 @@ +/** + * 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 migrate.lib.tuple; + +public class TupleException extends RuntimeException +{ + public TupleException(String msg) { super(msg) ; } +} Added: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/TupleN.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/TupleN.java?rev=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/TupleN.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/TupleN.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,72 @@ +/** + * 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 migrate.lib.tuple; + +import org.openjena.atlas.lib.Lib; + +public final class TupleN extends ZTuple +{ + T[] tuple ; + + protected TupleN(T...tuple) + { + this.tuple = tuple ; + } + + @Override + public T[] tuple() { return tuple ; } + + @Override + protected boolean equalElements(ZTuple x) + { + TupleN x1 = (TupleN)x ; + for ( int i = 0 ; i < tuple.length ; i++ ) + { + Object obj1 = x1.tuple[i] ; + Object obj2 = tuple[i] ; + if ( ! Lib.equal(obj1, obj2) ) + return false ; + } + return true ; + } + + @Override + public T get(int idx) + { + if ( idx < 0 || idx >= tuple.length ) + throw new TupleException("Out of bounds: "+idx) ; + return tuple[idx] ; + } + + @Override + public int hashCode() + { + int x = 0 ; + for ( T t: tuple) + x = x<<1 ^ Lib.hashCodeObject(t, ZTuple.NulItemHashCode) ; + return x ; + } + + @Override + public int size() + { + return tuple.length ; + } + +} Added: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/ZTuple.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/ZTuple.java?rev=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/ZTuple.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/ZTuple.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,105 @@ +/** + * 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 migrate.lib.tuple; + +import java.util.Arrays; +import java.util.List; + +import org.openjena.atlas.lib.ColumnMap; +import org.openjena.atlas.lib.Lib; +import org.openjena.atlas.lib.NotImplemented; + +/** Tuples - use less space by specific implementations for + * various sizes. Saves the array overhead of 3 slots. + * And 3 slots for two items might amount to a lot of space. + */ +public abstract class ZTuple +{ + static final int NulItemHashCode = 3 ; + + public abstract T get(int idx) ; + // Immutable + // public abstract T set(int idx, T item) ; + + public List asList() + { + return Arrays.asList(tuple()) ; + } + + public T[] tuple() + { + int N = size() ; + @SuppressWarnings("unchecked") + T[] array = (T[])new Object[N] ; + for (int i = 0; i < N; i++) + array[i] = get(i) ; + return array ; + } + + /** Return a tuple with the column mapping applied */ + public ZTuple map(ColumnMap colMap) + { + //return colMap.map(this) ; + throw new NotImplemented("Tuple.map") ; + } + + /** Return a tuple with the column mapping reversed */ + public ZTuple unmap(ColumnMap colMap) + { + //return colMap.unmap(this) ; + throw new NotImplemented("Tuple.unmap") ; + } + + public abstract int size() ; + + // Cache? + @Override + public int hashCode() + { + int x = 99 ; + for ( int i = 0; i < size() ; i++) + x ^= get(i).hashCode() ; + return x ; + } + + @Override + public boolean equals(Object other) + { + if ( this == other ) return true ; + if ( ! ( other instanceof ZTuple ) ) + return false ; + ZTuple x = (ZTuple)other ; + if ( x.size() != this.size() ) + return false ; + return equalElements(x) ; + } + + protected boolean equalElements(ZTuple tuple) + { + for ( int i = 0 ; i < tuple.size() ; i++ ) + { + Object obj1 = get(i) ; + Object obj2 = tuple.get(i) ; + if ( ! Lib.equal(obj1, obj2) ) + return false ; + } + return true ; + } + +} Added: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/_Triple.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/_Triple.java?rev=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/_Triple.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/migrate/lib/tuple/_Triple.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,35 @@ +/** + * 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 migrate.lib.tuple; + +import com.hp.hpl.jena.graph.Node; + +public class _Triple extends Tuple3 +{ + + public _Triple(Node s, Node p, Node o) + { + super(s, p, o) ; + } + + public Node getSubject() { return get(0) ; } + public Node getPredicate() { return get(1) ; } + public Node getObject() { return get(2) ; } + +} Added: incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/OrderedSet.java URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/OrderedSet.java?rev=1177690&view=auto ============================================================================== --- incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/OrderedSet.java (added) +++ incubator/jena/Scratch/AFS/Dev/trunk/src-lib/main/java/structure/OrderedSet.java Fri Sep 30 15:01:53 2011 @@ -0,0 +1,66 @@ +/** + * 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 structure; + +import org.openjena.atlas.io.Printable; + +import java.util.Iterator; +import java.util.List; + +// May change to allow duplicates -- OrderedBag +public interface OrderedSet> extends Iterable, Printable +{ + /** Clear all elements */ + public void clear() ; + + // This could be java.util.SortedSet - except that's quite large. + + public boolean contains(T item); + + public boolean isEmpty(); + + public T search(T item); + + public boolean add(T item); + + public boolean remove(T item); + + public T max() ; + + public T min() ; + + // hashCode + // equals + // Comparator comparator() ; + // subset + // headSet + // tailSet + + /** Number of elements in the set */ + public long size() ; + + /** Size by actually walking the tree and counting - mainly for testing */ + public long count() ; + public void checkTree() ; + public List elements() ; + + @Override + public Iterator iterator() ; + public Iterator iterator(T startInc, T endExc) ; +}