1 44 45 package org.jfree.chart.axis; 46 47 import java.io.Serializable ; 48 import java.text.DateFormat ; 49 import java.text.FieldPosition ; 50 import java.text.NumberFormat ; 51 import java.text.ParsePosition ; 52 import java.util.Arrays ; 53 import java.util.Calendar ; 54 import java.util.Date ; 55 import java.util.GregorianCalendar ; 56 import java.util.TimeZone ; 57 58 62 public class QuarterDateFormat extends DateFormat 63 implements Cloneable , Serializable { 64 65 66 private static final long serialVersionUID = -6738465248529797176L; 67 68 69 public static final String [] REGULAR_QUARTERS 70 = new String [] {"1", "2", "3", "4"}; 71 72 73 public static final String [] ROMAN_QUARTERS 74 = new String [] {"I", "II", "III", "IV"}; 75 76 77 private String [] quarters = REGULAR_QUARTERS; 78 79 82 public QuarterDateFormat() { 83 this(TimeZone.getDefault()); 84 } 85 86 91 public QuarterDateFormat(TimeZone zone) { 92 this(zone, REGULAR_QUARTERS); 93 } 94 95 101 public QuarterDateFormat(TimeZone zone, String [] quarterSymbols) { 102 if (zone == null) { 103 throw new IllegalArgumentException ("Null 'zone' argument."); 104 } 105 this.calendar = new GregorianCalendar (zone); 106 this.quarters = quarterSymbols; 107 108 this.numberFormat = NumberFormat.getNumberInstance(); 112 } 113 114 123 public StringBuffer format(Date date, StringBuffer toAppendTo, 124 FieldPosition fieldPosition) { 125 this.calendar.setTime(date); 126 int year = this.calendar.get(Calendar.YEAR); 127 int month = this.calendar.get(Calendar.MONTH); 128 toAppendTo.append(year); 129 toAppendTo.append(" "); 130 int quarter = month / 3; 131 toAppendTo.append(this.quarters[quarter]); 132 return toAppendTo; 133 } 134 135 143 public Date parse(String source, ParsePosition pos) { 144 return null; 145 } 146 147 154 public boolean equals(Object obj) { 155 if (obj == this) { 156 return true; 157 } 158 if (!(obj instanceof QuarterDateFormat)) { 159 return false; 160 } 161 if (!super.equals(obj)) { 162 return false; 163 } 164 QuarterDateFormat that = (QuarterDateFormat) obj; 165 if (!Arrays.equals(this.quarters, that.quarters)) { 166 return false; 167 } 168 return true; 169 } 170 171 } 172 | Popular Tags |