You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2020/08/24 21:32:31 UTC

svn commit: r1881161 [1/3] - in /xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema: SchemaContainer.java StscChecker.java StscResolver.java StscState.java

Author: kiwiwings
Date: Mon Aug 24 21:32:31 2020
New Revision: 1881161

URL: http://svn.apache.org/viewvc?rev=1881161&view=rev
Log:
use generics instead of rawtypes

Modified:
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaContainer.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/StscChecker.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/StscResolver.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/StscState.java

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaContainer.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaContainer.java?rev=1881161&r1=1881160&r2=1881161&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaContainer.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaContainer.java Mon Aug 24 21:32:31 2020
@@ -15,34 +15,24 @@
 
 package org.apache.xmlbeans.impl.schema;
 
+import org.apache.xmlbeans.*;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Collectors;
 
-import org.apache.xmlbeans.SchemaAnnotation;
-import org.apache.xmlbeans.SchemaAttributeGroup;
-import org.apache.xmlbeans.SchemaComponent;
-import org.apache.xmlbeans.SchemaGlobalAttribute;
-import org.apache.xmlbeans.SchemaGlobalElement;
-import org.apache.xmlbeans.SchemaIdentityConstraint;
-import org.apache.xmlbeans.SchemaModelGroup;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.SchemaTypeSystem;
-
-/*package*/ class SchemaContainer
-{
+/*package*/ class SchemaContainer {
     // The namespace that this is the container for
     // TODO(radup) In the future, I think the right approach is one container
     // per file instead of per namespace, but per namespace is easier for now
-    private String _namespace;
+    private final String _namespace;
 
-    SchemaContainer(String namespace)
-    {
+    SchemaContainer(String namespace) {
         _namespace = namespace;
     }
 
-    String getNamespace()
-    {
+    String getNamespace() {
         return _namespace;
     }
 
@@ -55,13 +45,11 @@ import org.apache.xmlbeans.SchemaTypeSys
     // at the same time providing the mechanism through which
     // we can "move" SchemaTypes from one SchemaTypeSystem to another
     // via incremental compilation
-    synchronized SchemaTypeSystem getTypeSystem()
-    {
+    synchronized SchemaTypeSystem getTypeSystem() {
         return _typeSystem;
     }
 
-    synchronized void setTypeSystem(SchemaTypeSystem typeSystem)
-    {
+    synchronized void setTypeSystem(SchemaTypeSystem typeSystem) {
         _typeSystem = typeSystem;
     }
 
@@ -73,138 +61,164 @@ import org.apache.xmlbeans.SchemaTypeSys
     // between typesystems.
     boolean _immutable;
 
-    synchronized void setImmutable()
-    {
+    synchronized void setImmutable() {
         _immutable = true;
     }
 
-    synchronized void unsetImmutable()
-    {
+    synchronized void unsetImmutable() {
         _immutable = false;
     }
 
-    private void check_immutable()
-    {
-        if (_immutable)
+    private void check_immutable() {
+        if (_immutable) {
             throw new IllegalStateException("Cannot add components to immutable SchemaContainer");
+        }
     }
 
     // Data
     // TODO(radup) unmodifiableList() is not really necessary, since this
     // is package-level access and code in this package should do the "right thing"
     // Global Elements
-    private List/*<SchemaGlobalElement.Ref>*/ _globalElements = new ArrayList();
+    private final List<SchemaGlobalElement.Ref> _globalElements = new ArrayList<>();
 
-    void addGlobalElement(SchemaGlobalElement.Ref e)
-    {   check_immutable(); _globalElements.add(e); }
+    void addGlobalElement(SchemaGlobalElement.Ref e) {
+        check_immutable();
+        _globalElements.add(e);
+    }
 
-    List globalElements()
-    {   return getComponentList(_globalElements); }
+    List<SchemaGlobalElement> globalElements() {
+        return _globalElements.stream().map(SchemaGlobalElement.Ref::get).collect(Collectors.toList());
+    }
 
     // Global Attributes
-    private List/*<SchemaGlobalAttribute.Ref>*/ _globalAttributes = new ArrayList();
+    private final List<SchemaGlobalAttribute.Ref> _globalAttributes = new ArrayList<>();
 
-    void addGlobalAttribute(SchemaGlobalAttribute.Ref a)
-    {   check_immutable(); _globalAttributes.add(a); }
+    void addGlobalAttribute(SchemaGlobalAttribute.Ref a) {
+        check_immutable();
+        _globalAttributes.add(a);
+    }
 
-    List globalAttributes()
-    {   return getComponentList(_globalAttributes); }
+    List<SchemaGlobalAttribute> globalAttributes() {
+        return _globalAttributes.stream().map(SchemaGlobalAttribute.Ref::get).collect(Collectors.toList());
+    }
 
     // Model Groups
-    private List/*<SchemaModelGroup.Ref>*/ _modelGroups = new ArrayList();
+    private final List<SchemaModelGroup.Ref> _modelGroups = new ArrayList<>();
 
-    void addModelGroup(SchemaModelGroup.Ref g)
-    {   check_immutable(); _modelGroups.add(g); }
+    void addModelGroup(SchemaModelGroup.Ref g) {
+        check_immutable();
+        _modelGroups.add(g);
+    }
 
-    List modelGroups()
-    {   return getComponentList(_modelGroups); }
+    List<SchemaModelGroup> modelGroups() {
+        return _modelGroups.stream().map(SchemaModelGroup.Ref::get).collect(Collectors.toList());
+    }
 
     // Redefined Model Groups
-    private List/*<SchemaModelGroup.Ref>*/ _redefinedModelGroups = new ArrayList();
+    private final List<SchemaModelGroup.Ref> _redefinedModelGroups = new ArrayList<>();
 
-    void addRedefinedModelGroup(SchemaModelGroup.Ref g)
-    {   check_immutable(); _redefinedModelGroups.add(g); }
+    void addRedefinedModelGroup(SchemaModelGroup.Ref g) {
+        check_immutable();
+        _redefinedModelGroups.add(g);
+    }
 
-    List redefinedModelGroups()
-    {   return getComponentList(_redefinedModelGroups); }
+    List<SchemaModelGroup> redefinedModelGroups() {
+        return _redefinedModelGroups.stream().map(SchemaModelGroup.Ref::get).collect(Collectors.toList());
+    }
 
     // Attribute Groups
-    private List/*<SchemaAttributeGroup.Ref>*/ _attributeGroups = new ArrayList();
+    private final List<SchemaAttributeGroup.Ref> _attributeGroups = new ArrayList<>();
 
-    void addAttributeGroup(SchemaAttributeGroup.Ref g)
-    {   check_immutable(); _attributeGroups.add(g); }
+    void addAttributeGroup(SchemaAttributeGroup.Ref g) {
+        check_immutable();
+        _attributeGroups.add(g);
+    }
 
-    List attributeGroups()
-    {   return getComponentList(_attributeGroups); }
+    List<SchemaAttributeGroup> attributeGroups() {
+        return _attributeGroups.stream().map(SchemaAttributeGroup.Ref::get).collect(Collectors.toList());
+    }
 
     // Redefined Attribute Groups
-    private List/*<SchemaAttributeGroup.Ref>*/ _redefinedAttributeGroups = new ArrayList();
+    private final List<SchemaAttributeGroup.Ref> _redefinedAttributeGroups = new ArrayList<>();
 
-    void addRedefinedAttributeGroup(SchemaAttributeGroup.Ref g)
-    {   check_immutable(); _redefinedAttributeGroups.add(g); }
+    void addRedefinedAttributeGroup(SchemaAttributeGroup.Ref g) {
+        check_immutable();
+        _redefinedAttributeGroups.add(g);
+    }
 
-    List redefinedAttributeGroups()
-    {   return getComponentList(_redefinedAttributeGroups); }
+    List<SchemaAttributeGroup> redefinedAttributeGroups() {
+        return _redefinedAttributeGroups.stream().map(SchemaAttributeGroup.Ref::get).collect(Collectors.toList());
+    }
 
     // Global Types
-    private List/*<SchemaType.Ref>*/ _globalTypes = new ArrayList();
+    private final List<SchemaType.Ref> _globalTypes = new ArrayList<>();
 
-    void addGlobalType(SchemaType.Ref t)
-    {   check_immutable(); _globalTypes.add(t); }
+    void addGlobalType(SchemaType.Ref t) {
+        check_immutable();
+        _globalTypes.add(t);
+    }
 
-    List globalTypes()
-    {   return getComponentList(_globalTypes); }
+    List<SchemaType> globalTypes() {
+        return _globalTypes.stream().map(SchemaType.Ref::get).collect(Collectors.toList());
+    }
 
     // Redefined Global Types
-    private List/*<SchemaType.Ref>*/ _redefinedGlobalTypes = new ArrayList();
+    private final List<SchemaType.Ref> _redefinedGlobalTypes = new ArrayList<>();
 
-    void addRedefinedType(SchemaType.Ref t)
-    {   check_immutable(); _redefinedGlobalTypes.add(t); }
+    void addRedefinedType(SchemaType.Ref t) {
+        check_immutable();
+        _redefinedGlobalTypes.add(t);
+    }
 
-    List redefinedGlobalTypes()
-    {   return getComponentList(_redefinedGlobalTypes); }
+    List<SchemaType> redefinedGlobalTypes() {
+        return _redefinedGlobalTypes.stream().map(SchemaType.Ref::get).collect(Collectors.toList());
+    }
 
     // Document Types
-    private List/*<SchemaType.Ref>*/ _documentTypes = new ArrayList();
+    private final List<SchemaType.Ref> _documentTypes = new ArrayList<>();
 
-    void addDocumentType(SchemaType.Ref t)
-    {   check_immutable(); _documentTypes.add(t); }
+    void addDocumentType(SchemaType.Ref t) {
+        check_immutable();
+        _documentTypes.add(t);
+    }
 
-    List documentTypes()
-    {   return getComponentList(_documentTypes); }
+    List<SchemaType> documentTypes() {
+        return _documentTypes.stream().map(SchemaType.Ref::get).collect(Collectors.toList());
+    }
 
     // Attribute Types
-    private List/*<SchemaType.Ref>*/ _attributeTypes = new ArrayList();
+    private final List<SchemaType.Ref> _attributeTypes = new ArrayList<>();
 
-    void addAttributeType(SchemaType.Ref t)
-    {   check_immutable(); _attributeTypes.add(t); }
+    void addAttributeType(SchemaType.Ref t) {
+        check_immutable();
+        _attributeTypes.add(t);
+    }
 
-    List attributeTypes()
-    {   return getComponentList(_attributeTypes); }
+    List<SchemaType> attributeTypes() {
+        return _attributeTypes.stream().map(SchemaType.Ref::get).collect(Collectors.toList());
+    }
 
     // Identity Constraints
-    private List/*<SchemaIdentityConstraint.Ref>*/ _identityConstraints = new ArrayList();
+    private final List<SchemaIdentityConstraint.Ref> _identityConstraints = new ArrayList<>();
 
-    void addIdentityConstraint(SchemaIdentityConstraint.Ref c)
-    {   check_immutable(); _identityConstraints.add(c); }
+    void addIdentityConstraint(SchemaIdentityConstraint.Ref c) {
+        check_immutable();
+        _identityConstraints.add(c);
+    }
 
-    List identityConstraints()
-    {   return getComponentList(_identityConstraints); }
+    List<SchemaIdentityConstraint> identityConstraints() {
+        return _identityConstraints.stream().map(SchemaIdentityConstraint.Ref::get).collect(Collectors.toList());
+    }
 
     // Annotations
-    private List/*<SchemaAnnotation>*/ _annotations = new ArrayList();
-
-    void addAnnotation(SchemaAnnotation a)
-    {   check_immutable(); _annotations.add(a); }
+    private final List<SchemaAnnotation> _annotations = new ArrayList<>();
 
-    List annotations()
-    {   return Collections.unmodifiableList(_annotations); }
+    void addAnnotation(SchemaAnnotation a) {
+        check_immutable();
+        _annotations.add(a);
+    }
 
-    private List getComponentList(List referenceList)
-    {
-        List result = new ArrayList();
-        for (int i = 0; i < referenceList.size(); i ++)
-            result.add(((SchemaComponent.Ref) referenceList.get(i)).getComponent());
-        return Collections.unmodifiableList(result);
+    List<SchemaAnnotation> annotations() {
+        return Collections.unmodifiableList(_annotations);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org