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 2017/11/20 18:37:30 UTC
svn commit: r1815831 - in /uima/uv3/uimaj-v3/trunk:
uima-docbook-v3-users-guide/src/docbook/
uimaj-core/src/main/java/org/apache/uima/jcas/cas/
uimaj-core/src/main/resources/org/apache/uima/
uimaj-core/src/test/java/org/apache/uima/jcas/test/
Author: schor
Date: Mon Nov 20 18:37:30 2017
New Revision: 1815831
URL: http://svn.apache.org/viewvc?rev=1815831&view=rev
Log:
[UIMA-5650] add FSLinkedHashSet and test case and doc
Added:
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSLinkedHashSet.java
Modified:
uima/uv3/uimaj-v3/trunk/uima-docbook-v3-users-guide/src/docbook/uv3.custom_java_objects.xml
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSHashSet.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/resources/org/apache/uima/semibuiltins.xml
uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/test/CASTestSetup.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/test/FSHashSetTest.java
Modified: uima/uv3/uimaj-v3/trunk/uima-docbook-v3-users-guide/src/docbook/uv3.custom_java_objects.xml
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uima-docbook-v3-users-guide/src/docbook/uv3.custom_java_objects.xml?rev=1815831&r1=1815830&r2=1815831&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uima-docbook-v3-users-guide/src/docbook/uv3.custom_java_objects.xml (original)
+++ uima/uv3/uimaj-v3/trunk/uima-docbook-v3-users-guide/src/docbook/uv3.custom_java_objects.xml Mon Nov 20 18:37:30 2017
@@ -238,10 +238,10 @@ public void _save_to_cas_data() {
</section>
<section id="uv3.custom_java_objects.semibuiltin_FSHashSet">
- <title>FSHashSet</title>
- <titleabbrev>FSHashSet</titleabbrev>
+ <title>FSHashSet and FSLinkedHashSet</title>
- <para>This type stores Feature Structures in a HashSet, using whatever is defined
+
+ <para>These types store Feature Structures in a HashSet, using whatever is defined
as the Feature Structure's <code>equals</code> and <code>hashcode</code>.
<blockquote>
@@ -253,6 +253,9 @@ public void _save_to_cas_data() {
</para>
<para>The CAS data form is held in an FSArray consisting of the members of the set.</para>
+
+ <para>If you want a predictable iteratation order, use FSLinkedHashSet instead of FSHashSet.
+ </para>
</section>
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSHashSet.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSHashSet.java?rev=1815831&r1=1815830&r2=1815831&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSHashSet.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSHashSet.java Mon Nov 20 18:37:30 2017
@@ -110,20 +110,28 @@ public class FSHashSet <T extends TOP> e
* @param type the type of this Feature Structure
*/
public FSHashSet(TypeImpl type, CASImpl casImpl) {
+ this(new HashSet<>(), type, casImpl);
+ }
+
+ public FSHashSet(HashSet<T> set, TypeImpl type, CASImpl casImpl) {
super(type, casImpl);
- fsHashSet = new HashSet<>();
+ fsHashSet = set;
if (CASImpl.traceFSs) { // tracing done after array setting, skipped in super class
_casView.traceFSCreate(this);
- }
+ }
}
/** @generated
* @param jcas JCas to which this Feature Structure belongs
*/
public FSHashSet(JCas jcas) {
+ this(new HashSet<>(), jcas);
+ }
+
+ public FSHashSet(HashSet<T> set, JCas jcas) {
super(jcas);
- fsHashSet = new HashSet<>();
+ fsHashSet = set;
if (CASImpl.traceFSs) { // tracing done after array setting, skipped in super class
_casView.traceFSCreate(this);
@@ -131,21 +139,25 @@ public class FSHashSet <T extends TOP> e
}
/**
- * Make a new ArrayList with an initial size .
+ * Make a new HashSet with an initial size .
*
* @param jcas The JCas
* @param length initial size
*/
public FSHashSet(JCas jcas, int length) {
+ this (new HashSet<>(length), jcas, length);
+ }
+
+ public FSHashSet(HashSet<T> set, JCas jcas, int length) {
super(jcas);
_casView.validateArraySize(length);
- fsHashSet = new HashSet<>(length);
+ fsHashSet = set;
if (CASImpl.traceFSs) { // tracing done after array setting, skipped in super class
_casView.traceFSCreate(this);
}
}
-
+
//*--------------*
//* Feature: fsArray
Added: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSLinkedHashSet.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSLinkedHashSet.java?rev=1815831&view=auto
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSLinkedHashSet.java (added)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/jcas/cas/FSLinkedHashSet.java Mon Nov 20 18:37:30 2017
@@ -0,0 +1,111 @@
+/*
+ * 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.
+ */
+
+/* Apache UIMA v3 - First created by JCasGen Fri Jan 20 11:55:59 EST 2017 */
+
+package org.apache.uima.jcas.cas;
+
+import java.lang.invoke.CallSite;
+import java.lang.invoke.MethodHandle;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.RandomAccess;
+import java.util.Set;
+import java.util.Spliterator;
+
+import org.apache.uima.UimaSerializableFSs;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.impl.FeatureStructureImplC;
+import org.apache.uima.cas.impl.TypeImpl;
+import org.apache.uima.cas.impl.TypeSystemImpl;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.JCasRegistry;
+import org.apache.uima.util.impl.Constants;
+
+
+/** a hash set of Feature Structures
+ * Is Pear aware - stores non-pear versions but may return pear version in pear contexts
+ * Updated by JCasGen Fri Jan 20 11:55:59 EST 2017
+ * XML source: C:/au/svnCheckouts/branches/uimaj/v3-alpha/uimaj-types/src/main/descriptors/java_object_type_descriptors.xml
+ * @generated */
+public class FSLinkedHashSet <T extends TOP> extends FSHashSet<T> {
+
+ /** @generated
+ * @ordered
+ */
+ @SuppressWarnings ("hiding")
+ public final static String _TypeName = "org.apache.uima.jcas.type.FSHashSet";
+
+ /** @generated
+ * @ordered
+ */
+ @SuppressWarnings ("hiding")
+ public final static int typeIndexID = JCasRegistry.register(FSLinkedHashSet.class);
+ /** @generated
+ * @ordered
+ */
+ @SuppressWarnings ("hiding")
+ public final static int type = typeIndexID;
+ /** @generated
+ * @return index of the type
+ */
+ @Override
+ public int getTypeIndexID() {return typeIndexID;}
+
+ /** Never called. Disable default constructor
+ * @generated */
+ protected FSLinkedHashSet() {
+ super();
+ }
+
+ /** Internal - constructor used by generator
+ * @generated
+ * @param casImpl the CAS this Feature Structure belongs to
+ * @param type the type of this Feature Structure
+ */
+ public FSLinkedHashSet(TypeImpl type, CASImpl casImpl) {
+ super(new LinkedHashSet<>(), type, casImpl);
+ }
+
+ /** @generated
+ * @param jcas JCas to which this Feature Structure belongs
+ */
+ public FSLinkedHashSet(JCas jcas) {
+ super(new LinkedHashSet<>(), jcas);
+ }
+
+ /**
+ * Make a new FSLinkedHashSet with an initial size .
+ *
+ * @param jcas The JCas
+ * @param length initial size
+ */
+ public FSLinkedHashSet(JCas jcas, int length) {
+ super(new LinkedHashSet<>(), jcas, length);
+ }
+
+}
+
+
\ No newline at end of file
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/resources/org/apache/uima/semibuiltins.xml
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/resources/org/apache/uima/semibuiltins.xml?rev=1815831&r1=1815830&r2=1815831&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/resources/org/apache/uima/semibuiltins.xml (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/resources/org/apache/uima/semibuiltins.xml Mon Nov 20 18:37:30 2017
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
- <!--
+<!--
***************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -19,7 +19,6 @@
* under the License.
***************************************************************
-->
-
<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
<name>semibuiltins</name>
<description>Semi-built-in types that can can be optionally imported by name.</description>
@@ -36,6 +35,7 @@
<description/>
<rangeTypeName>uima.cas.FSArray</rangeTypeName>
<elementType>uima.cas.TOP</elementType>
+ <multipleReferencesAllowed>true</multipleReferencesAllowed>
</featureDescription>
</features>
</typeDescription>
@@ -49,6 +49,7 @@
<description/>
<rangeTypeName>uima.cas.FSArray</rangeTypeName>
<elementType>uima.cas.TOP</elementType>
+ <multipleReferencesAllowed>true</multipleReferencesAllowed>
</featureDescription>
</features>
</typeDescription>
@@ -61,6 +62,21 @@
<name>intArray</name>
<description/>
<rangeTypeName>uima.cas.IntegerArray</rangeTypeName>
+ <multipleReferencesAllowed>true</multipleReferencesAllowed>
+ </featureDescription>
+ </features>
+ </typeDescription>
+ <typeDescription>
+ <name>org.apache.uima.jcas.cas.FSLinkedHashSet</name>
+ <description/>
+ <supertypeName>org.apache.uima.jcas.cas.FSHashSet</supertypeName>
+ <features>
+ <featureDescription>
+ <name>fsArray</name>
+ <description>Internal use only</description>
+ <rangeTypeName>uima.cas.FSArray</rangeTypeName>
+ <elementType>uima.cas.TOP</elementType>
+ <multipleReferencesAllowed>true</multipleReferencesAllowed>
</featureDescription>
</features>
</typeDescription>
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/test/CASTestSetup.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/test/CASTestSetup.java?rev=1815831&r1=1815830&r2=1815831&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/test/CASTestSetup.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/test/CASTestSetup.java Mon Nov 20 18:37:30 2017
@@ -112,6 +112,8 @@ public class CASTestSetup implements Ann
public static final String FS_ARRAY_LIST = "org.apache.uima.jcas.cas.FSArrayList";
public static final String FS_HASH_SET = "org.apache.uima.jcas.cas.FSHashSet";
+
+ public static final String FS_LINKED_HASH_SET = "org.apache.uima.jcas.cas.FSLinkedHashSet";
/**
* Constructor for CASTestSetup.
@@ -236,7 +238,7 @@ public class CASTestSetup implements Ann
tsm.addFeature("fsArray", fsArrayListType, typeArrayRef);
Type fsHashSetType = tsm.addType(FS_HASH_SET, topType);
tsm.addFeature("fsArray", fsHashSetType, typeArrayRef);
-
+ Type fsLinkedHashSetType = tsm.addType(FS_LINKED_HASH_SET, fsHashSetType);
}
public void initIndexes(FSIndexRepositoryMgr irm, TypeSystem ts) {
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/test/FSHashSetTest.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/test/FSHashSetTest.java?rev=1815831&r1=1815830&r2=1815831&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/test/FSHashSetTest.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/test/java/org/apache/uima/jcas/test/FSHashSetTest.java Mon Nov 20 18:37:30 2017
@@ -26,6 +26,7 @@ import org.apache.uima.cas.TypeSystem;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.cas.FSArray;
import org.apache.uima.jcas.cas.FSHashSet;
+import org.apache.uima.jcas.cas.FSLinkedHashSet;
import junit.framework.TestCase;
import x.y.z.EndOfSentence;
@@ -62,26 +63,31 @@ public class FSHashSetTest extends TestC
this.jcas = cas.getJCas();
}
- public void testBasic() {
- FSHashSet<Token> set = new FSHashSet<>(jcas);
- Token t1 = new Token(jcas);
+ private void basic(FSHashSet<Token> s) {
+ FSHashSet<Token> set = s;
+ Token t1 = new Token(jcas);
Token t2 = new Token(jcas);
- set.add(t1);
- set.add(t2);
- set.remove(t1);
-
- assertEquals(1, set.size());
-
+ set.add(t1);
+ set.add(t2);
+ set.remove(t1);
+
+ assertEquals(1, set.size());
+
Iterator<Token> it = set.iterator();
Token k = null;
- while (it.hasNext()) {
- assertNotNull(k = it.next());
- }
- assertNotNull(k);
- set._save_fsRefs_to_cas_data();
- FSArray fa = (FSArray) set.getFeatureValue(set.getType().getFeatureByBaseName("fsArray"));
- assertNotNull(fa);
- assertEquals(fa.get(0), k);
+ while (it.hasNext()) {
+ assertNotNull(k = it.next());
+ }
+ assertNotNull(k);
+ set._save_fsRefs_to_cas_data();
+ FSArray fa = (FSArray) set.getFeatureValue(set.getType().getFeatureByBaseName("fsArray"));
+ assertNotNull(fa);
+ assertEquals(fa.get(0), k);
+ }
+
+ public void testBasic() {
+ basic(new FSHashSet<>(jcas));
+ basic(new FSLinkedHashSet<>(jcas));
}