1 28 package net.sf.jasperreports.engine.fill; 29 30 import java.io.Serializable ; 31 32 import net.sf.jasperreports.engine.JRExpression; 33 import net.sf.jasperreports.engine.JRGroup; 34 35 36 42 public class JREvaluationTime implements Serializable 43 { 44 47 public static final JREvaluationTime EVALUATION_TIME_REPORT = new JREvaluationTime(JRExpression.EVALUATION_TIME_REPORT, null, null); 48 51 public static final JREvaluationTime EVALUATION_TIME_PAGE = new JREvaluationTime(JRExpression.EVALUATION_TIME_PAGE, null, null); 52 55 public static final JREvaluationTime EVALUATION_TIME_COLUMN = new JREvaluationTime(JRExpression.EVALUATION_TIME_COLUMN, null, null); 56 59 public static final JREvaluationTime EVALUATION_TIME_NOW = new JREvaluationTime(JRExpression.EVALUATION_TIME_NOW, null, null); 60 61 62 69 public static JREvaluationTime getGroupEvaluationTime(String groupName) 70 { 71 return new JREvaluationTime(JRExpression.EVALUATION_TIME_GROUP, groupName, null); 72 } 73 74 81 public static JREvaluationTime getBandEvaluationTime(JRFillBand band) 82 { 83 return new JREvaluationTime(JRExpression.EVALUATION_TIME_BAND, null, band); 84 } 85 86 87 97 public static JREvaluationTime getEvaluationTime(byte type, JRGroup group, JRFillBand band) 98 { 99 JREvaluationTime evaluationTime; 100 101 switch (type) 102 { 103 case JRExpression.EVALUATION_TIME_REPORT: 104 evaluationTime = EVALUATION_TIME_REPORT; 105 break; 106 case JRExpression.EVALUATION_TIME_PAGE: 107 evaluationTime = EVALUATION_TIME_PAGE; 108 break; 109 case JRExpression.EVALUATION_TIME_COLUMN: 110 evaluationTime = EVALUATION_TIME_COLUMN; 111 break; 112 case JRExpression.EVALUATION_TIME_GROUP: 113 evaluationTime = getGroupEvaluationTime(group.getName()); 114 break; 115 case JRExpression.EVALUATION_TIME_BAND: 116 evaluationTime = getBandEvaluationTime(band); 117 break; 118 default: 119 evaluationTime = null; 120 break; 121 } 122 123 return evaluationTime; 124 } 125 126 private final byte type; 127 private final String groupName; 128 private final int bandId; 129 private final int hash; 130 131 132 private JREvaluationTime(byte type, String groupName, JRFillBand band) 133 { 134 this.type = type; 135 this.groupName = groupName; 136 this.bandId = band == null ? 0 : band.getId(); 137 138 this.hash = computeHash(); 139 } 140 141 142 private int computeHash() 143 { 144 int hashCode = type; 145 hashCode = 31*hashCode + (groupName == null ? 0 : groupName.hashCode()); 146 hashCode = 31*hashCode + bandId; 147 return hashCode; 148 } 149 150 151 public boolean equals(Object obj) 152 { 153 if (obj == this) 154 { 155 return true; 156 } 157 158 JREvaluationTime e = (JREvaluationTime) obj; 159 160 boolean eq = e.type == type; 161 162 if (eq) 163 { 164 switch (type) 165 { 166 case JRExpression.EVALUATION_TIME_GROUP: 167 eq = groupName.equals(e.groupName); 168 break; 169 case JRExpression.EVALUATION_TIME_BAND: 170 eq = bandId == e.bandId; 171 break; 172 } 173 } 174 175 return eq; 176 } 177 178 179 public int hashCode() 180 { 181 return hash; 182 } 183 } 184 | Popular Tags |