Coverage Report - net.sf.statcvs.model.SymbolicName
 
Classes in this File Line Coverage Branch Coverage Complexity
SymbolicName
0%
0/30
0%
0/14
1.8
 
 1  
 /*
 2  
  *  StatCvs-XML - XML output for StatCvs.
 3  
  *
 4  
  *  Copyright by Steffen Pingel, Tammo van Lessen.
 5  
  *
 6  
  *  This program is free software; you can redistribute it and/or
 7  
  *  modify it under the terms of the GNU General Public License
 8  
  *  version 2 as published by the Free Software Foundation.
 9  
  *
 10  
  *  This program is distributed in the hope that it will be useful,
 11  
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  *  GNU General Public License for more details.
 14  
  *
 15  
  *  You should have received a copy of the GNU General Public License
 16  
  *  along with this program; if not, write to the Free Software
 17  
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 18  
  */
 19  
 package net.sf.statcvs.model;
 20  
 
 21  
 import java.util.Date;
 22  
 import java.util.SortedSet;
 23  
 import java.util.TreeSet;
 24  
 
 25  
 /**
 26  
  * Represents a symbolic name (tags).
 27  
  * It is a container for {@link Revision}s.
 28  
  * 
 29  
  * @author Tammo van Lessen
 30  
  * @version $Id: SymbolicName.java,v 1.6 2009/08/20 17:44:05 benoitx Exp $
 31  
  */
 32  
 public class SymbolicName implements Comparable {
 33  
     private final String name;
 34  0
     private final SortedSet revisions = new TreeSet();
 35  0
     private Date date = null;
 36  
 
 37  
     /**
 38  
      * Creates a new symbolic name.
 39  
      * 
 40  
      * @param name the symbolic name's name
 41  
      * @param date of the symbolic name creation
 42  
      */
 43  0
     public SymbolicName(final String name, final Date date) {
 44  0
         this.name = name;
 45  0
         this.date = date;
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Creates a new symbolic name. With this constructor,
 50  
      * its creation date will be assumed to be the date
 51  
      * of its latest revision.
 52  
      * 
 53  
      * @param name the symbolic name's name
 54  
      */
 55  0
     public SymbolicName(final String name) {
 56  0
         this.name = name;
 57  0
     }
 58  
 
 59  
     /**
 60  
      * Returns the symbolic name's name.
 61  
      * 
 62  
      * @return the symbolic name's name.
 63  
      */
 64  
     public String getName() {
 65  0
         return name;
 66  
     }
 67  
 
 68  
     /**
 69  
      * Adds a revision to this symbolic name.
 70  
      * 
 71  
      * @param rev the revision
 72  
      */
 73  
     protected void addRevision(final Revision rev) {
 74  0
         revisions.add(rev);
 75  0
     }
 76  
 
 77  
     /**
 78  
      * Returns a set of {@link Revision}s contained in this symbolic name.
 79  
      * 
 80  
      * @return the revisions
 81  
      */
 82  
     public SortedSet getRevisions() {
 83  0
         return revisions;
 84  
     }
 85  
 
 86  
     /**
 87  
      * Returns the 'date' of this symbolic name.
 88  
      *  
 89  
      * @return the smbolic name's date
 90  
      */
 91  
     public Date getDate() {
 92  0
         if (date != null) {
 93  0
             return date;
 94  
         }
 95  0
         if (revisions.isEmpty()) {
 96  0
             return null;
 97  
         }
 98  0
         return ((Revision) revisions.last()).getDate();
 99  
     }
 100  
 
 101  
     /**
 102  
      * @see java.lang.Comparable#compareTo(java.lang.Object)
 103  
      */
 104  
     public int compareTo(final Object o) {
 105  0
         final SymbolicName other = (SymbolicName) o;
 106  0
         if (getDate() == null || other.getDate() == null) {
 107  0
             return getName().compareTo(other.getName());
 108  
         }
 109  0
         final int dateComp = getDate().compareTo(other.getDate());
 110  0
         return (dateComp != 0) ? dateComp : getName().compareTo(other.getName());
 111  
     }
 112  
 
 113  
     /**
 114  
      * @see java.lang.Object#toString()
 115  
      */
 116  
     public String toString() {
 117  0
         return name + "[" + getDate() + "] (" + revisions.size() + " revisions)";
 118  
     }
 119  
 
 120  
     /**
 121  
      * @see java.lang.Object#equals(java.lang.Object)
 122  
      */
 123  
     public boolean equals(final Object obj) {
 124  0
         if (obj instanceof SymbolicName) {
 125  0
             final SymbolicName other = (SymbolicName) obj;
 126  0
             return ("" + getDate() + getName()).equals("" + other.getDate() + other.getName());
 127  
         }
 128  0
         return false;
 129  
     }
 130  
 
 131  
     /**
 132  0
      * @see java.lang.Object#hashCode()
 133  
      */
 134  
     public int hashCode() {
 135  0
         return ("" + getDate() + getName()).hashCode();
 136  
     }
 137  
 }