luetzkendorf    2004/09/26 07:12:45

  Modified:    src/share/org/apache/slide/structure Tag:
                        SLIDE_2_1_RELEASE_BRANCH ObjectNode.java
  Log:
  introduced some lazy construction for links and updatedBindings (reduces mem
  usage and increases speed)
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.27.2.2  +38 -23    
jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java
  
  Index: ObjectNode.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java,v
  retrieving revision 1.27.2.1
  retrieving revision 1.27.2.2
  diff -u -r1.27.2.1 -r1.27.2.2
  --- ObjectNode.java   23 Sep 2004 07:26:52 -0000      1.27.2.1
  +++ ObjectNode.java   26 Sep 2004 14:12:45 -0000      1.27.2.2
  @@ -24,12 +24,14 @@
   package org.apache.slide.structure;
   
   import java.io.Serializable;
  +import java.util.Collections;
   import java.util.Enumeration;
   import java.util.Vector;
   import java.util.Set;
   import java.util.HashSet;
   import org.apache.slide.common.ObjectValidationFailedException;
   import org.apache.slide.common.UriPath;
  +import org.apache.slide.util.EmptyEnumeration;
   import org.apache.slide.util.Messages;
   
   /**
  @@ -67,7 +69,7 @@
        * wheter [EMAIL PROTECTED] #linksShared} is true. In this case clone the vector
        * and set the shared state to false.
        */
  -    private Vector links;
  +    private Vector links = null;
       
       /*
        * If true then the [EMAIL PROTECTED] #links} vector is shared between multiple
  @@ -100,10 +102,8 @@
        * Default constructor.
        */
       public ObjectNode() {
  -        this.links = new Vector();
           this.bindings = new BindingList();
           this.parentBindings = new ParentBindingList();
  -        this.updatedBindings = new HashSet();
       }
       
       /**
  @@ -135,9 +135,10 @@
           this.parentBindings = new ParentBindingList(parentBindings);
           this.links = links;
           Enumeration e = bindings.elements();
  +        if (e.hasMoreElements()) this.updatedBindings = new HashSet();
           while(e.hasMoreElements()) {
  -                     
updatedBindings.add(((ObjectNode.Binding)e.nextElement()).getUuri());
  -             }
  +                  
updatedBindings.add(((ObjectNode.Binding)e.nextElement()).getUuri());
  +               }
       }
       
       /**
  @@ -188,11 +189,15 @@
       
   
       public Set getUpdatedBindings() {
  -             return updatedBindings;
  +        if (this.updatedBindings == null) {
  +            return Collections.EMPTY_SET;
  +        } else {
  +            return Collections.unmodifiableSet(updatedBindings);
  +        }
        }
   
        public void resetUpdatedBindings() {
  -             updatedBindings.clear();
  +        this.updatedBindings = null;
        }
   
       /**
  @@ -349,7 +354,11 @@
        * @return boolean true if this object has links, false otherwise
        */
       public boolean hasLinks() {
  -        return !( links.isEmpty());
  +        if (this.links == null) {
  +            return false;
  +        } else {
  +            return !( links.isEmpty());
  +        }
       }
       /**
        * Return this object's inbound links
  @@ -357,7 +366,11 @@
        * @return Enumeration Inbound links uris
        */
       public Enumeration enumerateLinks() {
  -        return links.elements();
  +        if (this.links == null) {
  +            return EmptyEnumeration.INSTANCE;
  +        } else {
  +            return links.elements();
  +        }
       }
       
       
  @@ -450,12 +463,7 @@
               throw new ObjectValidationFailedException
                   (uri, Messages.message
                        (ObjectNode.class.getName() + ".nullBindingsVector"));
  -        
  -        if (links == null)
  -            throw new ObjectValidationFailedException
  -                (uri, Messages.message
  -                     (ObjectNode.class.getName() + ".nullLinksVector"));
  -        
  +                
       }
       
       /**
  @@ -472,7 +480,8 @@
        * @param   link               an LinkNode
        */
       public void addLink( LinkNode link ) {
  -         links.add(link.getUri());
  +        if (this.links == null) this.links = new Vector();
  +        links.add(link.getUri());
       }
       
       /**
  @@ -481,7 +490,9 @@
        * @param    source              the child ObjectNode
        */
       public void addBinding( String bindingName, ObjectNode source ) {
  -             updatedBindings.add(source.getUri());
  +        if (this.updatedBindings == null) this.updatedBindings = new HashSet();
  +               updatedBindings.add(source.getUri());
  +          
           if (!hasBinding(bindingName)) {
               if(bindingsShared) {
                   // Lazy cloning on first write access
  @@ -505,7 +516,9 @@
        * @param child The child to remove
        */
       public void removeChild(ObjectNode child) {
  -             updatedBindings.add(child.getUri());
  +        if (this.updatedBindings == null) this.updatedBindings = new HashSet();
  +        updatedBindings.add(child.getUri());
  +        
           if (child == null) {
               return;
           }
  @@ -527,7 +540,9 @@
        * @param link
        */
       public void removeLink(LinkNode link) {
  -        links.remove(link.getUri());
  +        if (this.links != null) {
  +            links.remove(link.getUri());
  +        }
       }
       
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to