You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mb...@apache.org on 2005/08/05 19:28:26 UTC

cvs commit: ant/src/main/org/apache/tools/ant/types/resources BaseResourceCollectionContainer.java

mbenson     2005/08/05 10:28:26

  Modified:    src/main/org/apache/tools/ant/types/resources
                        BaseResourceCollectionContainer.java
  Log:
  Add option to disable collection caching; refactor cache usage for smaller code.
  
  Revision  Changes    Path
  1.3       +28 -12    ant/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
  
  Index: BaseResourceCollectionContainer.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BaseResourceCollectionContainer.java	12 Jun 2005 15:54:14 -0000	1.2
  +++ BaseResourceCollectionContainer.java	5 Aug 2005 17:28:25 -0000	1.3
  @@ -37,6 +37,23 @@
       extends DataType implements ResourceCollection, Cloneable {
       private List rc = new ArrayList();
       private Collection coll = null;
  +    private boolean cache = true;
  +
  +    /**
  +     * Set whether to cache collections.
  +     * @param b boolean cache flag.
  +     */
  +    public synchronized void setCache(boolean b) {
  +        cache = b;
  +    }
  +
  +    /**
  +     * Learn whether to cache collections. Default is <code>true</code>.
  +     * @return boolean cache flag.
  +     */
  +    public synchronized boolean isCache() {
  +        return cache;
  +    }
   
       /**
        * Add a ResourceCollection to the container.
  @@ -85,8 +102,7 @@
               return ((BaseResourceCollectionContainer) getCheckedRef()).iterator();
           }
           dieOnCircularReference();
  -        cacheCollection();
  -        return new FailFast(this, coll.iterator());
  +        return new FailFast(this, cacheCollection().iterator());
       }
   
       /**
  @@ -98,8 +114,7 @@
               return ((BaseResourceCollectionContainer) getCheckedRef()).size();
           }
           dieOnCircularReference();
  -        cacheCollection();
  -        return coll.size();
  +        return cacheCollection().size();
       }
   
       /**
  @@ -121,8 +136,7 @@
           }
           /* now check each Resource in case the child only
              lets through files from any children IT may have: */
  -        cacheCollection();
  -        for (Iterator i = coll.iterator(); i.hasNext();) {
  +        for (Iterator i = cacheCollection().iterator(); i.hasNext();) {
               if (!(i.next() instanceof FileResource)) {
                   return false;
               }
  @@ -137,7 +151,7 @@
        * @param p   the project to use to dereference the references.
        * @throws BuildException on error.
        */
  -    protected void dieOnCircularReference(Stack stk, Project p)
  +    protected synchronized void dieOnCircularReference(Stack stk, Project p)
           throws BuildException {
           if (isChecked()) {
               return;
  @@ -193,12 +207,11 @@
        * Format this BaseResourceCollectionContainer as a String.
        * @return a descriptive <code>String</code>.
        */
  -    public String toString() {
  +    public synchronized String toString() {
           if (isReference()) {
               return getCheckedRef().toString();
           }
  -        cacheCollection();
  -        if (coll.size() == 0) {
  +        if (cacheCollection().size() == 0) {
               return "";
           }
           StringBuffer sb = new StringBuffer();
  @@ -211,8 +224,11 @@
           return sb.toString();
       }
   
  -    private synchronized void cacheCollection() {
  -        coll = (coll == null) ? getCollection() : coll;
  +    private synchronized Collection cacheCollection() {
  +        if (coll == null || !isCache()) {
  +            coll = getCollection();
  +        }
  +        return coll;
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org