Changeset 4464


Ignore:
Timestamp:
2003-06-03T16:22:45+12:00 (21 years ago)
Author:
jmt12
Message:

2030093: Added a method getCount() which returns the count of both documents and folders.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/collection/Collection.java

    r4439 r4464  
    166166    return get(BUILT);
    167167    }
     168
     169    /** Determine the number of documents and folders in this collection. */
     170    public int getCount() {
     171    return getCount((TreeNode)Gatherer.c_man.getRecordSet().getRoot(), true, true);
     172    }
     173
    168174    /** Calculates the number of documents in this collection. */
    169175    public int getDocumentCount() {
    170     return getCount((TreeNode)Gatherer.c_man.getRecordSet().getRoot(), false);
     176    return getCount((TreeNode)Gatherer.c_man.getRecordSet().getRoot(), false, true);
    171177    }
    172178    /** Retrieve the description of this collection.
     
    242248    /** Counts the number of folders used in the current record set. */
    243249    public int getFolderCount() {
    244     return getCount((TreeNode)Gatherer.c_man.getRecordSet().getRoot(), true);
     250    return getCount((TreeNode)Gatherer.c_man.getRecordSet().getRoot(), true, false);
    245251    }
    246252    /** Determine if this collection has had an import action run upon it since the last major change.
     
    382388
    383389    /** Count either documents or folders, depending on the state of the given boolean. */
    384     private int getCount(TreeNode node, boolean folders) {
     390    private int getCount(TreeNode node, boolean count_folders, boolean count_files) {
    385391    int count = 0;
    386392    File file = ((FileNode)node).getFile();
    387     if(file.isFile() && !folders) {
     393    if(file.isFile() && count_files) {
    388394        count++;
    389395    }
    390     else if(file.isDirectory() && folders) {
     396    else if(file.isDirectory() && count_folders) {
    391397        count++;
    392398    }
    393399    for(int i = 0; i < node.getChildCount(); i++) {
    394         count = count + getCount(node.getChildAt(i), folders);
     400        count = count + getCount(node.getChildAt(i), count_folders, count_files);
    395401    }
    396402    return count;
Note: See TracChangeset for help on using the changeset viewer.