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 2016/05/06 18:32:07 UTC

svn commit: r1742586 - in /uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl: LongSet.java StringSet.java

Author: schor
Date: Fri May  6 18:32:06 2016
New Revision: 1742586

URL: http://svn.apache.org/viewvc?rev=1742586&view=rev
Log:
[UIMA-4674] backward compatibility support - for get/set int used to manipulate refs to strings and longs/doubles.

Added:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LongSet.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/StringSet.java

Added: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LongSet.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LongSet.java?rev=1742586&view=auto
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LongSet.java (added)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/LongSet.java Fri May  6 18:32:06 2016
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.cas.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+/**
+ * Sets of long values, used to support ll_set/getIntValue that manipulate v2 style long data 
+ * 
+ */
+final class LongSet {
+
+  private int lastLongCode = 0;
+  final private ArrayList<Long> longs = new ArrayList<>();
+  {longs.add(null);}
+  final private HashMap<Long, Integer> long2int = new HashMap<>();
+  
+  // Reset the long heap (called on CAS reset).
+  final void reset() {
+    longs.clear();
+    longs.add(null);
+    long2int.clear();
+    lastLongCode = 0;
+  }
+
+  // Get a long value
+  Long getLongForCode(int longCode) {
+    if (longCode == LowLevelCAS.NULL_FS_REF) {
+      return null;
+    }
+    return longs.get(longCode);
+  }
+
+  /**
+   * get the code for a long, adding it to the long table if not already there.
+   * @param s The long.
+   * @return The code corresponding to the long, which can be used in the getLongForCode call above
+   */
+  int getCodeForLong(Long s) {
+    if (s == null) {
+      return LowLevelCAS.NULL_FS_REF;
+    }
+    
+    Integer prev = long2int.putIfAbsent(s, lastLongCode + 1);
+    if (prev == null) {
+      longs.add(s);
+      return ++lastLongCode;
+    }
+    
+    return prev; 
+  }
+  
+  
+  final int getSize() {
+	  return this.longs.size();
+  }
+  
+}

Added: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/StringSet.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/StringSet.java?rev=1742586&view=auto
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/StringSet.java (added)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/main/java/org/apache/uima/cas/impl/StringSet.java Fri May  6 18:32:06 2016
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.cas.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+/**
+ * Like string heap, but keeps strings in a set
+ * 
+ */
+final class StringSet {
+
+  private int lastStringCode = 0;
+  final private ArrayList<String> strings = new ArrayList<>();
+  {strings.add(null);}
+  final private HashMap<String, Integer> string2int = new HashMap<>();
+  
+  // Reset the string heap (called on CAS reset).
+  final void reset() {
+    strings.clear();
+    strings.add(null);
+    string2int.clear();
+    lastStringCode = 0;
+  }
+
+  // Get a string value
+  String getStringForCode(int stringCode) {
+    if (stringCode == LowLevelCAS.NULL_FS_REF) {
+      return null;
+    }
+    return strings.get(stringCode);
+  }
+
+  /**
+   * get the code for a string, adding it to the string table if not already there.
+   * @param s The string.
+   * @return The code corresponding to the string, which can be used in the getStringForCode call above
+   */
+  int getCodeForString(String s) {
+    if (s == null) {
+      return LowLevelCAS.NULL_FS_REF;
+    }
+    
+    Integer prev = string2int.putIfAbsent(s, lastStringCode + 1);
+    if (prev == null) {
+      strings.add(s);
+      return ++lastStringCode;
+    }
+    
+    return prev; 
+  }
+  
+  
+  final int getSize() {
+	  return this.strings.size();
+  }
+  
+}