View Javadoc
1 /* 2 Bloof - visualize the evolution of your software project 3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de> 4 http://bloof.sf.net/ 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along with 15 this program; if not, write to the Free Software Foundation, Inc., 16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 $RCSfile: TimeInterval.java,v $ 19 Created on $Date: 2003/09/06 08:35:09 $ 20 */ 21 package net.sf.bloof.metrics; 22 23 import java.text.SimpleDateFormat; 24 import java.util.Date; 25 26 import net.sf.bloof.util.intl.Messages; 27 import net.sf.bloof.util.intl.Text; 28 29 /*** 30 * Represents a time interval. Acts as filter for a {@link net.sf.bloof.metrics.Metric} 31 * This class is used as an argument for a @link{MetricParameter} 32 * @author Lukasz Pekacki <pekacki@users.sourceforge.net> 33 * @version $Id: TimeInterval.java,v 1.10 2003/09/06 08:35:09 pekacki Exp $ 34 */ 35 public class TimeInterval implements Filter { 36 /*** 37 * Creates a TimeInterval that represents only one @link{Date}, 38 * precice to a millisecond 39 * @param aExactDate exact @link{Date} with Millisecond precision 40 */ 41 public TimeInterval(Date aExactDate) { 42 this(aExactDate, aExactDate); 43 } 44 /*** 45 * Creates a TimeInterval between the two specified @link{Date}s 46 * @param aFrom interval starting @link{Date} 47 * @param aTo interval end @link{Date} 48 */ 49 public TimeInterval(Date aFrom, Date aTo) { 50 this(null, aFrom, aTo); 51 } /*** 52 * Creates a TimeInterval between the two specified @link{Date}s and sets its name 53 * @param aName name of the time interval 54 * @param aFrom interval starting @link{Date} 55 * @param aTo interval end @link{Date} 56 */ 57 public TimeInterval(String aName, Date aFrom, Date aTo) { 58 mFilterType = Filter.TIMESPAN; 59 mName = aName; 60 if (aFrom == null || aTo == null || aTo.before(aFrom)) { 61 throw new IllegalArgumentException( 62 "from:" + aFrom + " - to:" + aTo + "; illegal Arguments!"); 63 } 64 mFrom = aFrom; 65 mTo = aTo; 66 } 67 /*** 68 * Creates a TimeInterval on a list of Intervals 69 * @param aIntervals interval list of Intervals 70 */ 71 public TimeInterval(TimeInterval[] aIntervals) { 72 this(getMin(aIntervals), getMax(aIntervals)); 73 } 74 private static Date getMax(TimeInterval[] aIntervals) { 75 Date maxDate = aIntervals[0].getTo(); 76 for (int i = 0; i < aIntervals.length; i++) { 77 if (aIntervals[0].getTo().after(maxDate)) { 78 maxDate = aIntervals[0].getTo(); 79 } 80 } 81 return maxDate; 82 83 } 84 private static Date getMin(TimeInterval[] aIntervals) { 85 Date minDate = aIntervals[0].getFrom(); 86 for (int i = 0; i < aIntervals.length; i++) { 87 if (aIntervals[0].getFrom().before(minDate)) { 88 minDate = aIntervals[0].getFrom(); 89 } 90 } 91 return minDate; 92 93 } 94 95 96 /*** 97 * @see java.lang.Object#toString( ) 98 */ 99 public String getContent() { 100 return mDateFormatter.format(mFrom) + "-" + mDateFormatter.format(mTo); 101 } 102 /*** 103 * @see net.sf.bloof.metrics.Filter#getFilterType() 104 */ 105 public int getFilterType() { 106 return mFilterType; 107 } 108 /*** 109 * Returns the from. 110 * @return Date 111 */ 112 public Date getFrom() { 113 return mFrom; 114 } /*** 115 * Returns the name. 116 * @return String 117 */ 118 public String getName() { 119 return mName; 120 } 121 /*** 122 * Returns the to. 123 * @return Date 124 */ 125 public Date getTo() { 126 return mTo; 127 } 128 129 /*** 130 * Checks if the Interval is empty and represents a single date 131 * @return boolean 132 */ 133 public boolean isSingleDate() { 134 return mFrom == mTo; 135 } 136 137 /*** 138 * Sets the name. 139 * @param aName The name to set 140 */ 141 public void setName(String aName) { 142 mName = aName; 143 } 144 145 /*** (non-Javadoc) 146 * @see java.lang.Object#toString() 147 */ 148 public String toString() { 149 return mName; 150 } 151 private SimpleDateFormat mDateFormatter = 152 new SimpleDateFormat(Messages.getString(Text.DATE_FORMAT)); 153 private int mFilterType; 154 private Date mFrom; 155 private String mName; 156 private Date mTo; 157 }

This page was automatically generated by Maven