Ignore:
Timestamp:
2003-05-27T15:57:37+12:00 (21 years ago)
Author:
kjdon
Message:

re-tabbed the code for java

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/Index.java

    r4293 r4366  
    5757import org.w3c.dom.Element;
    5858/** This class encapsulates a single indexing pair.
    59 * @author John Thompson, Greenstone Digital Library, University of Waikato
    60 * @version 2.2
    61 */
     59 * @author John Thompson, Greenstone Digital Library, University of Waikato
     60 * @version 2.2
     61 */
    6262public class Index
    63     implements Comparable {
    64     /** A refernce to the main manager for access to other sub-managers. */
    65     private CollectionDesignManager manager = null;
    66     /** The level of this index. */
    67     private int level = 0;
    68     /** The sources for data this index is built apon, which are either fully qualified metadata element names or 'text'. */
    69     private Vector sources = null;
    70     /** An element in the index level enumeration. */
    71     static public final int DOCUMENT = 0;
    72     /** An element in the index level enumeration. */
    73     static public final int PARAGRAPH = 1;
    74     /** An element in the index level enumeration. */
    75     static public final int SECTION = 2;
    76     /** An values of items in the index level enumeration. */
    77     static public final String LEVEL[] = {"document","paragraph","section"};
    78     /** Constructor.
    79       * @param level The level of this index as a <strong>String</string>.
    80       * @param metadata The fully qualified name of the metadata this index is built on as a <strong>String</strong>, or <i>null</i> in which case the data defaults to "text".
    81       */
    82     public Index(int level, Vector sources, CollectionDesignManager manager) {
    83           this.level = level;
    84           this.manager = manager;
    85           this.sources = sources;
    86           if(this.sources == null) {
    87                 this.sources = new Vector();
    88                 this.sources.add("text");
    89           }
    90     }
    91     /** Method to compare two indexes.
     63    implements Comparable {
     64    /** A refernce to the main manager for access to other sub-managers. */
     65    private CollectionDesignManager manager = null;
     66    /** The level of this index. */
     67    private int level = 0;
     68    /** The sources for data this index is built apon, which are either fully qualified metadata element names or 'text'. */
     69    private Vector sources = null;
     70    /** An element in the index level enumeration. */
     71    static public final int DOCUMENT = 0;
     72    /** An element in the index level enumeration. */
     73    static public final int PARAGRAPH = 1;
     74    /** An element in the index level enumeration. */
     75    static public final int SECTION = 2;
     76    /** An values of items in the index level enumeration. */
     77    static public final String LEVEL[] = {"document","paragraph","section"};
     78    /** Constructor.
     79     * @param level The level of this index as a <strong>String</string>.
     80     * @param metadata The fully qualified name of the metadata this index is built on as a <strong>String</strong>, or <i>null</i> in which case the data defaults to "text".
     81     */
     82    public Index(int level, Vector sources, CollectionDesignManager manager) {
     83    this.level = level;
     84    this.manager = manager;
     85    this.sources = sources;
     86    if(this.sources == null) {
     87        this.sources = new Vector();
     88        this.sources.add("text");
     89    }
     90    }
     91    /** Method to compare two indexes.
    9292      * @param object The other index as an <strong>Object</strong>.
    9393      * @return An <i>int</i> which indicates how the indexes compare.
    9494      * @see java.lang.String
    9595      */
    96     public int compareTo(Object object) {
    97           if(object instanceof Index) {
    98                 Index index = (Index) object;
    99                 return toString(false).compareTo(index.toString(false));
    100           }
    101           return toString(false).compareTo(object.toString());
    102     }
    103     /** Method to test for the equality of two indexes.
     96    public int compareTo(Object object) {
     97    if(object instanceof Index) {
     98        Index index = (Index) object;
     99        return toString(false).compareTo(index.toString(false));
     100    }
     101    return toString(false).compareTo(object.toString());
     102    }
     103    /** Method to test for the equality of two indexes.
    104104      * @param object The other index as an <strong>Object</strong>.
    105105      * @return A <i>boolean</i> which is <i>true</i> if the two indexes are equal, <i>false</i> otherwise.
    106106      */
    107     public boolean equals(Object object) {
    108           if(compareTo(object) == 0) {
    109                 return true;
    110           }
    111           return false;
    112     }
    113     /** Method to get the data source of this index.
     107    public boolean equals(Object object) {
     108    if(compareTo(object) == 0) {
     109        return true;
     110    }
     111    return false;
     112    }
     113    /** Method to get the data source of this index.
    114114      * @return A <strong>String</string> which is a comma separated list of either fully qualified names of an assigned metadata elements, or "text".
    115115      */
    116     public String getData() {
    117           String result = "";
    118           Collections.sort(sources, new IndexComparator());
    119           for(int i = 0; i < sources.size(); i++) {
    120                 result = result + sources.get(i).toString();
    121                 if(i < sources.size() - 1) {
    122                      result = result + ",";
    123                 }
    124           }
    125           return result;
    126     }
    127     /** Method to get the value of level.
     116    public String getData() {
     117    String result = "";
     118    Collections.sort(sources, new IndexComparator());
     119    for(int i = 0; i < sources.size(); i++) {
     120        result = result + sources.get(i).toString();
     121        if(i < sources.size() - 1) {
     122        result = result + ",";
     123        }
     124    }
     125    return result;
     126    }
     127    /** Method to get the value of level.
    128128      * @return The value of level as a <strong>String</strong>.
    129129      */
    130     public int getLevel() {
    131           return level;
    132     }
    133     /** Method to get the value of metadata.
     130    public int getLevel() {
     131    return level;
     132    }
     133    /** Method to get the value of metadata.
    134134      * @return The value of metadata as an <strong>Vector</strong>.
    135135      */
    136     public Vector getMetadata() {
    137           return sources;
    138     }
    139     /** Method to retrieve this indexes name.
     136    public Vector getMetadata() {
     137    return sources;
     138    }
     139    /** Method to retrieve this indexes name.
    140140      * @return A <strong>String</strong>.
    141141      */
    142     public String getName() {
    143           if(manager != null) {
    144                 String name = LEVEL[level] + ":" + getData();
    145                 Language language = manager.languages.getDefaultLanguage();
    146                 CollectionMeta metadata = manager.collectionmetadatum.getMetadata(name, language, true);
    147                 if(metadata != null) {
    148                      return metadata.getValue();
    149                 }
    150           }
    151           return "";
    152     }
    153     /** Method to turn this object into a string representation ready to be placed in the collection configuration file.
     142    public String getName() {
     143    if(manager != null) {
     144        String name = LEVEL[level] + ":" + getData();
     145        Language language = manager.languages.getDefaultLanguage();
     146        CollectionMeta metadata = manager.collectionmetadatum.getMetadata(name, language, true);
     147        if(metadata != null) {
     148        return metadata.getValue();
     149        }
     150    }
     151    return "";
     152    }
     153    /** Method to turn this object into a string representation ready to be placed in the collection configuration file.
    154154      * @return A <strong>String</strong> containing the information of this class.
    155155      */
    156     public String toString() {
    157           return LEVEL[level] + ":" + getData() + "  \"" + getName() + "\"";
    158     }
    159     /** Retrieve a textual representation of this index.
     156    public String toString() {
     157    return LEVEL[level] + ":" + getData() + "  \"" + getName() + "\"";
     158    }
     159    /** Retrieve a textual representation of this index.
    160160    * @param show_name <i>true</i> if you want the name of this index, <i>false</i> for the gsdl index reference.
    161161    */
    162     public String toString(boolean show_name) {
    163           if(show_name) {
    164                 return getName();
    165           }
    166           return LEVEL[level] + ":" + getData();
    167     }
    168     /** A custom comparator for comparing Indexes. */
    169     private class IndexComparator
    170           implements Comparator {
    171           /** Method to compare two objects, which may be either indexes or strings.
    172             * @param object1 One object as an <strong>Object</strong>.
    173             * @param object2 Another object as an <strong>Object</strong>.
    174             * @return An <i>int</i> which indicates how they compare.
    175             * @see java.lang.String
    176             */
    177           public int compare(Object object1, Object object2) {
    178                 if(object1 instanceof Index && object2 instanceof Index) {
    179                      Index index1 = (Index)object1;
    180                      Index index2 = (Index)object2;
    181                      return index1.toString(false).compareTo(index2.toString(false));
    182                 }
    183                 else if(object1 instanceof Index) {
    184                      Index index = (Index) object1;
    185                      return index.toString(false).compareTo(object2.toString());
    186                 }
    187                 else if(object2 instanceof Index) {
    188                      Index index = (Index) object2;
    189                      return object1.toString().compareTo(index.toString(false));
    190                 }
    191                 return object1.toString().compareTo(object2.toString());
    192           }
    193           /** Method to test for the equality of two objects, which may be indexes or strings.
     162    public String toString(boolean show_name) {
     163    if(show_name) {
     164        return getName();
     165    }
     166    return LEVEL[level] + ":" + getData();
     167    }
     168    /** A custom comparator for comparing Indexes. */
     169    private class IndexComparator
     170    implements Comparator {
     171    /** Method to compare two objects, which may be either indexes or strings.
     172     * @param object1 One object as an <strong>Object</strong>.
     173     * @param object2 Another object as an <strong>Object</strong>.
     174     * @return An <i>int</i> which indicates how they compare.
     175     * @see java.lang.String
     176     */
     177    public int compare(Object object1, Object object2) {
     178        if(object1 instanceof Index && object2 instanceof Index) {
     179        Index index1 = (Index)object1;
     180        Index index2 = (Index)object2;
     181        return index1.toString(false).compareTo(index2.toString(false));
     182        }
     183        else if(object1 instanceof Index) {
     184        Index index = (Index) object1;
     185        return index.toString(false).compareTo(object2.toString());
     186        }
     187        else if(object2 instanceof Index) {
     188        Index index = (Index) object2;
     189        return object1.toString().compareTo(index.toString(false));
     190        }
     191        return object1.toString().compareTo(object2.toString());
     192    }
     193    /** Method to test for the equality of two objects, which may be indexes or strings.
    194194            * @param object Another object as an <strong>Object</strong>.
    195195            * @return A <i>boolean</i> which is <i>true</i> if the two objects are equal, <i>false</i> otherwise.
    196196            */
    197           public boolean equals(Object object) {
    198                 if(compareTo(object) == 0) {
    199                      return true;
    200                 }
    201                 return false;
    202           }
    203     }
     197    public boolean equals(Object object) {
     198        if(compareTo(object) == 0) {
     199        return true;
     200        }
     201        return false;
     202    }
     203    }
    204204}
Note: See TracChangeset for help on using the changeset viewer.