You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2013/02/06 23:51:20 UTC

svn commit: r1443261 - in /uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src: main/java/org/apache/uima/cas/impl/BinaryCasSerDes5.java test/java/org/apache/uima/cas/impl/CasTypeSystemMapperTst.java

Author: schor
Date: Wed Feb  6 22:51:20 2013
New Revision: 1443261

URL: http://svn.apache.org/viewvc?rev=1443261&view=rev
Log:
[UIMA-2498] start on some test cases for CasTypeSystemMapper.  Update to general comment at top of BinaryCasSerDes5.  Comment out AuxSkip - not needed/used.

Added:
    uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasTypeSystemMapperTst.java   (with props)
Modified:
    uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes5.java

Modified: uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes5.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes5.java?rev=1443261&r1=1443260&r2=1443261&view=diff
==============================================================================
--- uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes5.java (original)
+++ uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/main/java/org/apache/uima/cas/impl/BinaryCasSerDes5.java Wed Feb  6 22:51:20 2013
@@ -62,9 +62,7 @@ import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.zip.Deflater;
@@ -85,14 +83,17 @@ import org.apache.uima.util.impl.Seriali
 /**
  * User callable serialization and deserialization of the CAS in a compressed Binary Format
  * 
- * This serializes/deserializes the state of the CAS, assuming that the type
- * information remains constant.
+ * This serializes/deserializes the state of the CAS.  It has the capability to map type systems,
+ * so the sending and receiving type systems do not have to be the same.
+ *   - types and features are matched by name, and features must have the same range (slot kind)
+ *   - types and/or features in one type system not in the other are skipped over
  * 
  * Header specifies to reader the format, and the compression level.
  * 
  * How to Serialize:  
  * 
  * 1) create an instance of this class, specifying some options that don't change very much
+ *      type system, compression levels and strategy, and doing measurements
  * 2) call serialize(CAS) to serialize the cas * 
  * 
  * You can reuse the instance for a different CAS (as long as the type system is the same);
@@ -105,14 +106,21 @@ import org.apache.uima.util.impl.Seriali
  * The form of the binary CAS is inserted at the beginning so that receivers can do the
  * proper deserialization.  
  *     
- * Binary format requires that the exact same type system be used when deserializing 
+ * Compressed Binary format no longer requires that the exact same type system be used when deserializing 
  * 
  * How to Deserialize:
  * 
- * 1) get an appropriate CAS to deserialize into.  For delta CAS, it does not have to be empty.
+ * 1) get an appropriate CAS to deserialize into.  For delta CAS, it does not have to be empty, but it must
+ *    be the originating CAS from which the delta was produced.
  * 2) call CASImpl: cas.reinit(inputStream)  This is the existing method
  *    for binary deserialization, and it now handles this compressed version, too.
- *    Delta cas is also supported.
+ *    Delta cas is also supported.  This form requires both source and target type systems to be exactly the same.
+ *    
+ * An alternative interface for Deserialization with type system mapping:
+ * 1) get an appropriate CAS to deserialize into (as above).
+ * 2) create (or reuse) an instance of this class -> xxx, with a type system corresponding to the receiving cas
+ * 3) call xxx.deserialize(receivingCas, inputStream, targetTypeSystemImpl)
+ *    where the targetTypeSystem is the type system of the cas being deserialized
  * 
  * Compression/Decompression
  * Works in two stages:
@@ -123,7 +131,7 @@ import org.apache.uima.util.impl.Seriali
  *      control info, float-exponents, string chars
  * Deserialization:
  *   Read all bytes, 
- *   create separate ByteArrayInputStreams for each segment, sharing byte bfr
+ *   create separate ByteArrayInputStreams for each segment
  *   create appropriate unzip data input streams for these
  *   
  * API design
@@ -145,7 +153,7 @@ import org.apache.uima.util.impl.Seriali
  *     
  * Use Cases, filtering and delta
  *   **************************************************************************
- *   * (de)serialize * filter? * delta? * comment
+ *   * (de)serialize * filter? * delta? * Use case
  *   **************************************************************************
  *   * serialize     *   N     *   N    * Saving a Cas, 
  *   *               *         *        * sending Cas to svc with identical ts
@@ -158,13 +166,13 @@ import org.apache.uima.util.impl.Seriali
  *   **************************************************************************
  *   * serialize     *   Y     *   Y    * NOT SUPPORTED (not needed)  
  *   **************************************************************************
- *   * deserialize   *   N     *   N    * reading/(recv) CAS, identical TS
+ *   * deserialize   *   N     *   N    * reading/(receiving) CAS, identical TS
  *   **************************************************************************
- *   * deserialize   *   Y     *   N    * reading/(recv) CAS, different TS
+ *   * deserialize   *   Y     *   N    * reading/(receiving) CAS, different TS
  *   **************************************************************************
- *   * deserialize   *   N     *   Y    * recv CAS, identical TS, 
+ *   * deserialize   *   N     *   Y    * receiving CAS, identical TS, 
  *   **************************************************************************
- *   * deserialize   *   Y     *   Y    * recv CAS, different TS (tgt a subset)
+ *   * deserialize   *   Y     *   Y    * receiving CAS, different TS (tgt a subset)
  *   **************************************************************************
  */
 public class BinaryCasSerDes5 {
@@ -178,9 +186,6 @@ public class BinaryCasSerDes5 {
    */
   private static final int VERSION = 1;  
 
-  // next must be set to true if you want the cas type system mapping to work
-  public static final boolean CHANGE_FS_REFS_TO_SEQUENTIAL = true;
-  // may add more later - to specify differing trade-offs between speed and compression
   public static final boolean IS_DIFF_ENCODE = true;
   public static final boolean CAN_BE_NEGATIVE = true;
   public static final boolean IGNORED = true;
@@ -194,17 +199,17 @@ public class BinaryCasSerDes5 {
   public enum AuxHeap {ByteAH, ShortAH, LongAH,};
   final static int AuxHeapsCount = AuxHeap.values().length;
 
-  public static class AuxSkip implements Comparable<AuxSkip> {
-    final int skipIndex;
-    final int skipSize;
-    public AuxSkip(int index, int size) {
-      skipIndex = index;
-      skipSize = size;
-    }
-    public int compareTo(AuxSkip o) {
-      return (skipIndex < o.skipIndex) ? -1 : (skipIndex > o.skipIndex) ? 1 : 0; 
-    }
-  }
+//  public static class AuxSkip implements Comparable<AuxSkip> {
+//    final int skipIndex;
+//    final int skipSize;
+//    public AuxSkip(int index, int size) {
+//      skipIndex = index;
+//      skipSize = size;
+//    }
+//    public int compareTo(AuxSkip o) {
+//      return (skipIndex < o.skipIndex) ? -1 : (skipIndex > o.skipIndex) ? 1 : 0; 
+//    }
+//  }
 
   /**
    * Compression alternatives
@@ -270,6 +275,11 @@ public class BinaryCasSerDes5 {
    */
 
   /**
+   * NOTE: adding or altering slots breaks backward compatability and
+   * the ability do deserialize previously serialized things
+   * 
+   * This definition shared with BinaryCasSerDes4
+   * 
    * Define all the slot kinds.
    */
   public enum SlotKind {
@@ -382,6 +392,7 @@ public class BinaryCasSerDes5 {
    */
   private boolean isTypeMappingCmn;
   private CasTypeSystemMapper typeMapperCmn;
+  
   /**
    * 
    * @param ts Type System (the source type system)
@@ -401,13 +412,17 @@ public class BinaryCasSerDes5 {
     this(ts, false, CompressLevel.Default, CompressStrat.Default);
   }
 
-  /**
+  
+  /*************************************************************************************
+   *   S E R I A L I Z E
+   *************************************************************************************/   
+  /**   
    * @param cas
    * @param out
    * @param trackingMark
    * @return null or serialization measurements (depending on setting of doMeasurements)
    * @throws IOException
-   */
+   **************************************************************************************/
   public SerializationMeasures serialize(
       AbstractCas cas, 
       Object out, 
@@ -435,8 +450,11 @@ public class BinaryCasSerDes5 {
   public SerializationMeasures serialize(AbstractCas cas, Object out) throws IOException {
     return serialize(cas, out, null, null);
   }
-  /**
-   * Use to deserialize compressed file, no type system mapping
+  
+  /*************************************************************************************
+   *   D E S E R I A L I Z E
+   *************************************************************************************/   
+  /** Use to deserialize compressed file, no type system mapping
    * @param cas
    * @param istream
    * @throws IOException
@@ -516,12 +534,12 @@ public class BinaryCasSerDes5 {
     deserializer.deserialize();
   }
 
-  /**
+  /*********************************************************************************************
+   * S e r i a l i z e r   Class for sharing variables among routines
    * Class instantiated once per serialization
-   * Multiple serializations in parallel supported, with
-   * multiple instances of this
-   */
-  
+   * Multiple serializations in parallel supported, with multiple instances of this
+   *********************************************************************************************/
+    
   private class Serializer {
     final private DataOutputStream serializedOut;  // where to write out the serialized result
     final private CASImpl cas;  // cas being serialized
@@ -543,7 +561,7 @@ public class BinaryCasSerDes5 {
 
     final private boolean isDelta;        // if true, there is a marker indicating the start spot(s)
     final private boolean doMeasurement;  // if true, doing measurements
-    final private ComprItemRefs fsStartIndexes = (CHANGE_FS_REFS_TO_SEQUENTIAL) ? new ComprItemRefs() : null;
+    final private ComprItemRefs fsStartIndexes = new ComprItemRefs();
     final private int[] typeCodeHisto = new int[ts.getTypeArraySize()]; 
 //    final private Integer[] serializedTypeCode2Code = new Integer[ts.getTypeArraySize()]; // needs to be Integer to get comparator choice
     final private int[] estimatedZipSize = new int[NBR_SLOT_KIND_ZIP_STREAMS]; // one entry for each output stream kind
@@ -660,11 +678,13 @@ public class BinaryCasSerDes5 {
       for (int i = 0; i < baosZipSources.length; i++) {
         setupOutputStream(i);
       }
-
     }
     
+    /************************
+     * Main serialize method
+     * @throws IOException
+     ************************/
     private void serialize() throws IOException {   
-
       if (doMeasurement) {
         System.out.println(printCasInfo(cas));
         sm.origAuxBytes = cas.getByteHeap().getSize();
@@ -836,7 +856,6 @@ public class BinaryCasSerDes5 {
         heapStart = 1;  // slot 0 not serialized, it's null / 0
       }
 
-//      if (CHANGE_FS_REFS_TO_SEQUENTIAL) {
 //        // scan thru all fs and save their offsets in the heap
 //        // to allow conversion from addr to sequential fs numbers
 //        initFsStartIndexes(fsStartIndexes, heap, heapStart, heapEnd, typeCodeHisto);
@@ -860,8 +879,6 @@ public class BinaryCasSerDes5 {
 //            System.out.format("%2d %,9d instance of Type %s%n", i, c, typeInfoArray[tCode]);
 //          }
 //        }
-        
-//      }
 
       
       
@@ -1720,7 +1737,7 @@ public class BinaryCasSerDes5 {
     private int double1Index = -1;
 
     final private boolean isDelta;        // if true, a delta is being deserialized
-    final private ComprItemRefs fsStartIndexes = (CHANGE_FS_REFS_TO_SEQUENTIAL) ? new ComprItemRefs() : null;
+    final private ComprItemRefs fsStartIndexes = new ComprItemRefs();
     private String[] readCommonString;
 
     private TypeInfo typeInfo; // type info for the current type being serialized
@@ -2675,17 +2692,17 @@ public class BinaryCasSerDes5 {
             if (!fSrcInTgt[iSrcFeat] && (
                 (srcTypeInfo.slotKinds[iSrcFeat] == SlotKind.Slot_DoubleRef) ||
                 (srcTypeInfo.slotKinds[iSrcFeat] == SlotKind.Slot_LongRef))) { 
-              fsStartIndexes.recordSkippedAuxHeap(AuxHeap.LongAH, srcHeap[iSrcHeap + iSrcFeat + 1], 1);
+//              fsStartIndexes.recordSkippedAuxHeap(AuxHeap.LongAH, srcHeap[iSrcHeap + iSrcFeat + 1], 1);
             }
           }
         } else if (!isIncludedType) {
           // if the src Type is not in the target, and the src Type is a ref to one of the aux arrays
           if (!srcTypeInfo.isHeapStoredArray) {
             // is an array of boolean, byte, short, long or double
-            final int skipStart = srcHeap[iSrcHeap + 2];
-            final int skipSize  = srcHeap[iSrcHeap + 1];
-            final AuxHeap auxHeap = getAuxHeapFromSlotKind(srcTypeInfo.slotKinds[1]);
-            fsStartIndexes.recordSkippedAuxHeap(auxHeap, skipStart, skipSize);
+//            final int skipStart = srcHeap[iSrcHeap + 2];
+//            final int skipSize  = srcHeap[iSrcHeap + 1];
+//            final AuxHeap auxHeap = getAuxHeapFromSlotKind(srcTypeInfo.slotKinds[1]);
+//            fsStartIndexes.recordSkippedAuxHeap(auxHeap, skipStart, skipSize);
           }
         }
       }
@@ -2701,12 +2718,12 @@ public class BinaryCasSerDes5 {
       iSrcHeap += incrToNextFs(srcHeap, iSrcHeap, srcTypeInfo);
     }
     
-    if (isTypeMapping) {
-      // sort the skip information
-      for (List<AuxSkip> skips : fsStartIndexes.skips) {
-        Collections.sort(skips);
-      }
-    }
+//    if (isTypeMapping) {
+//      // sort the skip information
+//      for (List<AuxSkip> skips : fsStartIndexes.skips) {
+//        Collections.sort(skips);
+//      }
+//    }
     return tgtHeapUsed;  // side effect: set up fsStartIndexes
   } 
 
@@ -3262,13 +3279,13 @@ public class BinaryCasSerDes5 {
      * Indexed by AuxHeap kind: 
      */
 
-    final private List<List<AuxSkip>> skips = new ArrayList<List<AuxSkip>>(AuxHeap.values().length);
-    
-    { // initialize instance block
-      for (int i = 0; i < skips.size(); i++) {
-        skips.add(new ArrayList<AuxSkip>());
-      }
-    }
+//    final private List<List<AuxSkip>> skips = new ArrayList<List<AuxSkip>>(AuxHeap.values().length);
+//    
+//    { // initialize instance block
+//      for (int i = 0; i < skips.size(); i++) {
+//        skips.add(new ArrayList<AuxSkip>());
+//      }
+//    }
    
     private int nextTgt = 0;
 
@@ -3296,15 +3313,15 @@ public class BinaryCasSerDes5 {
       srcSeq2TgtSeq.add(inTarget ? nextTgt++ : 0);
     }
     
-    /**
-     * record skipped entries in an Aux heap
-     * @param auxHeap which heap this is for
-     * @param srcSkipIndex the index of the first skipped slot in the src heap
-     * @param srcSkipSize the number of entries skipped
-     */
-    public void recordSkippedAuxHeap(AuxHeap auxHeap, int srcSkipIndex, int srcSkipSize) {
-      skips.get(auxHeap.ordinal()).add(new AuxSkip(srcSkipIndex, srcSkipSize));
-    }
+//    /**
+//     * record skipped entries in an Aux heap
+//     * @param auxHeap which heap this is for
+//     * @param srcSkipIndex the index of the first skipped slot in the src heap
+//     * @param srcSkipSize the number of entries skipped
+//     */
+//    public void recordSkippedAuxHeap(AuxHeap auxHeap, int srcSkipIndex, int srcSkipSize) {
+//      skips.get(auxHeap.ordinal()).add(new AuxSkip(srcSkipIndex, srcSkipSize));
+//    }
     
     /**
      * Called during deserialize to incrementally add 

Added: uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasTypeSystemMapperTst.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasTypeSystemMapperTst.java?rev=1443261&view=auto
==============================================================================
--- uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasTypeSystemMapperTst.java (added)
+++ uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasTypeSystemMapperTst.java Wed Feb  6 22:51:20 2013
@@ -0,0 +1,344 @@
+package org.apache.uima.cas.impl;
+
+import java.util.BitSet;
+
+import junit.framework.TestCase;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.admin.FSIndexRepositoryMgr;
+import org.apache.uima.cas.admin.TypeSystemMgr;
+import org.apache.uima.cas.test.AnnotatorInitializer;
+import org.apache.uima.cas.test.CASInitializer;
+
+public class CasTypeSystemMapperTst extends TestCase {
+  
+  protected void setUp() throws Exception {
+    super.setUp();
+  }
+
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  public void testCasTypeSystemMapperFull() {
+    TypeSystemImpl ts1 = createTs(3, 0x1ffff, 0x1ffff);
+    TypeSystemImpl ts2 = createTs(3, 0x1ffff, 0x1ffff); 
+    
+    CasTypeSystemMapper m = new CasTypeSystemMapper(ts1, ts2);
+    chkbase(m);
+    for (int i = 37; i < 39; i++) {
+      assertEquals(i, m.mapTypeCodeSrc2Tgt(i));
+      assertEquals(i, m.mapTypeCodeTgt2Src(i));
+      chkfeats(m, i);
+    }    
+  }
+
+  private void chkfeats(CasTypeSystemMapper m, int tCode) {
+    if (tCode > 0) {
+      final int[] tgtFeatOffsets = m.getTgtFeatOffsets2Src(tCode);
+      for (int j = 0; j < tgtFeatOffsets.length; j++) {
+        assertEquals(j, tgtFeatOffsets[j]);
+      }
+      final boolean[] featSrcInTg = m.getFSrcInTgt(tCode);
+      for (int j = 0; j < featSrcInTg.length; j++) {
+        assertTrue(featSrcInTg[j]);
+      }  
+    } 
+  }
+  
+  private void chkbase(CasTypeSystemMapper m) {
+    for (int i = 1; i < 37; i++) {
+      assertEquals(i, m.mapTypeCodeSrc2Tgt(i));
+      assertEquals(i, m.mapTypeCodeTgt2Src(i));
+      chkfeats(m, i);
+    }    
+  }
+  
+  public void testMissingType1() {
+    TypeSystemImpl ts1 = createTs(3, 0x1ffff, 0x1ffff);
+    TypeSystemImpl ts2 = createTs(1, 0x1ffff, 0x1ffff); 
+    
+    CasTypeSystemMapper m = new CasTypeSystemMapper(ts1, ts2);
+    chkbase(m);
+    assertEquals(37, m.mapTypeCodeSrc2Tgt(37));
+    assertEquals(0, m.mapTypeCodeSrc2Tgt(38));
+    assertEquals(37, m.mapTypeCodeTgt2Src(37));
+    chkfeats(m, 37);    
+  }
+
+  public void testMissingType2() {
+    TypeSystemImpl ts1 = createTs(3, 0x1ffff, 0x1ffff);
+    TypeSystemImpl ts2 = createTs(2, 0x1ffff, 0x1ffff); 
+    
+    CasTypeSystemMapper m = new CasTypeSystemMapper(ts1, ts2);
+    chkbase(m);
+    assertEquals(0, m.mapTypeCodeSrc2Tgt(37));
+    assertEquals(37, m.mapTypeCodeSrc2Tgt(38));
+    assertEquals(38, m.mapTypeCodeTgt2Src(37));
+  }
+  
+  public void testMissingFeature0() {
+    TypeSystemImpl ts1 = createTs(3, 0x1ffff, 0x1ffff);
+    TypeSystemImpl ts2 = createTs(3, 0x1ffff - 0x00100, 0x1ffff);  // feat 8
+    CasTypeSystemMapper m = new CasTypeSystemMapper(ts1, ts2);
+    chkbase(m);
+    assertEquals(37, m.mapTypeCodeSrc2Tgt(37));
+    assertEquals(38, m.mapTypeCodeSrc2Tgt(38));
+    assertEquals(37, m.mapTypeCodeTgt2Src(37));
+    assertEquals(38, m.mapTypeCodeTgt2Src(38));
+    chkfeats(m, 38);
+   
+    final int[] tgtFeatOffsets = m.getTgtFeatOffsets2Src(37);
+    for (int j = 0, k = 0; j < tgtFeatOffsets.length; j++, k++) {
+      if (j == 8) {
+        k++;
+      }
+      assertEquals(k, tgtFeatOffsets[j]);
+    }
+    final boolean[] featSrcInTg = m.getFSrcInTgt(37);
+    for (int j = 0; j < featSrcInTg.length; j++) {
+      assertEquals(j != 8, featSrcInTg[j]);
+    }  
+  }
+
+  public void testMissingFeature0r() {
+    TypeSystemImpl ts1 = createTs(3, 0x1ffff, 0x1ffff);
+    TypeSystemImpl ts2 = createTs(3, 0x1ffff, 0x1ffff - 0x00100);  // feat 8
+    CasTypeSystemMapper m = new CasTypeSystemMapper(ts1, ts2);
+    chkbase(m);
+    assertEquals(37, m.mapTypeCodeSrc2Tgt(37));
+    assertEquals(38, m.mapTypeCodeSrc2Tgt(38));
+    assertEquals(37, m.mapTypeCodeTgt2Src(37));
+    assertEquals(38, m.mapTypeCodeTgt2Src(38));
+    chkfeats(m, 37);
+   
+    final int[] tgtFeatOffsets = m.getTgtFeatOffsets2Src(38);
+    for (int j = 0, k = 0; j < tgtFeatOffsets.length; j++, k++) {
+      if (j == 8) {
+        k++;
+      }
+      assertEquals(k, tgtFeatOffsets[j]);
+    }
+    final boolean[] featSrcInTg = m.getFSrcInTgt(38);
+    for (int j = 0; j < featSrcInTg.length; j++) {
+      assertEquals(j != 8, featSrcInTg[j]);
+    }  
+  }
+
+  public void testMissingFeature0f() {
+    TypeSystemImpl ts1 = createTs(3, 0x1ffff - 0x00100, 0x1ffff); // feat 8
+    TypeSystemImpl ts2 = createTs(3, 0x1ffff, 0x1ffff);  
+    CasTypeSystemMapper m = new CasTypeSystemMapper(ts1, ts2);
+    chkbase(m);
+    assertEquals(37, m.mapTypeCodeSrc2Tgt(37));
+    assertEquals(38, m.mapTypeCodeSrc2Tgt(38));
+    assertEquals(37, m.mapTypeCodeTgt2Src(37));
+    assertEquals(38, m.mapTypeCodeTgt2Src(38));
+    chkfeats(m, 38);
+   
+    final int[] tgtFeatOffsets = m.getTgtFeatOffsets2Src(37);
+    for (int j = 0, k = 0; j < tgtFeatOffsets.length; j++, k++) {
+      if (j == 8) {
+        k--;
+        assertEquals(-1, tgtFeatOffsets[j]);
+        continue;
+      } 
+      assertEquals(k, tgtFeatOffsets[j]);
+    }
+    final boolean[] featSrcInTg = m.getFSrcInTgt(37);
+    for (int j = 0; j < featSrcInTg.length; j++) {
+      assertEquals(true, featSrcInTg[j]);
+    }  
+  }
+
+  /**
+   * Create a type system having all kinds of types
+   * @return
+   */
+  private TypeSystemImpl createTs(int types, int feats1, int feats2) {
+    return (TypeSystemImpl) CASInitializer.initCas(new CASTestSetup(types, feats1, feats2)).getTypeSystem();
+  }
+  
+  
+  
+  private Type akof;
+  private Type akof2;
+
+  private Type topType;
+  private Type typeArrayInt;
+  private Type typeArrayFs;
+  private Type typeArrayFloat;
+  private Type typeArrayDouble;
+  private Type typeArrayLong;
+  private Type typeArrayShort;
+  private Type typeArrayByte;
+  private Type typeArrayBoolean;
+  private Type typeArrayString;
+  
+  private Type typeInt;
+  private Type typeFloat;
+  private Type typeDouble;
+  private Type typeLong;
+  private Type typeShort;
+  private Type typeByte;
+  private Type typeBoolean;
+  private Type typeString;
+  private Type typeFs;
+  
+  private Feature akofInt;
+  private Feature akofFloat;
+  private Feature akofDouble;
+  private Feature akofLong;
+  private Feature akofShort;
+  private Feature akofByte;
+  private Feature akofBoolean;
+  private Feature akofString;
+  private Feature akofFs;
+
+  private Feature akofAint;
+  private Feature akofAfloat;
+  private Feature akofAdouble;
+  private Feature akofAlong;
+  private Feature akofAshort;
+  private Feature akofAbyte;
+  private Feature akofAboolean;
+  private Feature akofAstring;
+  private Feature akofAfs;
+  
+  private Feature akof2Int;
+  private Feature akof2Float;
+  private Feature akof2Double;
+  private Feature akof2Long;
+  private Feature akof2Short;
+  private Feature akof2Byte;
+  private Feature akof2Boolean;
+  private Feature akof2String;
+  private Feature akof2Fs;
+
+  private Feature akof2Aint;
+  private Feature akof2Afloat;
+  private Feature akof2Adouble;
+  private Feature akof2Along;
+  private Feature akof2Ashort;
+  private Feature akof2Abyte;
+  private Feature akof2Aboolean;
+  private Feature akof2Astring;
+  private Feature akof2Afs;
+
+
+  public class CASTestSetup  implements AnnotatorInitializer {
+    final int typesToGenerate;
+    final boolean[] ttgb;
+    final int featsToInclude1;
+    final int featsToInclude2;
+    final BitSet ftg1 = new BitSet(32);
+    final BitSet ftg2 = new BitSet(32);
+
+    CASTestSetup(int types, int feats1, int feats2) {
+      this.typesToGenerate = types;
+      this.featsToInclude1 = feats1;
+      this.featsToInclude2 = feats2;
+      ttgb = new boolean[2];
+      ttgb[0] = (1 == (typesToGenerate & 1));
+      ttgb[1] = (2 == (typesToGenerate & 2));
+      for (int i = 0; i < 32; i++) {
+        int v = 1 << i;
+        ftg1.set(i, v == (featsToInclude1 & v));
+        ftg2.set(i, v == (featsToInclude2 & v));
+      }
+    }
+    
+    
+    /** 
+     * Type system
+
+     * akof    - type: all kinds of features
+     *   akofInt  
+     *   akofFloat
+     *   akofByte
+     *   akofBoolean
+     *   akofShort
+     *   akofStr
+     *   akofLong
+     *   akofDouble
+     *   akofHeapRef
+     *   akofArrayRef 
+     */
+    
+    public void initTypeSystem(TypeSystemMgr tsm) {
+      // Add new types and features.
+      topType = tsm.getTopType();
+      typeArrayInt = tsm.getType(CAS.TYPE_NAME_INTEGER_ARRAY);
+      typeArrayFs = tsm.getType(CAS.TYPE_NAME_FS_ARRAY);
+      typeArrayFloat = tsm.getType(CAS.TYPE_NAME_FLOAT_ARRAY);
+      typeArrayDouble = tsm.getType(CAS.TYPE_NAME_DOUBLE_ARRAY);
+      typeArrayLong = tsm.getType(CAS.TYPE_NAME_LONG_ARRAY);
+      typeArrayShort = tsm.getType(CAS.TYPE_NAME_SHORT_ARRAY);
+      typeArrayByte = tsm.getType(CAS.TYPE_NAME_BYTE_ARRAY);
+      typeArrayBoolean= tsm.getType(CAS.TYPE_NAME_BOOLEAN_ARRAY);
+      typeArrayString = tsm.getType(CAS.TYPE_NAME_STRING_ARRAY);
+      
+      typeInt = tsm.getType(CAS.TYPE_NAME_INTEGER);
+      typeFloat = tsm.getType(CAS.TYPE_NAME_FLOAT);
+      typeDouble = tsm.getType(CAS.TYPE_NAME_DOUBLE);
+      typeLong = tsm.getType(CAS.TYPE_NAME_LONG);
+      typeShort = tsm.getType(CAS.TYPE_NAME_SHORT);
+      typeByte = tsm.getType(CAS.TYPE_NAME_BYTE);
+      typeBoolean = tsm.getType(CAS.TYPE_NAME_BOOLEAN);
+      typeString = tsm.getType(CAS.TYPE_NAME_STRING);
+      typeFs = tsm.getType(CAS.TYPE_NAME_TOP);
+
+      if (ttgb[0]) {
+        akof = tsm.addType("akof", topType);
+        if (ftg1.get(0)) {akofInt = tsm.addFeature("akofInt", akof, typeInt);}
+        if (ftg1.get(1)) {akofFs = tsm.addFeature("akofFs", akof, typeFs);}
+        if (ftg1.get(2)) {akofFloat = tsm.addFeature("akofFloat", akof, typeFloat);}
+        if (ftg1.get(3)) {akofDouble = tsm.addFeature("akofDouble", akof, typeDouble);}
+        if (ftg1.get(4)) {akofLong = tsm.addFeature("akofLong", akof, typeLong);}
+        if (ftg1.get(5)) {akofShort = tsm.addFeature("akofShort", akof, typeShort);}
+        if (ftg1.get(6)) {akofByte = tsm.addFeature("akofByte", akof, typeByte);}
+        if (ftg1.get(7)) {akofBoolean = tsm.addFeature("akofBoolean", akof, typeBoolean);}
+        if (ftg1.get(8)) {akofString = tsm.addFeature("akofStr", akof, typeString);}
+        
+        if (ftg1.get(9)) {akofAint = tsm.addFeature("akofAint", akof, typeArrayInt);}
+        if (ftg1.get(10)) {akofAfs = tsm.addFeature("akofAfs", akof, typeArrayFs);}
+        if (ftg1.get(11)) {akofAfloat = tsm.addFeature("akofAfloat", akof, typeArrayFloat);}
+        if (ftg1.get(12)) {akofAdouble = tsm.addFeature("akofAdouble", akof, typeArrayDouble);}
+        if (ftg1.get(13)) {akofAlong = tsm.addFeature("akofAlong", akof, typeArrayLong);}
+        if (ftg1.get(14)) {akofAshort = tsm.addFeature("akofAshort", akof, typeArrayShort);}
+        if (ftg1.get(15)) {akofAbyte = tsm.addFeature("akofAbyte", akof, typeArrayByte);}
+        if (ftg1.get(16)) {akofAboolean = tsm.addFeature("akofAboolean", akof, typeArrayBoolean);}
+        if (ftg1.get(17)) {akofAstring = tsm.addFeature("akofAstring", akof, typeArrayString);}        
+      }
+      if (ttgb[1]) {
+        akof2 = tsm.addType("akof2", topType);
+        if (ftg2.get(0)) {akof2Int = tsm.addFeature("akof2Int", akof2, typeInt);}
+        if (ftg2.get(1)) {akof2Fs = tsm.addFeature("akof2Fs", akof2, typeFs);}
+        if (ftg2.get(2)) {akof2Float = tsm.addFeature("akof2Float", akof2, typeFloat);}
+        if (ftg2.get(3)) {akof2Double = tsm.addFeature("akof2Double", akof2, typeDouble);}
+        if (ftg2.get(4)) {akof2Long = tsm.addFeature("akof2Long", akof2, typeLong);}
+        if (ftg2.get(5)) {akof2Short = tsm.addFeature("akof2Short", akof2, typeShort);}
+        if (ftg2.get(6)) {akof2Byte = tsm.addFeature("akof2Byte", akof2, typeByte);}
+        if (ftg2.get(7)) {akof2Boolean = tsm.addFeature("akof2Boolean", akof2, typeBoolean);}
+        if (ftg2.get(8)) {akof2String = tsm.addFeature("akof2Str", akof2, typeString);}
+        
+        if (ftg2.get(9)) {akof2Aint = tsm.addFeature("akof2Aint", akof2, typeArrayInt);}
+        if (ftg2.get(10)) {akof2Afs = tsm.addFeature("akof2Afs", akof2, typeArrayFs);}
+        if (ftg2.get(11)) {akof2Afloat = tsm.addFeature("akof2Afloat", akof2, typeArrayFloat);}
+        if (ftg2.get(12)) {akof2Adouble = tsm.addFeature("akof2Adouble", akof2, typeArrayDouble);}
+        if (ftg2.get(13)) {akof2Along = tsm.addFeature("akof2Along", akof2, typeArrayLong);}
+        if (ftg2.get(14)) {akof2Ashort = tsm.addFeature("akof2Ashort", akof2, typeArrayShort);}
+        if (ftg2.get(15)) {akof2Abyte = tsm.addFeature("akof2Abyte", akof2, typeArrayByte);}
+        if (ftg2.get(16)) {akof2Aboolean = tsm.addFeature("akof2Aboolean", akof2, typeArrayBoolean);}
+        if (ftg2.get(17)) {akof2Astring = tsm.addFeature("akof2Astring", akof2, typeArrayString);}        
+      }
+    }
+    public void initIndexes(FSIndexRepositoryMgr irm, TypeSystem ts) {
+    }
+  }
+
+
+}

Propchange: uima/uimaj/branches/filteredCompress-uima-2498/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasTypeSystemMapperTst.java
------------------------------------------------------------------------------
    svn:eol-style = native